From 68c73ce8a8d6dcbf34dad0762c359f930eabebd2 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Wed, 3 Sep 2014 22:03:03 +0200 Subject: [PATCH] Added "Static" Command --- plugin.yml | 3 ++ src/com/dre/brewery/BRecipe.java | 2 +- src/com/dre/brewery/Brew.java | 38 +++++++++++++++- src/com/dre/brewery/LanguageReader.java | 12 ++++-- src/com/dre/brewery/P.java | 3 +- .../brewery/listeners/CommandListener.java | 43 +++++++++++++++++++ 6 files changed, 93 insertions(+), 8 deletions(-) diff --git a/plugin.yml b/plugin.yml index 05d9fa7..6a2f735 100644 --- a/plugin.yml +++ b/plugin.yml @@ -41,6 +41,7 @@ permissions: brewery.cmd.copy: true brewery.cmd.delete: true brewery.cmd.persist: true + brewery.cmd.static: true brewery.cmd.reload: true # * brewery.*: @@ -69,6 +70,8 @@ permissions: description: Delete Potions brewery.cmd.persist: description: Make Potions Persistent + brewery.cmd.static: + description: Make Potions Static brewery.cmd.reload: description: Reload config diff --git a/src/com/dre/brewery/BRecipe.java b/src/com/dre/brewery/BRecipe.java index 98ad5a9..0aaf6b0 100644 --- a/src/com/dre/brewery/BRecipe.java +++ b/src/com/dre/brewery/BRecipe.java @@ -187,7 +187,7 @@ public class BRecipe { BIngredients bIngredients = new BIngredients(list, cookingTime); - Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false); + Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true); potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false)); potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 7aeeb94..546f131 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -29,6 +29,7 @@ public class Brew { private BRecipe currentRecipe; private boolean unlabeled; private boolean persistent; + private boolean stat; // static potions should not be changed public Brew(int uid, BIngredients ingredients) { this.ingredients = ingredients; @@ -44,7 +45,7 @@ public class Brew { } // loading from file - public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent) { + public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat) { potions.put(uid, this); this.ingredients = ingredients; this.quality = quality; @@ -53,6 +54,7 @@ public class Brew { this.wood = wood; this.unlabeled = unlabeled; this.persistent = persistent; + this.stat = stat; setRecipeFromString(recipe); } @@ -128,7 +130,9 @@ public class Brew { if (quality > 0) { currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); if (currentRecipe != null) { - this.quality = calcQuality(); + if (!stat) { + 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 { @@ -163,6 +167,9 @@ public class Brew { brew.distillRuns = distillRuns; brew.ageTime = ageTime; brew.unlabeled = unlabeled; + if (!brew.persistent) { + brew.stat = stat; + } return brew; } @@ -278,6 +285,22 @@ public class Brew { persistent = false; } + public boolean isStatic() { + return stat; + } + + // Set the Static flag, so potion is unchangeable + public void setStatic(boolean stat, ItemStack potion) { + this.stat = stat; + if (currentRecipe != null && canDistill()) { + if (stat) { + potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(false)); + } else { + potion.setDurability(PotionColor.valueOf(currentRecipe.getColor()).getColorId(true)); + } + } + } + // Distilling section --------------- // distill all custom potions in the brewer @@ -296,6 +319,10 @@ public class Brew { // distill custom potion in given slot public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) { + if (stat) { + return; + } + distillRuns += 1; BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime); if (recipe != null) { @@ -331,6 +358,10 @@ public class Brew { // Ageing Section ------------------ public void age(ItemStack item, float time, byte woodType) { + if (stat) { + return; + } + PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); ageTime += time; @@ -605,6 +636,9 @@ public class Brew { if (brew.persistent) { idConfig.set("persist", true); } + if (brew.stat) { + idConfig.set("stat", true); + } // save the ingredients idConfig.set("ingId", brew.ingredients.save(config.getParent())); } diff --git a/src/com/dre/brewery/LanguageReader.java b/src/com/dre/brewery/LanguageReader.java index d94839c..0cb588a 100644 --- a/src/com/dre/brewery/LanguageReader.java +++ b/src/com/dre/brewery/LanguageReader.java @@ -82,11 +82,13 @@ public class LanguageReader { defaults.put("CMD_Info_NotDrunk", "&v1 is not drunk"); defaults.put("CMD_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3"); defaults.put("CMD_UnLabel", "&aLabel removed!"); - defaults.put("CMD_Persistent", "&aPotion is now Persistent and may be copied like any other item. You can remove the persistence with the same command."); - defaults.put("CMD_PersistRemove", "&cThis Brew is Persistent. Deleting it would render every copy of it NOT made with '/brew copy' useless. To proceed, remove the persistence before deleting."); - defaults.put("CMD_UnPersist", "&aPersistence Removed. &eEvery Potential copy NOT made with '/brew copy' could become useless now!"); + defaults.put("CMD_Persistent", "&aPotion is now Persistent and Static and may now be copied like any other item. You can remove the persistence with the same command."); + defaults.put("CMD_PersistRemove", "&cPersistent Brews cannot be removed from the Database. It would render any copies of them useless!"); + defaults.put("CMD_UnPersist", "&aPersistence and static Removed. &eEvery Potential copy NOT made with '/brew copy' could become useless now!"); defaults.put("CMD_Copy_Error", "&6&v1 &cPotions did not fit into your inventory"); - defaults.put("CMD_CopyNotPersistent", "&eThese copies of this Brew will not be persistent!"); + defaults.put("CMD_CopyNotPersistent", "&eThese copies of this Brew will not be persistent or static!"); + defaults.put("CMD_Static", "&aPotion is now static and will not change in barrels or brewing stands."); + defaults.put("CMD_NonStatic", "&ePotion is not static anymore and will normally age in barrels."); /* Error */ defaults.put("Error_UnknownCommand", "Unknown Command"); @@ -96,6 +98,7 @@ public class LanguageReader { defaults.put("Error_NoBrewName", "&cNo Recipe with Name: '&v1&c' found!"); defaults.put("Error_Recipeload", "&cNot all recipes could be restored: More information in the server log!"); defaults.put("Error_ConfigUpdate", "Unknown Brewery config version: v&v1, config was not updated!"); + defaults.put("Error_PersistStatic", "&cPersistent potions are always static!"); /* Permissions */ defaults.put("Error_NoPermissions", "&cYou don't have permissions to do this!"); @@ -122,6 +125,7 @@ public class LanguageReader { defaults.put("Help_WakeupRemove", "&6/brew wakeup remove &9Removes the wakeup point with "); defaults.put("Help_Reload", "&6/brew reload &9Reload config"); defaults.put("Help_Persist", "&6/brew persist &9Make Brew persistent -> copyable by any plugin and technique"); + defaults.put("Help_Static", "&6/brew static &9Make Brew static -> No further ageing or distilling"); defaults.put("Help_Create", "&6/brew create &9Create a Brew with optional quality (1-10)"); /* Etc. */ diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 2b93db5..c13a7f8 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -324,8 +324,9 @@ public class P extends JavaPlugin { String recipe = section.getString(uid + ".recipe", null); boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); boolean persistent = section.getBoolean(uid + ".persist", false); + boolean stat = section.getBoolean(uid + ".stat", false); - new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent); + new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat); } } diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 3432a63..93ab388 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -101,6 +101,14 @@ public class CommandListener implements CommandExecutor { p.msg(sender, p.languageReader.get("Error_NoPermissions")); } + } else if (cmd.equalsIgnoreCase("static")) { + + if (sender.hasPermission("brewery.cmd.static")) { + cmdStatic(sender); + } else { + p.msg(sender, p.languageReader.get("Error_NoPermissions")); + } + } else if (cmd.equalsIgnoreCase("unlabel")) { if (sender.hasPermission("brewery.cmd.unlabel")) { @@ -199,6 +207,10 @@ public class CommandListener implements CommandExecutor { cmds.add(p.languageReader.get("Help_Persist")); } + if (sender.hasPermission("brewery.cmd.static")) { + cmds.add(p.languageReader.get("Help_Static")); + } + if (sender.hasPermission("brewery.cmd.create")) { cmds.add(p.languageReader.get("Help_Create")); } @@ -411,9 +423,11 @@ public class CommandListener implements CommandExecutor { if (brew != null) { if (brew.isPersistent()) { brew.removePersistence(); + brew.setStatic(false, hand); p.msg(sender, p.languageReader.get("CMD_UnPersist")); } else { brew.makePersistent(); + brew.setStatic(true, hand); p.msg(sender, p.languageReader.get("CMD_Persistent")); } return; @@ -426,6 +440,35 @@ public class CommandListener implements CommandExecutor { } + public void cmdStatic(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) { + if (brew.isStatic()) { + if (!brew.isPersistent()) { + brew.setStatic(false, hand); + p.msg(sender, p.languageReader.get("CMD_NonStatic")); + } else { + p.msg(sender, p.languageReader.get("Error_PersistStatic")); + } + } else { + brew.setStatic(true, hand); + p.msg(sender, p.languageReader.get("CMD_Static")); + } + return; + } + } + p.msg(sender, p.languageReader.get("Error_ItemNotPotion")); + } else { + p.msg(sender, p.languageReader.get("Error_PlayerCommand")); + } + + } + public void cmdUnlabel(CommandSender sender) { if (sender instanceof Player) {