From ea06f2d707eb4599b91296263b867f208743049a Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 30 Aug 2013 21:19:49 +0200 Subject: [PATCH 01/22] Added cmd Unlabel & Several Fixes --- config.yml | 14 +- readme.md | 6 + src/com/dre/brewery/BIngredients.java | 6 +- src/com/dre/brewery/BPlayer.java | 60 +++-- src/com/dre/brewery/BRecipe.java | 4 +- src/com/dre/brewery/Barrel.java | 13 +- src/com/dre/brewery/Brew.java | 238 ++++++++++-------- src/com/dre/brewery/P.java | 3 +- .../dre/brewery/listeners/BlockListener.java | 10 +- .../brewery/listeners/CommandListener.java | 32 +++ .../brewery/listeners/InventoryListener.java | 10 +- 11 files changed, 245 insertions(+), 151 deletions(-) diff --git a/config.yml b/config.yml index 8c4c21d..a34a0de 100644 --- a/config.yml +++ b/config.yml @@ -41,7 +41,7 @@ drainItems: # Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden colorInBarrels: true -colorInBrewer: true +colorInBrewer: false # Autosave Intervall in Minuten autosave: 3 @@ -49,11 +49,11 @@ autosave: 3 # Rezepte für Getränke -# name: Verschiedene Namen für schlecht/mittel/gut +# name: Verschiedene Namen für schlecht/mittel/gut (Farbcodes möglich: z.b. &6) # ingredients: Auflistung von material/Anzahl # cookingtime: Zeit in Echtminuten die die Zutaten kochen müssen -# distillruns: Wie oft destilliert werden muss 0-10 (0=ohne Destillieren) -# wood: Holz des Fasses 0=alle Holzsorten 1=Birch 2=Oak 3=Jungle 4=Pine +# distillruns: Wie oft destilliert werden muss für vollen Alkoholgehalt (0=ohne Destillieren) +# wood: Holz des Fasses 0=alle Holzsorten 1=Birch 2=Oak 3=Jungle 4=Spruce # age: Zeit in Minecraft-Tagen, die das Getränk im Fass reifen muss 0= kein reifen # color: Farbe des Getränks nach destillieren/reifen. DARK_RED, RED, BRIGHT_RED, ORANGE, PINK, BLUE, CYAN, WATER, GREEN, BLACK, GREY, BRIGHT_GREY # difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer) @@ -97,7 +97,7 @@ recipes: difficulty: 2 alcohol: 7 4: - name: Scheußlicher Met/Met/Goldener Met + name: Scheußlicher Met/Met/&6Goldener Met ingredients: - SUGAR_CANE/6 cookingtime: 3 @@ -108,7 +108,7 @@ recipes: difficulty: 2 alcohol: 9 5: - name: Apfelmet/Süßer Apfelmet/Goldensüßer Apfelmet + name: Apfelmet/Süßer Apfelmet/&6Goldensüßer Apfelmet ingredients: - SUGAR_CANE/6 - APPLE/2 @@ -122,7 +122,7 @@ recipes: effects: - WATER_BREATHINGX/150 6: - name: Bitterer Rum/Würziger Rum/Goldener Rum + name: Bitterer Rum/Würziger Rum/&6Goldener Rum ingredients: - SUGAR_CANE/14 cookingtime: 5 diff --git a/readme.md b/readme.md index 987d08e..be2dca2 100644 --- a/readme.md +++ b/readme.md @@ -64,6 +64,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver /br [Spieler] [Trunkenheit] [Qualität]Setzen der Spielerwerte. Trunkenheit in %, Qualität von 1-10. + + /br UnLabelVersteckt die genauen Zahlen in der Beschriftung des Trankes in der Hand unwiederbringlich + /br Copy [Anzahl]Kopiert den Trank in der Hand. Optional kann die Anzahl angegeben werden @@ -99,6 +102,9 @@ Auch hier können anhand der Erklärungen und Beispiele bestehende "Wörter" ver PermissionErmöglichter BefehlBeschreibung + + brewery.cmd.unlabelUnLabelTeile der Trankbeschriftung verstecken + brewery.cmd.infoInfoInformationen über die eigene Trunkenheit diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index f52fc95..b85c967 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -139,8 +139,8 @@ public class BIngredients { // needs riping in barrel ageQuality = getAgeQuality(recipe, time); woodQuality = getWoodQuality(recipe, wood); - P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + getWoodQuality(recipe, wood) + - " age Quality: " + getAgeQuality(recipe, time) + " for " + recipe.getName(5)); + P.p.log("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) { @@ -269,7 +269,7 @@ public class BIngredients { // type of wood doesnt matter return 10; } - int quality = 10 - (int) Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty()); + int quality = 10 - (recipe.getWoodDiff(wood) * recipe.getDifficulty()); if (quality > 0) { return quality; diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 5f19189..e86f874 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -73,8 +73,9 @@ public class BPlayer { return org.bukkit.Bukkit.getPlayer(getPlayerName()); }*/ + // returns the Player if online public static Player getPlayer(String name) { - return org.bukkit.Bukkit.getPlayer(name); + return org.bukkit.Bukkit.getPlayerExact(name); } // returns true if drinking was successful @@ -93,14 +94,16 @@ public class BPlayer { players.put(player.getName(), bPlayer); } bPlayer.drunkeness += brewAlc; - bPlayer.quality += brew.getQuality() * brewAlc; + if (brew.getQuality() > 0) { + bPlayer.quality += brew.getQuality() * brewAlc; + } else { + bPlayer.quality += brewAlc; + } if (bPlayer.drunkeness <= 100) { addBrewEffects(brew, player); - if (brew.getQuality() < 5) { - addQualityEffects(brew.getQuality(), brewAlc, player); - } + addQualityEffects(brew.getQuality(), brewAlc, player); } else { bPlayer.drinkCap(player); @@ -196,6 +199,9 @@ public class BPlayer { passedOut = true; } + + // #### Login #### + // can the player login or is he too drunk public int canJoin() { if (drunkeness <= 70) { @@ -290,13 +296,8 @@ public class BPlayer { } } - public void hangoverEffects(final Player player) { - int duration = offlineDrunk * 50 * getHangoverQuality(); - int amplifier = getHangoverQuality() / 3; - PotionEffectType.SLOW.createEffect(duration, amplifier).apply(player); - PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player); - } + // #### Puking #### // Chance that players puke on big drunkeness // runs every 6 sec, average chance is 10%, so should puke about every 60 sec @@ -358,6 +359,9 @@ public class BPlayer { item.setPickupDelay(Integer.MAX_VALUE); } + + // #### Effects #### + public void drunkEffects(Player player) { int duration = 10 - getQuality(); duration += drunkeness / 2; @@ -372,17 +376,21 @@ public class BPlayer { public static void addQualityEffects(int quality, int brewAlc, Player player) { int duration = 7 - quality; - duration *= 250; - PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player); - - if (brewAlc > 15) { - duration = 10 - quality; - duration += brewAlc; - duration *= 40; + if (quality <= 5) { + duration *= 250; } else { duration = 200; } PotionEffectType.POISON.createEffect(duration, 0).apply(player); + + if (brewAlc > 10 && quality <= 5) { + duration = 10 - quality; + duration += brewAlc; + duration *= 60; + } else { + duration = 240; + } + PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player); } public static void addBrewEffects(Brew brew, Player player) { @@ -396,6 +404,7 @@ public class BPlayer { type.createEffect(0, duration - 1).apply(player); } else { int amplifier = brew.getQuality() / 3; + duration /= type.getDurationModifier(); type.createEffect(duration * 20, amplifier).apply(player); } } @@ -403,6 +412,17 @@ public class BPlayer { } } + public void hangoverEffects(final Player player) { + int duration = offlineDrunk * 50 * getHangoverQuality(); + int amplifier = getHangoverQuality() / 3; + + PotionEffectType.SLOW.createEffect(duration, amplifier).apply(player); + PotionEffectType.HUNGER.createEffect(duration, amplifier).apply(player); + } + + + // #### Sheduled #### + public static void drunkeness() { for (String name : players.keySet()) { BPlayer bplayer = players.get(name); @@ -458,7 +478,9 @@ public class BPlayer { } } - // getter + + // #### getter/setter #### + public int getDrunkeness() { return drunkeness; } diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index d1c489d..bc5415b 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -84,7 +84,7 @@ public class BRecipe { } // difference between given and recipe-wanted woodtype - public float getWoodDiff(byte wood) { + public int getWoodDiff(byte wood) { int woodType = 0; if (wood == 0x0) { woodType = 2; @@ -95,7 +95,7 @@ public class BRecipe { } else if (wood == 0x3) { woodType = 3; } - return Math.abs(woodType - wood); + return Math.abs(woodType - this.wood); } public boolean isCookingOnly() { diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index fa17d3b..6a01f94 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -79,13 +79,13 @@ public class Barrel { if (inventory.getViewers().isEmpty()) { // if inventory contains potions if (inventory.contains(373)) { + byte wood = getWood(); long loadTime = System.nanoTime(); for (ItemStack item : inventory.getContents()) { if (item != null) { - if (item.getTypeId() == 373) { - if (item.hasItemMeta()) { - Brew.age(item, time, getWood()); - } + Brew brew = Brew.get(item); + if (brew != null) { + brew.age(item, time, wood); } } } @@ -129,9 +129,10 @@ public class Barrel { ItemStack[] items = inventory.getContents(); for (ItemStack item : items) { if (item != null) { - if (item.getTypeId() == 373) { + Brew brew = Brew.get(item); + if (brew != null) { // Brew before throwing - Brew.age(item, time, getWood()); + brew.age(item, time, getWood()); } // "broken" is the block that destroyed, throw them there! if (broken != null) { diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index f8a70c9..7daf187 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -29,6 +29,7 @@ public class Brew { private int distillRuns; private float ageTime; private BRecipe currentRecipe; + private boolean unlabeled; public Brew(int uid, BIngredients ingredients) { this.ingredients = ingredients; @@ -44,12 +45,13 @@ public class Brew { } // loading from file - public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe) { + public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe, Boolean unlabeled) { this.ingredients = ingredients; this.quality = quality; this.distillRuns = distillRuns; this.ageTime = ageTime; this.currentRecipe = BIngredients.getRecipeByName(recipe); + this.unlabeled = unlabeled; potions.put(uid, this); } @@ -133,21 +135,38 @@ public class Brew { Brew brew = new Brew(uid, quality, currentRecipe, ingredients); brew.distillRuns = distillRuns; brew.ageTime = ageTime; + brew.unlabeled = unlabeled; return brew; } // calculate alcohol from recipe public int calcAlcohol() { + if (quality == 0) { + // Give bad potions some alc + if (distillRuns > 1) { + return distillRuns; + } else { + return 1; + } + } if (currentRecipe != null) { int alc = currentRecipe.getAlcohol(); - alc *= ((float) quality / 10.0); if (currentRecipe.needsDistilling()) { - // distillable Potions should have full alc after 6 distills - float factor = 1.4F / (distillRuns + 1); - factor += 0.8; - alc /= factor; + if (distillRuns == 0) { + return 0; + } + // bad quality can decrease alc by up to 40% + alc *= 1 - ((float) (10 - quality) * 0.04); + // distillable Potions should have half alc after one and full alc after all needed distills + alc /= 2; + alc *= 1.0F + ((float) distillRuns / currentRecipe.getDistillRuns()) ; + } else { + // quality decides 10% - 100% + alc *= ((float) quality / 10.0); + } + if (alc > 0) { + return alc; } - return alc; } return 0; } @@ -171,24 +190,37 @@ public class Brew { } public boolean canDistill() { - if (distillRuns >= 6) { + if (currentRecipe != null) { + return currentRecipe.getDistillRuns() > distillRuns; + } else if (distillRuns >= 6) { return false; - } else { - if (currentRecipe != null) { - return currentRecipe.needsDistilling(); - } } return true; } // return special effect public Map getEffects() { - if (currentRecipe != null) { + if (currentRecipe != null && quality > 0) { return currentRecipe.getEffects(); } return null; } + // Set unlabeled to true to hide the numbers in Lore + public void unLabel(ItemStack item) { + PotionMeta meta = (PotionMeta) item.getItemMeta(); + if (meta.hasLore()) { + if (distillRuns > 0) { + addOrReplaceLore(meta, P.p.color("&7"), "Destilliert"); + } + if (ageTime >= 1) { + addOrReplaceLore(meta, P.p.color("&7"), "Fassgereift"); + } + item.setItemMeta(meta); + } + unlabeled = true; + } + // Distilling section --------------- // distill all custom potions in the brewer @@ -196,104 +228,87 @@ public class Brew { int slot = 0; while (slot < 3) { if (contents[slot]) { - distillSlot(inv, slot); + ItemStack slotItem = inv.getItem(slot); + PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta(); + Brew brew = get(potionMeta); + brew.distillSlot(slotItem, potionMeta); } slot++; } } // distill custom potion in given slot - public static void distillSlot(BrewerInventory inv, int slot) { - ItemStack slotItem = inv.getItem(slot); - PotionMeta potionMeta = (PotionMeta) slotItem.getItemMeta(); - Brew brew = get(potionMeta); - BRecipe recipe = brew.ingredients.getdistillRecipe(); - + public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) { + distillRuns += 1; + BRecipe recipe = ingredients.getdistillRecipe(); if (recipe != null) { // distillRuns will have an effect on the amount of alcohol, not the quality - brew.quality = brew.calcQuality(recipe, (byte) 0, true); - brew.distillRuns += 1; - brew.currentRecipe = recipe; + quality = calcQuality(recipe, (byte) 0, true); + currentRecipe = recipe; + P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); - // Distill Lore - if (colorInBrewer != hasColorLore(potionMeta)) { - brew.convertLore(potionMeta, colorInBrewer); - } else { - String prefix = P.p.color("&7"); - if (colorInBrewer) { - prefix = getQualityColor(brew.ingredients.getDistillQuality(recipe, brew.distillRuns)); - } - brew.updateDistillLore(prefix, potionMeta); - } - addOrReplaceEffects(potionMeta, brew.getEffects()); - - P.p.log("destilled " + recipe.getName(5) + " has Quality: " + brew.quality + ", alc: " + brew.calcAlcohol()); - - potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality))); - - // if the potion should be further distillable - if (recipe.getDistillRuns() > 1 && brew.distillRuns <= 5) { - slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(true)); - } else { - slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false)); - } + addOrReplaceEffects(potionMeta, getEffects()); + potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); + slotItem.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill())); } else { + quality = 0; potionMeta.setDisplayName(P.p.color("&f" + "Undefinierbares Destillat")); - slotItem.setDurability(PotionColor.GREY.getColorId(brew.distillRuns <= 5)); + slotItem.setDurability(PotionColor.GREY.getColorId(canDistill())); } + // Distill Lore + if (currentRecipe != null) { + if (colorInBrewer != hasColorLore(potionMeta)) { + convertLore(potionMeta, colorInBrewer); + } + } + String prefix = P.p.color("&7"); + if (colorInBrewer && currentRecipe != null) { + prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns)); + } + updateDistillLore(prefix, potionMeta); + slotItem.setItemMeta(potionMeta); } // Ageing Section ------------------ - public static void age(ItemStack item, float time, byte wood) { + public void age(ItemStack item, float time, byte wood) { PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); - Brew brew = get(potionMeta); - if (brew != null) { - brew.ageTime += time; - // if younger than half a day, it shouldnt get aged form - if (brew.ageTime > 0.5) { - BRecipe recipe = brew.ingredients.getAgeRecipe(wood, brew.ageTime, brew.distillRuns > 0); - if (recipe != null) { - brew.quality = brew.calcQuality(recipe, wood, brew.distillRuns > 0); - brew.currentRecipe = recipe; - P.p.log("Final " + recipe.getName(5) + " has Quality: " + brew.quality); + ageTime += time; + + // if younger than half a day, it shouldnt get aged form + if (ageTime > 0.5) { + BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0); + if (recipe != null) { + currentRecipe = recipe; + quality = calcQuality(recipe, wood, distillRuns > 0); + P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); - potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(brew.quality))); - item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(false)); - } - } - - // Lore - if (colorInBarrels != hasColorLore(potionMeta)) { - brew.convertLore(potionMeta, colorInBarrels); + addOrReplaceEffects(potionMeta, getEffects()); + potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); + item.setDurability(PotionColor.valueOf(recipe.getColor()).getColorId(canDistill())); } else { - if (brew.ageTime >= 1) { - String prefix = P.p.color("&7"); - if (colorInBarrels) { - prefix = getQualityColor(brew.ingredients.getAgeQuality(brew.currentRecipe, brew.ageTime)); - } - brew.updateAgeLore(prefix, potionMeta); - addOrReplaceEffects(potionMeta, brew.getEffects()); - } + quality = 0; + potionMeta.setDisplayName(P.p.color("&f" + "Verdorbenes Getränk")); + item.setDurability(PotionColor.GREY.getColorId(canDistill())); } - item.setItemMeta(potionMeta); } - } - public static void addOrReplaceEffects(PotionMeta meta, Map effects) { - if (effects != null) { - for (Map.Entry entry : effects.entrySet()) { - if (!entry.getKey().endsWith("X")) { - PotionEffectType type = PotionEffectType.getByName(entry.getKey()); - if (type != null) { - meta.addCustomEffect(type.createEffect(0, 0), true); - } - } + // Lore + if (currentRecipe != null) { + if (colorInBarrels != hasColorLore(potionMeta)) { + convertLore(potionMeta, colorInBarrels); } - } + if (ageTime >= 1) { + String prefix = P.p.color("&7"); + if (colorInBarrels && currentRecipe != null) { + prefix = getQualityColor(ingredients.getAgeQuality(currentRecipe, ageTime)); + } + updateAgeLore(prefix, potionMeta); + } + item.setItemMeta(potionMeta); } // Lore ----------- @@ -303,17 +318,13 @@ public class Brew { if (currentRecipe == null) { return; } - if (meta == null) { - P.p.log("has no meta"); - return; - } meta.setLore(null); - - // Ingredients int quality; String prefix = P.p.color("&7"); String lore; - if (toQuality) { + + // Ingredients + if (toQuality && !unlabeled) { quality = ingredients.getIngredientQuality(currentRecipe); prefix = getQualityColor(quality); lore = "Zutaten"; @@ -321,7 +332,7 @@ public class Brew { } // Cooking - if (toQuality) { + if (toQuality && !unlabeled) { if (distillRuns > 0 == currentRecipe.needsDistilling()) { quality = ingredients.getCookingQuality(currentRecipe, distillRuns > 0); prefix = getQualityColor(quality) + ingredients.getCookedTime() + " minute"; @@ -354,22 +365,26 @@ public class Brew { // sets the DistillLore. Prefix is the color to be used public void updateDistillLore(String prefix, PotionMeta meta) { - if (distillRuns > 1) { - prefix = prefix + distillRuns + "-fach "; + if (!unlabeled) { + if (distillRuns > 1) { + prefix = prefix + distillRuns + "-fach "; + } } - addOrReplaceLore(meta, prefix, "destilliert"); + addOrReplaceLore(meta, prefix, "Destilliert"); } // sets the AgeLore. Prefix is the color to be used public void updateAgeLore(String prefix, PotionMeta meta) { - if (ageTime >= 1 && ageTime < 2) { - prefix = prefix + "Ein Jahr"; - } else if (ageTime < 201) { - prefix = prefix + (int) Math.floor(ageTime) + " Jahre"; - } else { - prefix = prefix + "Hunderte Jahre"; + if (!unlabeled) { + if (ageTime >= 1 && ageTime < 2) { + prefix = prefix + "Ein Jahr "; + } else if (ageTime < 201) { + prefix = prefix + (int) Math.floor(ageTime) + " Jahre "; + } else { + prefix = prefix + "Hunderte Jahre "; + } } - addOrReplaceLore(meta, prefix, " Fassgereift"); + addOrReplaceLore(meta, prefix, "Fassgereift"); } // Adds or replaces a line of Lore. Searches for Substring lore and replaces it @@ -391,6 +406,20 @@ public class Brew { meta.setLore(newLore); } + // Adds the Effect names to the Items description + public static void addOrReplaceEffects(PotionMeta meta, Map effects) { + if (effects != null) { + for (Map.Entry entry : effects.entrySet()) { + if (!entry.getKey().endsWith("X")) { + PotionEffectType type = PotionEffectType.getByName(entry.getKey()); + if (type != null) { + meta.addCustomEffect(type.createEffect(0, 0), true); + } + } + } + } + } + // Returns the Index of a String from the list that contains this substring public static int indexOfSubstring(List list, String substring) { for (int index = 0; index < list.size(); index++) { @@ -445,6 +474,9 @@ public class Brew { if (brew.currentRecipe != null) { idConfig.set("recipe", brew.currentRecipe.getName(5)); } + if (brew.unlabeled) { + idConfig.set("unlabeled", true); + } // save the ingredients brew.ingredients.save(idConfig.createSection("ingredients")); } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 15e3caa..8326aa8 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -200,8 +200,9 @@ public class P extends JavaPlugin { int distillRuns = section.getInt(uid + ".distillRuns", 0); float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0); String recipe = section.getString(uid + ".recipe", null); + Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); - new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe); + new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe, unlabeled); } } diff --git a/src/com/dre/brewery/listeners/BlockListener.java b/src/com/dre/brewery/listeners/BlockListener.java index 50bbd96..03062cb 100644 --- a/src/com/dre/brewery/listeners/BlockListener.java +++ b/src/com/dre/brewery/listeners/BlockListener.java @@ -7,7 +7,6 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import com.dre.brewery.BCauldron; import com.dre.brewery.Barrel; @@ -31,12 +30,9 @@ public class BlockListener implements Listener { Block block = event.getBlock(); // remove cauldron if (block.getType() == Material.CAULDRON) { - if (block.getRelative(BlockFace.DOWN).getType() == Material.FIRE || block.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA - || block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { - if (block.getData() != 0) { - // will only remove when existing - BCauldron.remove(block); - } + if (block.getData() != 0) { + // will only remove when existing + BCauldron.remove(block); } // remove barrel and throw potions on the ground } else if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) { diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index e18ad0e..6823c10 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -86,6 +86,14 @@ public class CommandListener implements CommandExecutor { p.msg(sender, "&cDu hast keine Rechte dies zu tun!"); } + } else if (cmd.equalsIgnoreCase("unlabel")) { + + if (p.permission.has(sender, "brewery.cmd.unlabel")) { + cmdUnlabel(sender); + } else { + p.msg(sender, "&cDu hast keine Rechte dies zu tun!"); + } + } else { if (p.getServer().getPlayerExact(cmd) != null || BPlayer.players.containsKey(cmd)) { @@ -143,6 +151,10 @@ public class CommandListener implements CommandExecutor { cmds.add ("&6/br Info&9 Zeigt deine aktuelle Trunkenheit und Qualität an"); } + if (p.permission.has(sender, "brewery.cmd.unlabel")) { + cmds.add ("&6/br UnLabel &9Entfernt die genaue Beschriftung des Trankes"); + } + if (p.permission.has(sender, "brewery.cmd.copy")) { cmds.add ("&6/br Copy &9 Kopiert den Trank in deiner Hand"); } @@ -335,4 +347,24 @@ public class CommandListener implements CommandExecutor { } + public void cmdUnlabel(CommandSender sender) { + + if (sender instanceof Player) { + Player player = (Player) sender; + ItemStack hand = player.getItemInHand(); + if (hand != null) { + Brew brew = Brew.get(hand); + if (brew != null) { + brew.unLabel(hand); + p.msg(sender, "&aDas Label wurde entfernt"); + return; + } + } + p.msg(sender, "&cDas Item in deiner Hand konnte nicht als Trank identifiziert werden"); + } else { + p.msg(sender, "&cDieser Befehl kann nur als Spieler ausgeführt werden"); + } + + } + } \ No newline at end of file diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 3182bd0..990a675 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -56,10 +56,12 @@ public class InventoryListener implements Listener { if (event.getSlot() > 2) { return; } - } else if (event.getInventory().getType() != InventoryType.CHEST) { + } else if (event.getInventory().getType() == InventoryType.CHEST) { if (!event.getInventory().getTitle().equals("Fass")) { return; } + } else { + return; } ItemStack item = event.getCurrentItem(); @@ -69,8 +71,10 @@ public class InventoryListener implements Listener { PotionMeta meta = (PotionMeta) item.getItemMeta(); Brew brew = Brew.get(meta); if (brew != null) { - brew.convertLore(meta, false); - item.setItemMeta(meta); + if (Brew.hasColorLore(meta)) { + brew.convertLore(meta, false); + item.setItemMeta(meta); + } } } } From 33285e54dedb82f1c6a895cdf54918819d2e7790 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sat, 31 Aug 2013 18:23:03 +0200 Subject: [PATCH 02/22] Alc changes for bad potions --- config.yml | 4 ++-- src/com/dre/brewery/BPlayer.java | 4 +++- src/com/dre/brewery/Brew.java | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index a34a0de..8a20cb8 100644 --- a/config.yml +++ b/config.yml @@ -59,8 +59,8 @@ autosave: 3 # difficulty: 1-10 Genauigkeit der Einhaltung der Vorgaben (1 = ungenau/einfach 10 = sehr genau/schwer) # alcohol: Alkoholgehalt 0-100 in absoluter Menge bei perfektem Getränk (wird dem Spieler hinzugefügt, bei 100 = tot) # effects: Auflistung Effekt/Dauer Besonderere Trank-Effekte beim Trinken, Dauer in sek. Ein 'X' an den Namen anhängen, um ihn zu verbergen. Bsp: POISONX/10 -# (WEAKNESS, INCREASE_DAMAGE, SLOW und SPEED sind immer verborgen.) Mögliche Effekte: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html -# Bei Effekten mit sofortiger Wirkung (z.B. HEAL) muss anstatt der Dauer das Level angegeben werden. +# (WEAKNESS, INCREASE_DAMAGE, SLOW und SPEED sind immer verborgen.) Mögliche Effekte: http://jd.bukkit.org/rb/apidocs/org/bukkit/potion/PotionEffectType.html +# Bei Effekten mit sofortiger Wirkung (z.B. HEAL) _muss_ anstatt der Dauer das Level angegeben werden. recipes: 1: diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index e86f874..f1fd34a 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -376,7 +376,9 @@ public class BPlayer { public static void addQualityEffects(int quality, int brewAlc, Player player) { int duration = 7 - quality; - if (quality <= 5) { + if (quality == 0) { + duration *= 500; + } else if (quality <= 5) { duration *= 250; } else { duration = 200; diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 7daf187..171da5f 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -143,12 +143,22 @@ public class Brew { public int calcAlcohol() { if (quality == 0) { // Give bad potions some alc + int badAlc = 0; if (distillRuns > 1) { - return distillRuns; + badAlc = distillRuns; + } + if (ageTime > 10) { + badAlc += 5; + } else if (ageTime > 2) { + badAlc += 3; + } + if (currentRecipe != null) { + return badAlc; } else { - return 1; + return badAlc / 2; } } + if (currentRecipe != null) { int alc = currentRecipe.getAlcohol(); if (currentRecipe.needsDistilling()) { From c748e0b7b5f687b30e2fac44835edd8018cfec37 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 1 Sep 2013 18:58:51 +0200 Subject: [PATCH 03/22] Reduced Difficulty for small Ingredient amounts --- src/com/dre/brewery/BIngredients.java | 4 ++-- src/com/dre/brewery/BRecipe.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index b85c967..cc9930a 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -226,7 +226,7 @@ public class BIngredients { badStuff++; if (badStuff < ingredients.size()) { // when there are other ingredients - quality -= count * 2; + quality -= count * (recipe.getDifficulty() / 2); continue; } else { // ingredients dont fit at all @@ -234,7 +234,7 @@ public class BIngredients { } } // calculate the quality - quality -= (((float) Math.abs(count - recipe.amountOf(ingredient)) / recipe.allowedCountDiff(recipe.amountOf(ingredient))) * 10.0); + quality -= ((float) Math.abs(count - recipe.amountOf(ingredient)) / recipe.allowedCountDiff(recipe.amountOf(ingredient))) * 10.0; } if (quality >= 0) { return Math.round(quality); diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index bc5415b..e5f8bb3 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -47,7 +47,11 @@ public class BRecipe { for (String effectString : effectStringList) { String[] effectSplit = effectString.split("/"); String effect = effectSplit[0]; - if (effect.equalsIgnoreCase("WEAKNESS") || effect.equalsIgnoreCase("INCREASE_DAMAGE") || effect.equalsIgnoreCase("SLOW") || effect.equalsIgnoreCase("SPEED") || effect.equalsIgnoreCase("REGERATION")) { + if (effect.equalsIgnoreCase("WEAKNESS") || + effect.equalsIgnoreCase("INCREASE_DAMAGE") || + effect.equalsIgnoreCase("SLOW") || + effect.equalsIgnoreCase("SPEED") || + effect.equalsIgnoreCase("REGENERATION")) { // hide these effects as they put crap into lore effect = effect + "X"; } @@ -62,6 +66,9 @@ public class BRecipe { // allowed deviation to the recipes count of ingredients at the given difficulty public int allowedCountDiff(int count) { + if (count < 8) { + count = 8; + } int allowedCountDiff = Math.round((float) ((11.0 - difficulty) * (count / 10.0))); if (allowedCountDiff == 0) { From b09131c2e09e7ee5c0a88e87d765299ad1a9f5a0 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 1 Sep 2013 20:26:19 +0200 Subject: [PATCH 04/22] Also for small cooking time --- src/com/dre/brewery/BIngredients.java | 3 +++ src/com/dre/brewery/BRecipe.java | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index cc9930a..0c4c9b9 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -247,6 +247,9 @@ public class BIngredients { if (!recipe.needsDistilling() == distilled) { return 0; } + if (cookedTime <= 1) { + return 0; + } int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0); if (quality > 0) { diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index e5f8bb3..413d152 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -79,11 +79,11 @@ public class BRecipe { // allowed deviation to the recipes cooking-time at the given difficulty public int allowedTimeDiff(int time) { + if (time < 8) { + time = 8; + } int allowedTimeDiff = Math.round((float) ((11.0 - difficulty) * (time / 10.0))); - while (allowedTimeDiff >= time) { - allowedTimeDiff -= 1; - } if (allowedTimeDiff == 0) { return 1; } From c7c72e1699fe459e2cecbeaf971e4a1fa3f2439a Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 1 Sep 2013 21:37:38 +0200 Subject: [PATCH 05/22] Dont get non-distill Recipe for distilled Brew --- src/com/dre/brewery/BIngredients.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index 0c4c9b9..c551b78 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -134,7 +134,7 @@ public class BIngredients { ingredientQuality = getIngredientQuality(recipe); cookingQuality = getCookingQuality(recipe, distilled); - if (ingredientQuality > -1) { + if (ingredientQuality > -1 && cookingQuality > -1) { if (recipe.needsToAge()) { // needs riping in barrel ageQuality = getAgeQuality(recipe, time); @@ -245,17 +245,17 @@ public class BIngredients { // returns the quality regarding the cooking-time conditioning given Recipe public int getCookingQuality(BRecipe recipe, boolean distilled) { if (!recipe.needsDistilling() == distilled) { - return 0; - } - if (cookedTime <= 1) { - return 0; + return -1; } int quality = 10 - (int) Math.round(((float) Math.abs(cookedTime - recipe.getCookingTime()) / recipe.allowedTimeDiff(recipe.getCookingTime())) * 10.0); - if (quality > 0) { + if (quality >= 0) { + if (cookedTime <= 1) { + return 0; + } return quality; } - return 0; + return -1; } // returns pseudo quality of distilling. 0 if doesnt match the need of the recipes distilling From 16bb62c8544742745052f8b075640555619f1870 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 1 Sep 2013 21:45:02 +0200 Subject: [PATCH 06/22] Fixed dropping Potions with colored Lore --- src/com/dre/brewery/Barrel.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 6a01f94..5293b0f 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import org.bukkit.block.Block; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.configuration.ConfigurationSection; public class Barrel { @@ -133,6 +134,11 @@ public class Barrel { if (brew != null) { // Brew before throwing brew.age(item, time, getWood()); + PotionMeta meta = (PotionMeta) item.getItemMeta(); + if (Brew.hasColorLore(meta)) { + brew.convertLore(meta, false); + item.setItemMeta(meta); + } } // "broken" is the block that destroyed, throw them there! if (broken != null) { From edfeab1fc8d10208e95ccf19b3e68e3744f3270b Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 1 Sep 2013 23:47:01 +0200 Subject: [PATCH 07/22] Fixed Hangover --- config.yml | 23 ++++++++----- src/com/dre/brewery/BPlayer.java | 34 +++++++++++++------ src/com/dre/brewery/P.java | 1 + .../brewery/listeners/CommandListener.java | 3 ++ .../dre/brewery/listeners/PlayerListener.java | 9 +++++ 5 files changed, 51 insertions(+), 19 deletions(-) diff --git a/config.yml b/config.yml index 8a20cb8..724035c 100644 --- a/config.yml +++ b/config.yml @@ -2,11 +2,13 @@ # Verschiedene Einstellungen +# Standardeinstellungen sind in [] angegeben +# Löschen einzelner Einstellungen deaktiviert sie -# Ob der Spieler beim nächsten Einloggen nach starker Trunkenheit am nächsten morgen Zuhause "aufwacht" (Ein home Plugin muss installiert sein!) +# Ob der Spieler beim nächsten Einloggen nach starker Trunkenheit am nächsten morgen Zuhause "aufwacht" (Ein home Plugin muss installiert sein!) [true] enableHome: true -# Art des Nachhause-teleports: +# Art des Nachhause-teleports: ['cmd: home'] # bed = Spieler wird zu seinem Spawn Bett teleportiert # SamplePlugin = installiertes home plugin. Unterstützt: ManagerXL. Wenn dies nicht geht: # 'cmd: home' = /home wird vom Spieler ausgelöst. Es sollte kein Verzögerungs, etc. plugin installiert sein! @@ -15,23 +17,23 @@ enableHome: true homeType: 'cmd: home' # Ob der Spieler nach etwas kürzerem Ausloggen an einem zufälligen Ort "aufwacht" (diese müssen durch '/br Wakeup add' von einem Admin festgelegt werden) -# Der Spieler wacht an dem nähesten zweier zufälliger Orte aus seiner Welt auf. +# Der Spieler wacht an dem nähesten zweier zufälliger Orte aus seiner Welt auf. [true] enableWake: true # Der Text, den der Spieler beim Aufwachen sieht wakeString: 'Ohh nein! Ich kann mich nicht erinnern, wie ich hier hergekommen bin... *hicks*' -# Ob der Spieler sich bei großer Trunkenheit teilweise nicht einloggen kann und kurz warten muss, da sein Charakter nicht reagiert +# Ob der Spieler sich bei großer Trunkenheit teilweise nicht einloggen kann und kurz warten muss, da sein Charakter nicht reagiert [true] enableLoginDisallow: true -# Ob der Spieler sich übertrinken kann und dann in Ohnmacht fällt (gekickt wird) und sich für einige Minuten nicht einloggen kann +# Ob der Spieler sich übertrinken kann und dann in Ohnmacht fällt (gekickt wird) und sich für einige Minuten nicht einloggen kann [true] enableKickOnOverdrink: true -# Ob der Spieler sich bei großer Trunkenheit übergibt (unten definiertes Item aus dem Mund fallen lässt) +# Ob der Spieler sich bei großer Trunkenheit übergibt (unten definiertes Item aus dem Mund fallen lässt) [true] # Das Item kann nicht aufgesammelt werden und bleibt bis zum Despawnen liegen. (Achtung: Kann nach Serverrestart, oder durch Hopper aufgesammelt werden.) enablePuke: true -# Item das beim Erbrechen mehrfach unaufsammelbar fallen gelassen wird +# Item das beim Erbrechen mehrfach unaufsammelbar fallen gelassen wird [SOUL_SAND] pukeItem: SOUL_SAND # Konsumierbares Item/Stärke. Senkt den Alkoholpegel um wenn konsumiert. @@ -39,11 +41,14 @@ drainItems: - BREAD/4 - MILK_BUCKET/2 -# Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden +# Zeit (in Tagen) die Trunkenheitsdaten nach offlinegehen eines Spielers im Speicher verbleiben, um z.B. Kater-Effekte anzuwenden. [7] +hangoverDays: 7 + +# Färben der Iteminformationen je nach Qualität während sie sich 1. im Fass und/oder 2. im Braustand befinden [true, false] colorInBarrels: true colorInBrewer: false -# Autosave Intervall in Minuten +# Autosave Intervall in Minuten [3] autosave: 3 diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index f1fd34a..9e4fbf4 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -19,12 +19,13 @@ import com.dre.brewery.Brew; public class BPlayer { public static Map players = new HashMap();// Players name and BPlayer - public static Map drainItems = new HashMap();// DrainItem Material and Strength private static Map pTasks = new HashMap();// Player and count + private static int taskId; // Settings - private static int taskId; + public static Map drainItems = new HashMap();// DrainItem Material and Strength public static int pukeItemId; + public static int hangoverTime; public static boolean overdrinkKick; public static boolean enableHome; public static boolean enableLoginDisallow; @@ -144,7 +145,9 @@ public class BPlayer { // drain the drunkeness by amount, returns true when player has to be removed public boolean drain(String name, int amount) { - quality -= getQuality() * amount; + if (drunkeness > 0) { + quality -= getQuality() * amount; + } drunkeness -= amount; if (drunkeness > 0) { if (offlineDrunk == 0) { @@ -152,8 +155,13 @@ public class BPlayer { offlineDrunk = drunkeness; } } - } else if (drunkeness <= (-1) * offlineDrunk) { - return true; + } else { + quality = getQuality(); + if (drunkeness <= -offlineDrunk) { + if (drunkeness <= -hangoverTime) { + return true; + } + } } return false; } @@ -274,6 +282,10 @@ public class BPlayer { passedOut = false; } + public void disconnecting() { + offlineDrunk = drunkeness; + } + public void goHome(final Player player) { if (homeType != null) { Location home = null; @@ -505,16 +517,18 @@ public class BPlayer { P.p.errorLog("drunkeness should not be 0!"); return quality; } + if (drunkeness < 0) { + return quality; + } return Math.round(quality / drunkeness); } // opposite of quality public int getHangoverQuality() { - return -getQuality() + 10; - } - - public int getHangoverProgress() { - return offlineDrunk + drunkeness; + if (drunkeness < 0) { + return quality + 11; + } + return -getQuality() + 11; } } \ No newline at end of file diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 8326aa8..a751763 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -137,6 +137,7 @@ public class P extends JavaPlugin { // various Settings autosave = config.getInt("autosave", 3); BPlayer.pukeItemId = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND")).getId(); + 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); diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 6823c10..1bc6d25 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -242,6 +242,9 @@ public class CommandListener implements CommandExecutor { public void cmdPlayer(CommandSender sender, String[] args) { int drunkeness = p.parseInt(args[1]); + if (drunkeness < 0) { + return; + } int quality = -1; if (args.length > 2) { quality = p.parseInt(args[2]); diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index 04df1bf..d4d7c65 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -6,6 +6,7 @@ import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -165,4 +166,12 @@ public class PlayerListener implements Listener { } } } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + BPlayer bplayer = BPlayer.get(event.getPlayer().getName()); + if (bplayer != null) { + bplayer.disconnecting(); + } + } } \ No newline at end of file From bfe859d3bc87845b24be88bc836ebce4cfe4e0c5 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 4 Sep 2013 23:32:09 +0200 Subject: [PATCH 08/22] Optimized Storage of BIngredients --- src/com/dre/brewery/BCauldron.java | 19 ++++++--- src/com/dre/brewery/BIngredients.java | 29 ++++++++----- src/com/dre/brewery/BPlayer.java | 11 +++-- src/com/dre/brewery/Brew.java | 7 ++-- src/com/dre/brewery/P.java | 59 ++++++++++++++++++++------- 5 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 03c3b4c..35f1a85 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -15,14 +15,13 @@ import com.dre.brewery.BIngredients; public class BCauldron { public static CopyOnWriteArrayList bcauldrons = new CopyOnWriteArrayList(); - private BIngredients ingredients; + private BIngredients ingredients = new BIngredients(); private Block block; - private int state; + private int state = 1; + private boolean someRemoved = false; public BCauldron(Block block, Material ingredient) { this.block = block; - this.state = 1; - this.ingredients = new BIngredients(); add(ingredient); bcauldrons.add(this); } @@ -41,11 +40,19 @@ public class BCauldron { || block.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { // add a minute to cooking time state++; + if (someRemoved) { + ingredients = ingredients.clone(); + someRemoved = false; + } } } // add an ingredient to the cauldron public void add(Material ingredient) { + if (someRemoved) { + ingredients = ingredients.clone(); + someRemoved = false; + } ingredients.add(ingredient); block.getWorld().playEffect(block.getLocation(), Effect.EXTINGUISH, 0); if (state > 1) { @@ -98,6 +105,8 @@ public class BCauldron { if (block.getData() == 0) { bcauldrons.remove(bcauldron); + } else { + bcauldron.someRemoved = true; } return true; } @@ -154,7 +163,7 @@ public class BCauldron { if (cauldron.state != 1) { config.set(prefix + ".state", cauldron.state); } - cauldron.ingredients.save(config.createSection(prefix + ".ingredients")); + config.set(prefix + ".ingredients", cauldron.ingredients.serializeIngredients()); id++; } } diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index c551b78..dbe96d9 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -17,19 +17,25 @@ public class BIngredients { public static ArrayList possibleIngredients = new ArrayList(); public static ArrayList recipes = new ArrayList(); public static Map cookedNames = new HashMap(); + private static int lastId = 0; + private int id; private Map ingredients = new HashMap(); private int cookedTime; // Represents ingredients in Cauldron, Brew // Init a new BIngredients public BIngredients() { + this.id = lastId; + lastId++; } // Load from File public BIngredients(Map ingredients, int cookedTime) { this.ingredients = ingredients; this.cookedTime = cookedTime; + this.id = lastId; + lastId++; } //returns the recipe with the given name @@ -69,7 +75,7 @@ public class BIngredients { // Potion is best with cooking only int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0); P.p.log("cooked potion has Quality: " + quality); - Brew brew = new Brew(uid, quality, cookRecipe, clone()); + Brew brew = new Brew(uid, quality, cookRecipe, this); Brew.addOrReplaceEffects(potionMeta, brew.getEffects()); cookedName = cookRecipe.getName(quality); @@ -77,7 +83,7 @@ public class BIngredients { } else { // new base potion - new Brew(uid, clone()); + new Brew(uid, this); if (state <= 1) { cookedName = "Schlammiger Sud"; @@ -298,22 +304,23 @@ public class BIngredients { return copy; } - // saves data into ingredient section of Brew/BCauldron - public void save(ConfigurationSection config) { + // saves data into main Ingredient section. Returns the save id + public int save(ConfigurationSection config) { + String path = "Ingredients." + id; if (cookedTime != 0) { - config.set("cookedTime", cookedTime); + config.set(path + ".cookedTime", cookedTime); } + config.set(path + ".mats", serializeIngredients()); + return id; + } - // convert the ingredient Material to id + // convert the ingredient Material to id + public Map serializeIngredients() { Map mats = new HashMap(); for (Material mat : ingredients.keySet()) { mats.put(mat.getId(), ingredients.get(mat)); } - // list all Material ids with their amount - ConfigurationSection matSection = config.createSection("mats"); - for (int id : mats.keySet()) { - matSection.set("" + id, mats.get(id)); - } + return mats; } } \ No newline at end of file diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 9e4fbf4..d2c7994 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -156,6 +156,9 @@ public class BPlayer { } } } else { + if (offlineDrunk == 0) { + return true; + } quality = getQuality(); if (drunkeness <= -offlineDrunk) { if (drunkeness <= -hangoverTime) { @@ -438,8 +441,9 @@ public class BPlayer { // #### Sheduled #### public static void drunkeness() { - for (String name : players.keySet()) { - BPlayer bplayer = players.get(name); + for (Map.Entry entry : players.entrySet()) { + String name = entry.getKey(); + BPlayer bplayer = entry.getValue(); if (bplayer.drunkeness > 30) { if (bplayer.offlineDrunk == 0) { @@ -462,7 +466,8 @@ public class BPlayer { public static void onUpdate() { if (!players.isEmpty()) { int soberPerMin = 2; - for (Iterator> iter = players.entrySet().iterator(); iter.hasNext();) { + Iterator> iter = players.entrySet().iterator(); + while (iter.hasNext()) { Map.Entry entry = iter.next(); String name = entry.getKey(); BPlayer bplayer = entry.getValue(); diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 171da5f..9208437 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -468,9 +468,10 @@ public class Brew { // Saves all data public static void save(ConfigurationSection config) { - for (int uid : potions.keySet()) { + for (Map.Entry entry : potions.entrySet()) { + int uid = entry.getKey(); + Brew brew = entry.getValue(); ConfigurationSection idConfig = config.createSection("" + uid); - Brew brew = potions.get(uid); // not saving unneccessary data if (brew.quality != 0) { idConfig.set("quality", brew.quality); @@ -488,7 +489,7 @@ public class Brew { idConfig.set("unlabeled", true); } // save the ingredients - brew.ingredients.save(idConfig.createSection("ingredients")); + idConfig.set("ingId", brew.ingredients.save(config.getParent())); } } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index a751763..052d681 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -191,12 +191,32 @@ public class P extends JavaPlugin { FileConfiguration data = YamlConfiguration.loadConfiguration(file); + // loading Ingredients into ingMap + Map ingMap = new HashMap(); + ConfigurationSection section = data.getConfigurationSection("Ingredients"); + if (section != null) { + for (String id : section.getKeys(false)) { + ConfigurationSection matSection = section.getConfigurationSection(id + ".mats"); + if (matSection != null) { + // matSection has all the materials + amount as Integers + Map ingredients = new HashMap(); + for (String ingredient : matSection.getKeys(false)) { + // convert to Material + ingredients.put(Material.getMaterial(parseInt(ingredient)), matSection.getInt(ingredient)); + } + ingMap.put(id, new BIngredients(ingredients, section.getInt(id + ".cookedTime", 0))); + } else { + errorLog("Ingredient id: '" + id + "' incomplete in data.yml"); + } + } + } + // loading Brew - ConfigurationSection section = data.getConfigurationSection("Brew"); + section = data.getConfigurationSection("Brew"); if (section != null) { // All sections have the UID as name for (String uid : section.getKeys(false)) { - BIngredients ingredients = loadIngredients(section.getConfigurationSection(uid + ".ingredients")); + BIngredients ingredients = getIngredients(ingMap, section.getString(uid + ".ingId")); int quality = section.getInt(uid + ".quality", 0); int distillRuns = section.getInt(uid + ".distillRuns", 0); float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0); @@ -234,21 +254,30 @@ public class P extends JavaPlugin { } } - // loads BIngredients from ingredient section - public BIngredients loadIngredients(ConfigurationSection config) { - if (config != null) { - ConfigurationSection matSection = config.getConfigurationSection("mats"); - if (matSection != null) { - // matSection has all the materials + amount in Integer form - Map ingredients = new HashMap(); - for (String ingredient : matSection.getKeys(false)) { - // convert to Material - ingredients.put(Material.getMaterial(parseInt(ingredient)), matSection.getInt(ingredient)); - } - return new BIngredients(ingredients, config.getInt("cookedTime", 0)); + // returns Ingredients by id from the specified ingMap + public BIngredients getIngredients(Map ingMap, String id) { + if (!ingMap.isEmpty()) { + if (ingMap.containsKey(id)) { + return ingMap.get(id); } } - errorLog("Ingredient section not found or incomplete in data.yml"); + errorLog("Ingredient id: '" + id + "' not found in data.yml"); + return new BIngredients(); + } + + // loads BIngredients from an ingredient section + public BIngredients loadIngredients(ConfigurationSection section) { + if (section != null) { + // has all the materials + amount as Integers + Map ingredients = new HashMap(); + for (String ingredient : section.getKeys(false)) { + // convert to Material + ingredients.put(Material.getMaterial(parseInt(ingredient)), section.getInt(ingredient)); + } + return new BIngredients(ingredients, 0); + } else { + errorLog("Cauldron is missing Ingredient Section"); + } return new BIngredients(); } From a990e914965318aa69a027fead7cdfd8eafb83b6 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 4 Sep 2013 23:46:07 +0200 Subject: [PATCH 09/22] Dont Override Interaction while Sneaking --- .../dre/brewery/listeners/PlayerListener.java | 100 +++++++++--------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index d4d7c65..eb9d1e8 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -31,66 +31,68 @@ public class PlayerListener implements Listener { if (clickedBlock != null) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - if (clickedBlock.getType() == Material.CAULDRON) { - if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA - || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { - Material materialInHand = event.getMaterial(); - Player player = event.getPlayer(); - ItemStack item = event.getItem(); + Player player = event.getPlayer(); + if (!player.isSneaking()) { + if (clickedBlock.getType() == Material.CAULDRON) { + if (clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.FIRE || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_LAVA + || clickedBlock.getRelative(BlockFace.DOWN).getType() == Material.LAVA) { + Material materialInHand = event.getMaterial(); + ItemStack item = event.getItem(); - - if (materialInHand == Material.WATCH) { - BCauldron.printTime(player, clickedBlock); + + if (materialInHand == Material.WATCH) { + BCauldron.printTime(player, clickedBlock); - // fill a glass bottle with potion - } else if (materialInHand == Material.GLASS_BOTTLE) { - if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) { - if (BCauldron.fill(player, clickedBlock)) { + // fill a glass bottle with potion + } else if (materialInHand == Material.GLASS_BOTTLE) { + if (player.getInventory().firstEmpty() != -1 || item.getAmount() == 1) { + if (BCauldron.fill(player, clickedBlock)) { + event.setCancelled(true); + if (item.getAmount() > 1) { + item.setAmount(item.getAmount() - 1); + } else { + player.setItemInHand(new ItemStack(0)); + } + } + } else { event.setCancelled(true); + } + + // reset cauldron when refilling to prevent + // unlimited source of potions + } else if (materialInHand == Material.WATER_BUCKET) { + if (clickedBlock.getData() != 0) { + if (clickedBlock.getData() < 3) { + // will only remove when existing + BCauldron.remove(clickedBlock); + } + } + + // add ingredient to cauldron that meet the previous + // contitions + } else if (BIngredients.possibleIngredients.contains(materialInHand)) { + if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) { if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.setItemInHand(new ItemStack(0)); } } - } else { - event.setCancelled(true); - } - - // reset cauldron when refilling to prevent - // unlimited source of potions - } else if (materialInHand == Material.WATER_BUCKET) { - if (clickedBlock.getData() != 0) { - if (clickedBlock.getData() < 3) { - // will only remove when existing - BCauldron.remove(clickedBlock); - } - } - - // add ingredient to cauldron that meet the previous - // contitions - } else if (BIngredients.possibleIngredients.contains(materialInHand)) { - if (BCauldron.ingredientAdd(clickedBlock, materialInHand)) { - if (item.getAmount() > 1) { - item.setAmount(item.getAmount() - 1); - } else { - player.setItemInHand(new ItemStack(0)); - } } } - } - // access a barrel - } else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN - || clickedBlock.getType() == Material.WALL_SIGN) { - Barrel barrel = Barrel.get(clickedBlock); - if (barrel != null) { - event.setCancelled(true); - Block broken = Barrel.getBrokenBlock(clickedBlock); - // barrel is built correctly - if (broken == null) { - barrel.open(event.getPlayer()); - } else { - barrel.remove(broken); + // access a barrel + } else if (clickedBlock.getType() == Material.FENCE || clickedBlock.getType() == Material.NETHER_FENCE || clickedBlock.getType() == Material.SIGN + || clickedBlock.getType() == Material.WALL_SIGN) { + Barrel barrel = Barrel.get(clickedBlock); + if (barrel != null) { + event.setCancelled(true); + Block broken = Barrel.getBrokenBlock(clickedBlock); + // barrel is built correctly + if (broken == null) { + barrel.open(player); + } else { + barrel.remove(broken); + } } } } From 8a5f19899c898f9a689e41578ceed4d873e90245 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 17:09:20 +0200 Subject: [PATCH 10/22] Reworked Barrel Wood Type --- src/com/dre/brewery/BIngredients.java | 19 +++--- src/com/dre/brewery/BRecipe.java | 31 ++------- src/com/dre/brewery/Barrel.java | 49 +++++++++------ src/com/dre/brewery/Brew.java | 90 ++++++++++++++++++++++----- src/com/dre/brewery/P.java | 3 +- 5 files changed, 124 insertions(+), 68 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index dbe96d9..7526e59 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -129,7 +129,7 @@ public class BIngredients { // best recipe for current state of potion, STILL not always returns the // correct one... - public BRecipe getBestRecipe(byte wood, float time, boolean distilled) { + public BRecipe getBestRecipe(float wood, float time, boolean distilled) { float quality = 0; int ingredientQuality = 0; int cookingQuality = 0; @@ -141,7 +141,7 @@ public class BIngredients { cookingQuality = getCookingQuality(recipe, distilled); if (ingredientQuality > -1 && cookingQuality > -1) { - if (recipe.needsToAge()) { + if (recipe.needsToAge() || time > 0.5) { // needs riping in barrel ageQuality = getAgeQuality(recipe, time); woodQuality = getWoodQuality(recipe, wood); @@ -172,7 +172,7 @@ public class BIngredients { // returns recipe that is cooking only and matches the ingredients and // cooking time public BRecipe getCookRecipe() { - BRecipe bestRecipe = getBestRecipe((byte) 0, 0, false); + BRecipe bestRecipe = getBestRecipe(0, 0, false); // Check if best recipe is cooking only if (bestRecipe != null) { @@ -185,8 +185,8 @@ public class BIngredients { // returns the currently best matching recipe for distilling for the // ingredients and cooking time - public BRecipe getdistillRecipe() { - BRecipe bestRecipe = getBestRecipe((byte) 0, 0, true); + public BRecipe getdistillRecipe(float wood, float time) { + BRecipe bestRecipe = getBestRecipe(wood, time, true); // Check if best recipe needs to be destilled if (bestRecipe != null) { @@ -199,7 +199,7 @@ public class BIngredients { // returns currently best matching recipe for ingredients, cooking- and // ageingtime - public BRecipe getAgeRecipe(byte wood, float time, boolean distilled) { + public BRecipe getAgeRecipe(float wood, float time, boolean distilled) { BRecipe bestRecipe = getBestRecipe(wood, time, distilled); if (bestRecipe != null) { @@ -273,12 +273,13 @@ public class BIngredients { } // returns the quality regarding the barrel wood conditioning given Recipe - public int getWoodQuality(BRecipe recipe, byte wood) { - if (recipe.getWood() == 0x8) { + public int getWoodQuality(BRecipe recipe, float wood) { + if (recipe.getWood() == 0) { // type of wood doesnt matter return 10; } - int quality = 10 - (recipe.getWoodDiff(wood) * recipe.getDifficulty()); + int quality = 10 - Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty()); + P.p.log("wood: " + wood + " needed: " + recipe.getWood() + " diff: " + recipe.getWoodDiff(wood)); if (quality > 0) { return quality; diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index 413d152..298e089 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -13,7 +13,7 @@ public class BRecipe { private Map ingredients = new HashMap();// material and amount private int cookingTime;// time to cook in cauldron private int distillruns;// runs through the brewer - private int wood;// type of wood the barrel has to consist of + private byte wood;// type of wood the barrel has to consist of private int age;// time in minecraft days for the potions to age in barrels private String color;// color of the destilled/finished potion private int difficulty;// difficulty to brew the potion, how exact the instruction has to be followed @@ -36,7 +36,7 @@ public class BRecipe { } this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime"); this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns"); - this.wood = configSectionRecipes.getInt(recipeId + ".wood"); + 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"); @@ -91,18 +91,8 @@ public class BRecipe { } // difference between given and recipe-wanted woodtype - public int getWoodDiff(byte wood) { - int woodType = 0; - if (wood == 0x0) { - woodType = 2; - } else if (wood == 0x1) { - woodType = 4; - } else if (wood == 0x2) { - woodType = 1; - } else if (wood == 0x3) { - woodType = 3; - } - return Math.abs(woodType - this.wood); + public float getWoodDiff(float wood) { + return Math.abs(wood - this.wood); } public boolean isCookingOnly() { @@ -177,18 +167,9 @@ public class BRecipe { return color.toUpperCase(); } - // get the woodtype in blockData-byte + // get the woodtype public byte getWood() { - if (wood == 1) { - return 0x2; - } else if (wood == 2) { - return 0x0; - } else if (wood == 3) { - return 0x3; - } else if (wood == 4) { - return 0x1; - } - return 0x8; + return wood; } public float getAge() { diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 5293b0f..24ef1c8 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -76,23 +76,25 @@ public class Barrel { inventory = org.bukkit.Bukkit.createInventory(null, 9, "Fass"); } } else { - // if nobody has the inventory opened - if (inventory.getViewers().isEmpty()) { - // if inventory contains potions - if (inventory.contains(373)) { - byte wood = getWood(); - long loadTime = System.nanoTime(); - for (ItemStack item : inventory.getContents()) { - if (item != null) { - Brew brew = Brew.get(item); - if (brew != null) { - brew.age(item, time, wood); + if (time > 0) { + // if nobody has the inventory opened + if (inventory.getViewers().isEmpty()) { + // if inventory contains potions + if (inventory.contains(373)) { + byte wood = getWood(); + long loadTime = System.nanoTime(); + for (ItemStack item : inventory.getContents()) { + if (item != null) { + Brew brew = Brew.get(item); + if (brew != null) { + brew.age(item, time, wood); + } } } + loadTime = System.nanoTime() - loadTime; + float ftime = (float) (loadTime / 1000000.0); + P.p.log("opening Barrel with potions (" + ftime + "ms)"); } - loadTime = System.nanoTime() - loadTime; - float ftime = (float) (loadTime / 1000000.0); - P.p.log("opening Barrel with potions (" + ftime + "ms)"); } } } @@ -282,19 +284,28 @@ public class Barrel { wood = this.spigot.getRelative(0, 0, -1); } if (wood.getTypeId() == 5) { - return wood.getData(); + byte data = wood.getData(); + if (data == 0x0) { + return 2; + } else if (data == 0x1) { + return 4; + } else if (data == 0x2) { + return 1; + } else { + return 3; + } } if (wood.getTypeId() == 53) { - return 0x0; + return 2; } if (wood.getTypeId() == 134) { - return 0x1; + return 4; } if (wood.getTypeId() == 135) { - return 0x2; + return 1; } if (wood.getTypeId() == 136) { - return 0x3; + return 3; } return 0; } diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 9208437..848de58 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -28,6 +28,7 @@ public class Brew { private int quality; private int distillRuns; private float ageTime; + private float wood; private BRecipe currentRecipe; private boolean unlabeled; @@ -45,11 +46,12 @@ public class Brew { } // loading from file - public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, String recipe, Boolean unlabeled) { + public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, Boolean unlabeled) { this.ingredients = ingredients; this.quality = quality; this.distillRuns = distillRuns; this.ageTime = ageTime; + this.wood = wood; this.currentRecipe = BIngredients.getRecipeByName(recipe); this.unlabeled = unlabeled; potions.put(uid, this); @@ -182,16 +184,15 @@ public class Brew { } // calculating quality - public int calcQuality(BRecipe recipe, byte wood, boolean distilled) { + public int calcQuality() { // calculate quality from all of the factors - float quality = ( - - ingredients.getIngredientQuality(recipe) + - ingredients.getCookingQuality(recipe, distilled) + - ingredients.getWoodQuality(recipe, wood) + - ingredients.getAgeQuality(recipe, ageTime)); - - quality /= 4; + float quality = ingredients.getIngredientQuality(currentRecipe) + ingredients.getCookingQuality(currentRecipe, distillRuns > 0); + if (currentRecipe.needsToAge() || ageTime > 0.5) { + quality += ingredients.getWoodQuality(currentRecipe, wood) + ingredients.getAgeQuality(currentRecipe, ageTime); + quality /= 4; + } else { + quality /= 2; + } return (int) Math.round(quality); } @@ -250,11 +251,11 @@ public class Brew { // distill custom potion in given slot public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) { distillRuns += 1; - BRecipe recipe = ingredients.getdistillRecipe(); + BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime); if (recipe != null) { // distillRuns will have an effect on the amount of alcohol, not the quality - quality = calcQuality(recipe, (byte) 0, true); currentRecipe = recipe; + quality = calcQuality(); P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); addOrReplaceEffects(potionMeta, getEffects()); @@ -283,16 +284,23 @@ public class Brew { // Ageing Section ------------------ - public void age(ItemStack item, float time, byte wood) { + public void age(ItemStack item, float time, byte woodType) { PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); ageTime += time; // if younger than half a day, it shouldnt get aged form if (ageTime > 0.5) { + if (wood == 0) { + wood = woodType; + } else { + if (wood != woodType) { + woodShift(time, woodType); + } + } BRecipe recipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0); if (recipe != null) { currentRecipe = recipe; - quality = calcQuality(recipe, wood, distillRuns > 0); + quality = calcQuality(); P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); addOrReplaceEffects(potionMeta, getEffects()); @@ -318,9 +326,36 @@ public class Brew { } updateAgeLore(prefix, potionMeta); } + if (ageTime > 0.5) { + if (colorInBarrels && !unlabeled && currentRecipe != null) { + updateWoodLore(potionMeta); + } + } item.setItemMeta(potionMeta); } + // Slowly shift the wood of the Brew to the new Type + public void woodShift(float time, byte to) { + byte factor = 1; + if (ageTime > 5) { + factor = 2; + } else if (ageTime > 10) { + factor = 2; + factor += Math.round(ageTime / 10); + } + if (wood > to) { + wood -= time / factor; + if (wood < to) { + wood = to; + } + } else { + wood += time / factor; + if (wood > to) { + wood = to; + } + } + } + // Lore ----------- // Converts to/from qualitycolored Lore @@ -371,6 +406,13 @@ public class Brew { } updateAgeLore(prefix, meta); } + + // WoodType + if (toQuality && !unlabeled) { + if (ageTime > 0.5) { + updateWoodLore(meta); + } + } } // sets the DistillLore. Prefix is the color to be used @@ -397,6 +439,23 @@ public class Brew { addOrReplaceLore(meta, prefix, "Fassgereift"); } + // updates/sets the color on WoodLore + public void updateWoodLore(PotionMeta meta) { + if (currentRecipe.getWood() > 0) { + int quality = ingredients.getWoodQuality(currentRecipe, wood); + addOrReplaceLore(meta, getQualityColor(quality), "Holzart"); + } else { + if (meta.hasLore()) { + List existingLore = meta.getLore(); + int index = indexOfSubstring(existingLore, "Holzart"); + if (index > -1) { + existingLore.remove(index); + meta.setLore(existingLore); + } + } + } + } + // Adds or replaces a line of Lore. Searches for Substring lore and replaces it public static void addOrReplaceLore(PotionMeta meta, String prefix, String lore) { if (meta.hasLore()) { @@ -482,6 +541,9 @@ public class Brew { if (brew.ageTime != 0) { idConfig.set("ageTime", brew.ageTime); } + if (brew.wood != -1) { + idConfig.set("wood", brew.wood); + } if (brew.currentRecipe != null) { idConfig.set("recipe", brew.currentRecipe.getName(5)); } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 052d681..4b87e86 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -220,10 +220,11 @@ public class P extends JavaPlugin { int quality = section.getInt(uid + ".quality", 0); int distillRuns = section.getInt(uid + ".distillRuns", 0); float ageTime = (float) section.getDouble(uid + ".ageTime", 0.0); + float wood = (float) section.getDouble(uid + ".wood", -1.0); String recipe = section.getString(uid + ".recipe", null); Boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); - new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, recipe, unlabeled); + new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled); } } From 4bd011f23269b7615a31f83066154e244ac62837 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 17:45:44 +0200 Subject: [PATCH 11/22] Handling for renamed or removed Recipes --- readme.md | 2 +- src/com/dre/brewery/Brew.java | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index be2dca2..dd3127c 100644 --- a/readme.md +++ b/readme.md @@ -41,7 +41,7 @@ Hier werden die Rezepte für die verschiedenen Tränke eingetragen. Es können b Die Rezepte bestimmen alle Eigenschaften der entstehenden Tränke. Ob und wie lange sie reifen müssen, ihre Farbe, Effekte die beim Trinken wirken, den Alkoholgehalt, usw. Optionen die weggelassen werden, werden nicht verwendet, oder verwenden die Standardwerte. Wenn z.B. die Anzahl der Destilliervorgänge weggelassen wird, muss der Trank nicht destilliert werden. -Wichtig: Werdem die Namen der Rezepte verändert werden vorhandene Tränke der geänderten Rezepte nutzlos! +Werden im Nachhinein Rezepte umbenannt, so kann es sein, dass vorhandene Tränke den neuen Namen erst nach erneutem Reifen/Brauen erhalten. **Wörter** diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 848de58..86bdb74 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -47,14 +47,33 @@ public class Brew { // loading from file public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, Boolean unlabeled) { + potions.put(uid, this); this.ingredients = ingredients; this.quality = quality; this.distillRuns = distillRuns; this.ageTime = ageTime; this.wood = wood; - this.currentRecipe = BIngredients.getRecipeByName(recipe); this.unlabeled = unlabeled; - potions.put(uid, this); + if (recipe != null && !recipe.equals("")) { + currentRecipe = BIngredients.getRecipeByName(recipe); + if (currentRecipe == null) { + if (quality > 0) { + if (ageTime > 0.5) { + currentRecipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0); + } else if (distillRuns > 0) { + currentRecipe = ingredients.getdistillRecipe(wood, ageTime); + } else { + currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); + } + if (currentRecipe != null) { + this.quality = calcQuality(); + P.p.log("Brew was made from Recipe: '" + recipe + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); + } else { + P.p.errorLog("Brew was made from Recipe: '" + recipe + "' which could not be found!"); + } + } + } + } } // returns a Brew by its UID From a4665939205f280fe4d877dd4d16c6850ab29a57 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 17:53:55 +0200 Subject: [PATCH 12/22] Consider All Recipes --- src/com/dre/brewery/Brew.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 86bdb74..98cbe9f 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -58,13 +58,7 @@ public class Brew { currentRecipe = BIngredients.getRecipeByName(recipe); if (currentRecipe == null) { if (quality > 0) { - if (ageTime > 0.5) { - currentRecipe = ingredients.getAgeRecipe(wood, ageTime, distillRuns > 0); - } else if (distillRuns > 0) { - currentRecipe = ingredients.getdistillRecipe(wood, ageTime); - } else { - currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); - } + currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); if (currentRecipe != null) { this.quality = calcQuality(); P.p.log("Brew was made from Recipe: '" + recipe + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); From 8ab8fe91a624349b6538e7046eabf62dff854460 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 18:46:33 +0200 Subject: [PATCH 13/22] Fixed Recipes not reloading on cmd --- src/com/dre/brewery/BIngredients.java | 10 ---- src/com/dre/brewery/Brew.java | 48 ++++++++++++------- src/com/dre/brewery/P.java | 12 ++++- .../brewery/listeners/CommandListener.java | 2 +- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index 7526e59..fb9b153 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -38,16 +38,6 @@ public class BIngredients { lastId++; } - //returns the recipe with the given name - public static BRecipe getRecipeByName(String name) { - for (BRecipe recipe : recipes) { - if (recipe.getName(5).equalsIgnoreCase(name)) { - return recipe; - } - } - return null; - } - // Add an ingredient to this public void add(Material ingredient) { if (ingredients.containsKey(ingredient)) { diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 98cbe9f..2953c21 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -22,8 +22,6 @@ public class Brew { public static Boolean colorInBarrels; // color the Lore while in Barrels public static Boolean colorInBrewer; // color the Lore while in Brewer - //public static Map> oldLore = new HashMap>(); - private BIngredients ingredients; private int quality; private int distillRuns; @@ -54,20 +52,7 @@ public class Brew { this.ageTime = ageTime; this.wood = wood; this.unlabeled = unlabeled; - if (recipe != null && !recipe.equals("")) { - currentRecipe = BIngredients.getRecipeByName(recipe); - if (currentRecipe == null) { - if (quality > 0) { - currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); - if (currentRecipe != null) { - this.quality = calcQuality(); - P.p.log("Brew was made from Recipe: '" + recipe + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); - } else { - P.p.errorLog("Brew was made from Recipe: '" + recipe + "' which could not be found!"); - } - } - } - } + setRecipeFromString(recipe); } // returns a Brew by its UID @@ -133,6 +118,37 @@ public class Brew { return uid; } + //returns the recipe with the given name, recalculates if not found + public boolean setRecipeFromString(String name) { + currentRecipe = null; + if (name != null && !name.equals("")) { + for (BRecipe recipe : BIngredients.recipes) { + if (recipe.getName(5).equalsIgnoreCase(name)) { + currentRecipe = recipe; + return true; + } + } + + if (quality > 0) { + currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); + if (currentRecipe != null) { + this.quality = calcQuality(); + P.p.log("Brew was made from Recipe: '" + name + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!"); + return true; + } else { + P.p.errorLog("Brew was made from Recipe: '" + name + "' which could not be found!"); + } + } + } + return false; + } + + public boolean reloadRecipe() { + if (currentRecipe != null) { + return setRecipeFromString(currentRecipe.getName(5)); + } + return true; + } // Copy a Brew with a new unique ID and return its item public ItemStack copy(ItemStack item) { diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 4b87e86..b0c8a15 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -97,7 +97,7 @@ public class P extends JavaPlugin { this.log(this.getDescription().getName() + " disabled!"); } - public void reload() { + public void reload(CommandSender sender) { BIngredients.possibleIngredients.clear(); BIngredients.recipes.clear(); BIngredients.cookedNames.clear(); @@ -105,6 +105,16 @@ public class P extends JavaPlugin { BPlayer.drainItems.clear(); readConfig(); + + Boolean successful = true; + for (Brew brew : Brew.potions.values()) { + if (!brew.reloadRecipe()) { + successful = false; + } + } + if (!successful) { + msg(sender, "&cEs konnten nicht alle Rezepte wiederhergesellt werden: Siehe Serverlog!"); + } } public void msg(CommandSender sender, String msg) { diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 1bc6d25..95b13e8 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -32,7 +32,7 @@ public class CommandListener implements CommandExecutor { } else if (cmd.equalsIgnoreCase("reload")) { if (p.permission.has(sender, "brewery.cmd.reload")) { - p.reload(); + p.reload(sender); p.msg(sender, "&aConfig wurde neu eingelesen"); } else { p.msg(sender, "&cDu hast keine Rechte dies zu tun!"); From dee9208b827dea86b60858d0a1eccf133b5f44d8 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 19:53:49 +0200 Subject: [PATCH 14/22] Save Worldnames for later use --- src/com/dre/brewery/P.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index b0c8a15..823370d 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -452,6 +452,8 @@ public class P extends JavaPlugin { p.log("Saving Wakeups (" + ftime + "ms)"); time = System.nanoTime(); + saveWorldNames(configFile, oldData.getConfigurationSection("Worlds")); + try { configFile.save(datafile); } catch (IOException e) { @@ -465,6 +467,22 @@ public class P extends JavaPlugin { p.log("Writing Data to File (" + ftime + "ms)"); } + public void saveWorldNames(FileConfiguration root, ConfigurationSection old) { + if (old != null) { + root.set("Worlds", old); + } + for (World world : p.getServer().getWorlds()) { + String worldName = world.getName(); + if (worldName.startsWith("DXL_")) { + worldName = getDxlName(worldName); + root.set("Worlds." + worldName, 0); + } else { + worldName = world.getUID().toString(); + root.set("Worlds." + worldName, world.getName()); + } + } + } + // Utility @@ -481,7 +499,7 @@ public class P extends JavaPlugin { for (File file : dungeonFolder.listFiles()) { if (!file.isDirectory()) { if (file.getName().startsWith(".id_")) { - return file.getName().substring(1); + return file.getName().substring(1).toLowerCase(); } } } From 67a9a9e12478fe383b19fe3c53cf75340a85cfe0 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 20:05:19 +0200 Subject: [PATCH 15/22] Add File Version --- config.yml | 3 +++ src/com/dre/brewery/P.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/config.yml b/config.yml index 724035c..7116e7c 100644 --- a/config.yml +++ b/config.yml @@ -51,6 +51,9 @@ colorInBrewer: false # Autosave Intervall in Minuten [3] autosave: 3 +# Config Version +version: '0.4' + # Rezepte für Getränke diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 823370d..e706343 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -454,6 +454,8 @@ public class P extends JavaPlugin { saveWorldNames(configFile, oldData.getConfigurationSection("Worlds")); + configFile.set("Version", "0.4"); + try { configFile.save(datafile); } catch (IOException e) { From 07a9778c8babd1e837768a98ca69dbab08ed4b78 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 22:21:26 +0200 Subject: [PATCH 16/22] Less Bad Effects for good Quality --- readme.md | 2 +- src/com/dre/brewery/BPlayer.java | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index dd3127c..305efa1 100644 --- a/readme.md +++ b/readme.md @@ -29,7 +29,7 @@ Die Config.yml enthält: * Rezepte * Wörter -Sie kann frei editiert werden und nach Belieben angepasst werden. Die meisten Optionen werden allerdings erst bei einem Neustart des Servers übernommen. +Sie kann frei editiert werden und nach Belieben angepasst werden. Die Änderungen werden nach ausführen des Commands Reload oder nach einem Serverrestart übernommen Alle Teile der Config sind kommentiert. Die Kommentare enthalten Erklärungen und Beispiele. diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index d2c7994..0cfcb35 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -396,18 +396,25 @@ public class BPlayer { } else if (quality <= 5) { duration *= 250; } else { - duration = 200; + duration = 100; + if (brewAlc <= 10) { + duration = 0; + } + } + if (duration > 0) { + PotionEffectType.POISON.createEffect(duration, 0).apply(player); } - PotionEffectType.POISON.createEffect(duration, 0).apply(player); - if (brewAlc > 10 && quality <= 5) { - duration = 10 - quality; - duration += brewAlc; - duration *= 60; - } else { - duration = 240; + if (brewAlc > 10) { + if (quality <= 5) { + duration = 10 - quality; + duration += brewAlc; + duration *= 60; + } else { + duration = 120; + } + PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player); } - PotionEffectType.BLINDNESS.createEffect(duration, 0).apply(player); } public static void addBrewEffects(Brew brew, Player player) { From c691fea1ee049c4d53fb0a12d40374f218f80ea4 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Thu, 5 Sep 2013 23:02:45 +0200 Subject: [PATCH 17/22] Errorhandling for Recipeloading --- config.yml | 2 +- src/com/dre/brewery/BRecipe.java | 44 ++++++++++++++++++++++++-------- src/com/dre/brewery/P.java | 7 ++++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/config.yml b/config.yml index 7116e7c..2dc0e68 100644 --- a/config.yml +++ b/config.yml @@ -124,7 +124,7 @@ recipes: distillruns: 0 wood: 2 age: 4 - COLOR: ORANGE + color: ORANGE difficulty: 4 alcohol: 12 effects: diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index 298e089..ee9ed9e 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -21,18 +21,34 @@ public class BRecipe { private Map effects = new HashMap(); // Special Effect, Duration public BRecipe(ConfigurationSection configSectionRecipes, String recipeId) { - String[] name = configSectionRecipes.getString(recipeId + ".name").split("/"); - if (name.length > 2) { - this.name = name; + 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 { - this.name = new String[1]; - this.name[0] = name[0]; + return; } List ingredientsList = configSectionRecipes.getStringList(recipeId + ".ingredients"); - for (String item : ingredientsList) { - String[] ingredParts = item.split("/"); - ingredParts[0] = ingredParts[0].toUpperCase(); - this.ingredients.put(Material.getMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1])); + if (ingredientsList != null) { + for (String item : ingredientsList) { + String[] ingredParts = item.split("/"); + if (ingredParts.length == 2) { + Material mat = Material.matchMaterial(ingredParts[0]); + if (mat != null) { + this.ingredients.put(Material.matchMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1])); + } else { + P.p.errorLog("Unknown Material: " + ingredParts[0]); + return; + } + } else { + return; + } + } } this.cookingTime = configSectionRecipes.getInt(recipeId + ".cookingtime"); this.distillruns = configSectionRecipes.getInt(recipeId + ".distillruns"); @@ -129,6 +145,11 @@ public class BRecipe { return false; } + // true if name and ingredients are correct + public boolean isValid() { + return (name != null && ingredients != null && !ingredients.isEmpty()); + } + // Getter @@ -164,7 +185,10 @@ public class BRecipe { } public String getColor() { - return color.toUpperCase(); + if (color != null) { + return color.toUpperCase(); + } + return "BLUE"; } // get the woodtype diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index e706343..b028d76 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -161,7 +161,12 @@ public class P extends JavaPlugin { ConfigurationSection configSection = config.getConfigurationSection("recipes"); if (configSection != null) { for (String recipeId : configSection.getKeys(false)) { - BIngredients.recipes.add(new BRecipe(configSection, recipeId)); + BRecipe recipe = new BRecipe(configSection, recipeId); + if (recipe.isValid()) { + BIngredients.recipes.add(recipe); + } else { + errorLog("Recipe with id: '" + recipeId + "' failed to load!"); + } } } From dcf92cf074851976b26241e696a9dc92b509b3ea Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 6 Sep 2013 00:22:39 +0200 Subject: [PATCH 18/22] Remove Drunkeness on Death --- src/com/dre/brewery/BRecipe.java | 3 ++- src/com/dre/brewery/P.java | 10 +++++++--- src/com/dre/brewery/listeners/PlayerListener.java | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index ee9ed9e..177d7c0 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -42,7 +42,8 @@ public class BRecipe { if (mat != null) { this.ingredients.put(Material.matchMaterial(ingredParts[0]), P.p.parseInt(ingredParts[1])); } else { - P.p.errorLog("Unknown Material: " + ingredParts[0]); + P.p.errorLog("Unbekanntes Material: " + ingredParts[0]); + this.ingredients = null; return; } } else { diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index b028d76..3eba1f2 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -165,7 +165,7 @@ public class P extends JavaPlugin { if (recipe.isValid()) { BIngredients.recipes.add(recipe); } else { - errorLog("Recipe with id: '" + recipeId + "' failed to load!"); + errorLog("Laden des Rezeptes mit id: '" + recipeId + "' fehlgeschlagen!"); } } } @@ -175,8 +175,12 @@ public class P extends JavaPlugin { if (configSection != null) { for (String ingredient : configSection.getKeys(false)) { Material mat = Material.matchMaterial(ingredient); - BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null))); - BIngredients.possibleIngredients.add(mat); + if (mat != null) { + BIngredients.cookedNames.put(mat, (configSection.getString(ingredient, null))); + BIngredients.possibleIngredients.add(mat); + } else { + errorLog("Unbekanntes Material: " + ingredient); + } } } diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index eb9d1e8..f8e548a 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -3,6 +3,7 @@ package com.dre.brewery.listeners; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; +import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerLoginEvent; @@ -134,6 +135,12 @@ public class PlayerListener implements Listener { } } + // Player has died! He should no longer be drunk + @EventHandler + public void onPlayerRespawn(PlayerRespawnEvent event) { + BPlayer.players.remove(event.getPlayer().getName()); + } + // player walks while drunk, push him around! @EventHandler(priority = EventPriority.LOW) public void onPlayerMove(PlayerMoveEvent event) { From 080bcf2d76e71cd90679f95df2258490c6018934 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sat, 7 Sep 2013 19:27:46 +0200 Subject: [PATCH 19/22] Decrease Drunkeness on Death --- src/com/dre/brewery/BPlayer.java | 2 +- src/com/dre/brewery/listeners/PlayerListener.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index 0cfcb35..ac4ed81 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -427,7 +427,7 @@ public class BPlayer { if (type.isInstant()) { type.createEffect(0, duration - 1).apply(player); } else { - int amplifier = brew.getQuality() / 3; + int amplifier = brew.getQuality() / 4; duration /= type.getDurationModifier(); type.createEffect(duration * 20, amplifier).apply(player); } diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index f8e548a..0aad642 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -135,10 +135,18 @@ public class PlayerListener implements Listener { } } - // Player has died! He should no longer be drunk + // Player has died! Decrease Drunkeness by 20 @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event) { - BPlayer.players.remove(event.getPlayer().getName()); + String playerName = event.getPlayer().getName(); + BPlayer bPlayer = BPlayer.get(playerName); + if (bPlayer != null) { + if (bPlayer.getDrunkeness() > 20) { + bPlayer.setData(bPlayer.getDrunkeness() - 20, 0); + } else { + BPlayer.players.remove(playerName); + } + } } // player walks while drunk, push him around! From a549280ee6d525a9ee0b488703afe95ff5997b0b Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sat, 7 Sep 2013 19:31:02 +0200 Subject: [PATCH 20/22] Version 0.5 --- config.yml | 2 +- plugin.yml | 2 +- src/com/dre/brewery/P.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index 2dc0e68..e8cc196 100644 --- a/config.yml +++ b/config.yml @@ -52,7 +52,7 @@ colorInBrewer: false autosave: 3 # Config Version -version: '0.4' +version: '0.5' # Rezepte für Getränke diff --git a/plugin.yml b/plugin.yml index 7dfc5e6..305da45 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: Brewery -version: 0.4 +version: 0.5 main: com.dre.brewery.P authors: [Milan Albrecht, Frank Baumann] softdepend: [Vault] diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 3eba1f2..e96d99c 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -463,7 +463,7 @@ public class P extends JavaPlugin { saveWorldNames(configFile, oldData.getConfigurationSection("Worlds")); - configFile.set("Version", "0.4"); + configFile.set("Version", "0.5"); try { configFile.save(datafile); From ef7293883fb100a6a75f8a0a21b14fbb74509085 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Mon, 9 Sep 2013 16:28:35 +0200 Subject: [PATCH 21/22] Disable Debug Messages --- src/com/dre/brewery/BIngredients.java | 11 +++--- src/com/dre/brewery/BPlayer.java | 1 - src/com/dre/brewery/Barrel.java | 5 +-- src/com/dre/brewery/Brew.java | 2 - src/com/dre/brewery/P.java | 54 ++++++--------------------- 5 files changed, 18 insertions(+), 55 deletions(-) diff --git a/src/com/dre/brewery/BIngredients.java b/src/com/dre/brewery/BIngredients.java index fb9b153..81b0fdf 100644 --- a/src/com/dre/brewery/BIngredients.java +++ b/src/com/dre/brewery/BIngredients.java @@ -64,7 +64,7 @@ public class BIngredients { if (cookRecipe != null) { // Potion is best with cooking only int quality = (int) Math.round((getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0); - P.p.log("cooked potion has Quality: " + quality); + P.p.debugLog("cooked potion has Quality: " + quality); Brew brew = new Brew(uid, quality, cookRecipe, this); Brew.addOrReplaceEffects(potionMeta, brew.getEffects()); @@ -135,8 +135,8 @@ public class BIngredients { // needs riping in barrel ageQuality = getAgeQuality(recipe, time); woodQuality = getWoodQuality(recipe, wood); - P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " Wood Quality: " + woodQuality + - " age Quality: " + ageQuality + " for " + recipe.getName(5)); + 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) { @@ -144,7 +144,7 @@ public class BIngredients { bestRecipe = recipe; } } else { - P.p.log("Ingredient Quality: " + ingredientQuality + " Cooking Quality: " + cookingQuality + " for " + recipe.getName(5)); + 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; @@ -154,7 +154,7 @@ public class BIngredients { } } if (bestRecipe != null) { - P.p.log("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality); + P.p.debugLog("best recipe: " + bestRecipe.getName(5) + " has Quality= " + quality); } return bestRecipe; } @@ -269,7 +269,6 @@ public class BIngredients { return 10; } int quality = 10 - Math.round(recipe.getWoodDiff(wood) * recipe.getDifficulty()); - P.p.log("wood: " + wood + " needed: " + recipe.getWood() + " diff: " + recipe.getWoodDiff(wood)); if (quality > 0) { return quality; diff --git a/src/com/dre/brewery/BPlayer.java b/src/com/dre/brewery/BPlayer.java index ac4ed81..b988b1e 100644 --- a/src/com/dre/brewery/BPlayer.java +++ b/src/com/dre/brewery/BPlayer.java @@ -109,7 +109,6 @@ public class BPlayer { } else { bPlayer.drinkCap(player); } - P.p.msg(player, "Du bist nun " + bPlayer.drunkeness + "% betrunken, mit einer Qualität von " + bPlayer.getQuality()); return true; } return false; diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 24ef1c8..4258c7a 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -93,7 +93,7 @@ public class Barrel { } loadTime = System.nanoTime() - loadTime; float ftime = (float) (loadTime / 1000000.0); - P.p.log("opening Barrel with potions (" + ftime + "ms)"); + P.p.debugLog("opening Barrel with potions (" + ftime + "ms)"); } } } @@ -375,7 +375,6 @@ public class Barrel { int x = startX; int y = 0; int z = startZ; - // P.p.log("startX="+startX+" startZ="+startZ+" endX="+endX+" endZ="+endZ+" direction="+direction); while (y <= 1) { while (x <= endX) { while (z <= endZ) { @@ -441,12 +440,10 @@ public class Barrel { int x = startX; int y = 0; int z = startZ; - // P.p.log("startX="+startX+" startZ="+startZ+" endX="+endX+" endZ="+endZ+" direction="+direction); while (y <= 2) { while (x <= endX) { while (z <= endZ) { typeId = spigot.getRelative(x, y, z).getTypeId(); - // spigot.getRelative(x,y,z).setTypeId(1); if (direction == 1 || direction == 2) { if (y == 1 && z == 0) { if (x == -2 || x == -3 || x == 2 || x == 3) { diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 2953c21..428d7b8 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -285,7 +285,6 @@ public class Brew { // distillRuns will have an effect on the amount of alcohol, not the quality currentRecipe = recipe; quality = calcQuality(); - P.p.log("destilled " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); addOrReplaceEffects(potionMeta, getEffects()); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); @@ -330,7 +329,6 @@ public class Brew { if (recipe != null) { currentRecipe = recipe; quality = calcQuality(); - P.p.log("Final " + recipe.getName(5) + " has Quality: " + quality + ", alc: " + calcAlcohol()); addOrReplaceEffects(potionMeta, getEffects()); potionMeta.setDisplayName(P.p.color("&f" + recipe.getName(quality))); diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index e96d99c..f139bad 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -29,6 +29,7 @@ import com.dre.brewery.listeners.*; public class P extends JavaPlugin { public static P p; + public static boolean debug; public static int lastBackup = 0; public static int lastSave = 1; public static int autosave = 3; @@ -125,6 +126,12 @@ public class P extends JavaPlugin { this.msg(Bukkit.getConsoleSender(), msg); } + public void debugLog(String msg) { + if (debug) { + this.msg(Bukkit.getConsoleSender(), "&2[Debug] &f" + msg); + } + } + public void errorLog(String msg) { Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg); } @@ -146,6 +153,7 @@ public class P extends JavaPlugin { // various Settings autosave = config.getInt("autosave", 3); + debug = config.getBoolean("debug", false); BPlayer.pukeItemId = Material.matchMaterial(config.getString("pukeItem", "SOUL_SAND")).getId(); BPlayer.hangoverTime = config.getInt("hangoverDays", 0) * 24 * 60; BPlayer.overdrinkKick = config.getBoolean("enableKickOnOverdrink", false); @@ -411,56 +419,26 @@ public class P extends JavaPlugin { FileConfiguration configFile = new YamlConfiguration(); - time = System.nanoTime() - time; - float ftime = (float) (time / 1000000.0); - p.log("Creating a savefile (" + ftime + "ms)"); - time = System.nanoTime(); - if (!Brew.potions.isEmpty()) { Brew.save(configFile.createSection("Brew")); } - time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Saving Brew (" + ftime + "ms)"); - time = System.nanoTime(); - if (!BCauldron.bcauldrons.isEmpty() || oldData.contains("BCauldron")) { BCauldron.save(configFile.createSection("BCauldron"), oldData.getConfigurationSection("BCauldron")); } - time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Saving BCauldrons (" + ftime + "ms)"); - time = System.nanoTime(); - if (!Barrel.barrels.isEmpty() || oldData.contains("Barrel")) { Barrel.save(configFile.createSection("Barrel"), oldData.getConfigurationSection("Barrel")); } - time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Saving Barrels (" + ftime + "ms)"); - time = System.nanoTime(); - if (!BPlayer.players.isEmpty()) { BPlayer.save(configFile.createSection("Player")); } - time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Saving players (" + ftime + "ms)"); - time = System.nanoTime(); - if (!Wakeup.wakeups.isEmpty() || oldData.contains("Wakeup")) { Wakeup.save(configFile.createSection("Wakeup"), oldData.getConfigurationSection("Wakeup")); } - time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Saving Wakeups (" + ftime + "ms)"); - time = System.nanoTime(); - saveWorldNames(configFile, oldData.getConfigurationSection("Worlds")); configFile.set("Version", "0.5"); @@ -474,8 +452,8 @@ public class P extends JavaPlugin { lastSave = 1; time = System.nanoTime() - time; - ftime = (float) (time / 1000000.0); - p.log("Writing Data to File (" + ftime + "ms)"); + float ftime = (float) (time / 1000000.0); + p.debugLog("Writing Data to File (" + ftime + "ms)"); } public void saveWorldNames(FileConfiguration root, ConfigurationSection old) { @@ -604,26 +582,18 @@ public class P extends JavaPlugin { @Override public void run() { - long time = System.nanoTime(); - for (BCauldron cauldron : BCauldron.bcauldrons) { cauldron.onUpdate();// runs every min to update cooking time } Barrel.onUpdate();// runs every min to check and update ageing time BPlayer.onUpdate();// updates players drunkeness + debugLog("Update"); + if (lastSave >= autosave) { saveData();// save all data - - time = System.nanoTime() - time; - float ftime = (float) (time / 1000000.0); - p.log("Update and saving (" + ftime + "ms)"); } else { lastSave++; - - time = System.nanoTime() - time; - float ftime = (float) (time / 1000000.0); - p.log("Update (" + ftime + "ms)"); } } From 807922d34f0e356b3f6045561609b9da7d7d5ad3 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Mon, 9 Sep 2013 16:34:29 +0200 Subject: [PATCH 22/22] v0.5 -> v0.5.1 --- plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.yml b/plugin.yml index 305da45..8ecb9bd 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: Brewery -version: 0.5 +version: 0.5.1 main: com.dre.brewery.P authors: [Milan Albrecht, Frank Baumann] softdepend: [Vault]