Esempio n. 1
0
  // returns the quality regarding the ageing time conditioning given Recipe
  public int getAgeQuality(BRecipe recipe, float time) {
    int quality =
        10 - Math.round(Math.abs(time - recipe.getAge()) * ((float) recipe.getDifficulty() / 2));

    if (quality > 0) {
      return quality;
    }
    return 0;
  }
Esempio n. 2
0
  // returns an Potion item with cooked ingredients
  public ItemStack cook(int state) {

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    // cookedTime is always time in minutes, state may differ with number of ticks
    cookedTime = state;
    String cookedName = null;
    BRecipe cookRecipe = getCookRecipe();

    int uid = Brew.generateUID();

    if (cookRecipe != null) {
      // Potion is best with cooking only
      int quality =
          (int)
              Math.round(
                  (getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
      P.p.debugLog("cooked potion has Quality: " + quality);
      Brew brew = new Brew(uid, quality, cookRecipe, this);
      Brew.addOrReplaceEffects(potionMeta, brew.getEffects());

      cookedName = cookRecipe.getName(quality);
      potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));

    } else {
      // new base potion
      new Brew(uid, this);

      if (state <= 1) {
        cookedName = P.p.languageReader.get("Brew_ThickBrew");
        potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
      } else {
        for (Material ingredient : ingredients.keySet()) {
          if (cookedNames.containsKey(ingredient)) {
            // if more than half of the ingredients is of one kind
            if (ingredients.get(ingredient) > (getIngredientsCount() / 2)) {
              cookedName = cookedNames.get(ingredient);
              potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
            }
          }
        }
      }
    }
    if (cookedName == null) {
      // if no name could be found
      cookedName = P.p.languageReader.get("Brew_Undefined");
      potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
    }

    potionMeta.setDisplayName(P.p.color("&f" + cookedName));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
    potion.setItemMeta(potionMeta);

    return potion;
  }
Esempio n. 3
0
  // returns currently best matching recipe for ingredients, cooking- and
  // ageingtime
  public BRecipe getAgeRecipe(float wood, float time, boolean distilled) {
    BRecipe bestRecipe = getBestRecipe(wood, time, distilled);

    if (bestRecipe != null) {
      if (bestRecipe.needsToAge()) {
        return bestRecipe;
      }
    }
    return null;
  }
Esempio n. 4
0
  // returns the currently best matching recipe for distilling for the
  // ingredients and cooking time
  public BRecipe getdistillRecipe(float wood, float time) {
    BRecipe bestRecipe = getBestRecipe(wood, time, true);

    // Check if best recipe needs to be destilled
    if (bestRecipe != null) {
      if (bestRecipe.needsDistilling()) {
        return bestRecipe;
      }
    }
    return null;
  }
Esempio n. 5
0
  // returns recipe that is cooking only and matches the ingredients and
  // cooking time
  public BRecipe getCookRecipe() {
    BRecipe bestRecipe = getBestRecipe(0, 0, false);

    // Check if best recipe is cooking only
    if (bestRecipe != null) {
      if (bestRecipe.isCookingOnly()) {
        return bestRecipe;
      }
    }
    return null;
  }
Esempio n. 6
0
  // returns the quality regarding the barrel wood conditioning given Recipe
  public int getWoodQuality(BRecipe recipe, float wood) {
    if (recipe.getWood() == 0) {
      // type of wood doesnt matter
      return 10;
    }
    int quality = 10 - Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty());

    if (quality > 0) {
      return quality;
    }
    return 0;
  }
Esempio n. 7
0
  // returns the quality regarding the cooking-time conditioning given Recipe
  public int getCookingQuality(BRecipe recipe, boolean distilled) {
    if (!recipe.needsDistilling() == distilled) {
      return -1;
    }
    int quality =
        10
            - (int)
                Math.round(
                    ((float) Math.abs(cookedTime - recipe.getCookingTime())
                            / recipe.allowedTimeDiff(recipe.getCookingTime()))
                        * 10.0);

    if (quality >= 0) {
      if (cookedTime <= 1) {
        return 0;
      }
      return quality;
    }
    return -1;
  }
Esempio n. 8
0
  // best recipe for current state of potion, STILL not always returns the
  // correct one...
  public BRecipe getBestRecipe(float wood, float time, boolean distilled) {
    float quality = 0;
    int ingredientQuality;
    int cookingQuality;
    int woodQuality;
    int ageQuality;
    BRecipe bestRecipe = null;
    for (BRecipe recipe : recipes) {
      ingredientQuality = getIngredientQuality(recipe);
      cookingQuality = getCookingQuality(recipe, distilled);

      if (ingredientQuality > -1 && cookingQuality > -1) {
        if (recipe.needsToAge() || time > 0.5) {
          // needs riping in barrel
          ageQuality = getAgeQuality(recipe, time);
          woodQuality = getWoodQuality(recipe, wood);
          P.p.debugLog(
              "Ingredient Quality: "
                  + ingredientQuality
                  + " Cooking Quality: "
                  + cookingQuality
                  + " Wood Quality: "
                  + woodQuality
                  + " age Quality: "
                  + ageQuality
                  + " for "
                  + recipe.getName(5));

          // is this recipe better than the previous best?
          if ((((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4)
              > quality) {
            quality = ((float) ingredientQuality + cookingQuality + woodQuality + ageQuality) / 4;
            bestRecipe = recipe;
          }
        } else {
          P.p.debugLog(
              "Ingredient Quality: "
                  + ingredientQuality
                  + " Cooking Quality: "
                  + cookingQuality
                  + " for "
                  + recipe.getName(5));
          // calculate quality without age and barrel
          if ((((float) ingredientQuality + cookingQuality) / 2) > quality) {
            quality = ((float) ingredientQuality + cookingQuality) / 2;
            bestRecipe = recipe;
          }
        }
      }
    }
    if (bestRecipe != null) {
      P.p.debugLog("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality);
    }
    return bestRecipe;
  }
Esempio n. 9
0
 // returns the quality of the ingredients conditioning given recipe, -1 if
 // no recipe is near them
 public int getIngredientQuality(BRecipe recipe) {
   float quality = 10;
   int count;
   int badStuff = 0;
   if (recipe.isMissingIngredients(ingredients)) {
     // when ingredients are not complete
     return -1;
   }
   for (Material ingredient : ingredients.keySet()) {
     count = ingredients.get(ingredient);
     if (recipe.amountOf(ingredient) == 0) {
       // this ingredient doesnt belong into the recipe
       if (count > (getIngredientsCount() / 2)) {
         // when more than half of the ingredients dont fit into the
         // recipe
         return -1;
       }
       badStuff++;
       if (badStuff < ingredients.size()) {
         // when there are other ingredients
         quality -= count * (recipe.getDifficulty() / 2);
         continue;
       } else {
         // ingredients dont fit at all
         return -1;
       }
     }
     // calculate the quality
     quality -=
         ((float) Math.abs(count - recipe.amountOf(ingredient))
                 / recipe.allowedCountDiff(recipe.amountOf(ingredient)))
             * 10.0;
   }
   if (quality >= 0) {
     return Math.round(quality);
   }
   return -1;
 }
Esempio n. 10
0
 // returns pseudo quality of distilling. 0 if doesnt match the need of the recipes distilling
 public int getDistillQuality(BRecipe recipe, int distillRuns) {
   if (recipe.needsDistilling() != distillRuns > 0) {
     return 0;
   }
   return 10 - Math.abs(recipe.getDistillRuns() - distillRuns);
 }
Esempio n. 11
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;
  }