Exemplo n.º 1
0
 public static String getItemName(ItemStack stack) {
   if (stack != null) {
     if (stack.getItemMeta() != null && stack.getItemMeta().getDisplayName() != null) {
       return stack.getItemMeta().getDisplayName();
     }
     ItemInfo itemInfo = Items.itemByStack(stack);
     return itemInfo != null ? itemInfo.getName() : "" + stack.getType();
   }
   return null;
 }
Exemplo n.º 2
0
  public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) {
    String nameList = configSectionRecipes.getString(recipeId + ".name");
    if (nameList != null) {
      String[] name = nameList.split("/");
      if (name.length > 2) {
        this.name = name;
      } else {
        this.name = new String[1];
        this.name[0] = name[0];
      }
    } else {
      return;
    }
    List<String> ingredientsList = configSectionRecipes.getStringList(recipeId + ".ingredients");
    if (ingredientsList != null) {
      for (String item : ingredientsList) {
        String[] ingredParts = item.split("/");
        if (ingredParts.length == 2) {
          String[] matParts;
          if (ingredParts[0].contains(",")) {
            matParts = ingredParts[0].split(",");
          } else if (ingredParts[0].contains(":")) {
            matParts = ingredParts[0].split(":");
          } else if (ingredParts[0].contains(";")) {
            matParts = ingredParts[0].split(";");
          } else {
            matParts = ingredParts[0].split("\\.");
          }
          Material mat = Material.matchMaterial(matParts[0]);
          short durability = -1;
          if (matParts.length == 2) {
            durability = (short) P.p.parseInt(matParts[1]);
          }
          if (mat == null && P.p.hasVault) {
            try {
              net.milkbowl.vault.item.ItemInfo vaultItem =
                  net.milkbowl.vault.item.Items.itemByString(matParts[0]);
              if (vaultItem != null) {
                mat = vaultItem.getType();
                if (durability == -1 && vaultItem.getSubTypeId() != 0) {
                  durability = vaultItem.getSubTypeId();
                }
              }
            } catch (Exception e) {
              P.p.errorLog("Could not check vault for Item Name");
              e.printStackTrace();
            }
          }
          if (mat != null) {
            ItemStack stack = new ItemStack(mat, P.p.parseInt(ingredParts[1]), durability);
            this.ingredients.add(stack);
            BIngredients.possibleIngredients.add(mat);
          } else {
            P.p.errorLog("Unknown Material: " + ingredParts[0]);
            this.ingredients = null;
            return;
          }
        } else {
          return;
        }
      }
    }
    this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime");
    this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns");
    this.wood = (byte) configSectionRecipes.getInt(recipeId + ".wood");
    this.age = configSectionRecipes.getInt(recipeId + ".age");
    this.color = configSectionRecipes.getString(recipeId + ".color");
    this.difficulty = configSectionRecipes.getInt(recipeId + ".difficulty");
    this.alcohol = configSectionRecipes.getInt(recipeId + ".alcohol");

    List<String> effectStringList = configSectionRecipes.getStringList(recipeId + ".effects");
    if (effectStringList != null) {
      for (String effectString : effectStringList) {
        BEffect effect = new BEffect(effectString);
        if (effect.isValid()) {
          effects.add(effect);
        } else {
          P.p.errorLog("Error adding Effect to Recipe: " + getName(5));
        }
      }
    }
  }
Exemplo n.º 3
0
  public boolean readConfig() {
    File file = new File(p.getDataFolder(), "config.yml");
    if (!checkConfigs()) {
      return false;
    }
    FileConfiguration config = YamlConfiguration.loadConfiguration(file);

    // Set the Language
    language = config.getString("language", "en");

    // Load LanguageReader
    languageReader =
        new LanguageReader(new File(p.getDataFolder(), "languages/" + language + ".yml"));

    // Check if config is the newest version
    String version = config.getString("version", null);
    if (version != null) {
      if (!version.equals(configVersion)) {
        new ConfigUpdater(file).update(version, language);
        P.p.log("Config Updated to version: " + configVersion);
        config = YamlConfiguration.loadConfiguration(file);
      }
    }

    // If the Update Checker should be enabled
    updateCheck = config.getBoolean("updateCheck", false);

    // Third-Party
    useWG =
        config.getBoolean("useWorldGuard", true)
            && getServer().getPluginManager().isPluginEnabled("WorldGuard");
    if (useWG) {
      try {
        try {
          Class.forName("com.sk89q.worldguard.bukkit.RegionContainer");
          wg = new WGBarrelNew();
        } catch (ClassNotFoundException e) {
          wg = new WGBarrelOld();
        }
      } catch (Throwable e) {
        wg = null;
        P.p.errorLog("Failed loading WorldGuard Integration! Opening Barrels will NOT work!");
        P.p.errorLog("Brewery was tested with version 5.8 to 6.0 of WorldGuard!");
        P.p.errorLog("Disable the WorldGuard support in the config and do /brew reload");
        e.printStackTrace();
      }
    }
    useLWC =
        config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC");
    useGP =
        config.getBoolean("useGriefPrevention", true)
            && getServer().getPluginManager().isPluginEnabled("GriefPrevention");
    useLB =
        config.getBoolean("useLogBlock", false)
            && getServer().getPluginManager().isPluginEnabled("LogBlock");
    hasVault = getServer().getPluginManager().isPluginEnabled("Vault");

    // various Settings
    DataSave.autosave = config.getInt("autosave", 3);
    debug = config.getBoolean("debug", false);
    BPlayer.pukeItem = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND"));
    BPlayer.hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60;
    BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false);
    BPlayer.enableHome = config.getBoolean("enableHome", false);
    BPlayer.enableLoginDisallow = config.getBoolean("enableLoginDisallow", false);
    BPlayer.enablePuke = config.getBoolean("enablePuke", false);
    BPlayer.homeType = config.getString("homeType", null);
    Brew.colorInBarrels = config.getBoolean("colorInBarrels", false);
    Brew.colorInBrewer = config.getBoolean("colorInBrewer", false);
    PlayerListener.openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
    Words.log = config.getBoolean("logRealChat", false);
    Words.commands = config.getStringList("distortCommands");
    Words.doSigns = config.getBoolean("distortSignText", false);
    for (String bypass : config.getStringList("distortBypass")) {
      Words.ignoreText.add(bypass.split(","));
    }

    // loading recipes
    ConfigurationSection configSection = config.getConfigurationSection("recipes");
    if (configSection != null) {
      for (String recipeId : configSection.getKeys(false)) {
        BRecipe recipe = new BRecipe(configSection, recipeId);
        if (recipe.isValid()) {
          BIngredients.recipes.add(recipe);
        } else {
          errorLog("Loading the Recipe with id: '" + recipeId + "' failed!");
        }
      }
    }

    // loading cooked names and possible ingredients
    configSection = config.getConfigurationSection("cooked");
    if (configSection != null) {
      for (String ingredient : configSection.getKeys(false)) {
        Material mat = Material.matchMaterial(ingredient);
        if (mat == null && hasVault) {
          try {
            net.milkbowl.vault.item.ItemInfo vaultItem =
                net.milkbowl.vault.item.Items.itemByString(ingredient);
            if (vaultItem != null) {
              mat = vaultItem.getType();
            }
          } catch (Exception e) {
            P.p.errorLog("Could not check vault for Item Name");
            e.printStackTrace();
          }
        }
        if (mat != null) {
          BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null)));
          BIngredients.possibleIngredients.add(mat);
        } else {
          errorLog("Unknown Material: " + ingredient);
        }
      }
    }

    // loading drainItems
    List<String> drainList = config.getStringList("drainItems");
    if (drainList != null) {
      for (String drainString : drainList) {
        String[] drainSplit = drainString.split("/");
        if (drainSplit.length > 1) {
          Material mat = Material.matchMaterial(drainSplit[0]);
          int strength = p.parseInt(drainSplit[1]);
          if (mat == null && hasVault && strength > 0) {
            try {
              net.milkbowl.vault.item.ItemInfo vaultItem =
                  net.milkbowl.vault.item.Items.itemByString(drainSplit[0]);
              if (vaultItem != null) {
                mat = vaultItem.getType();
              }
            } catch (Exception e) {
              P.p.errorLog("Could not check vault for Item Name");
              e.printStackTrace();
            }
          }
          if (mat != null && strength > 0) {
            BPlayer.drainItems.put(mat, strength);
          }
        }
      }
    }

    // telling Words the path, it will load it when needed
    Words.config = config;

    return true;
  }