Added "Static" Command

This commit is contained in:
Sn0wStorm 2014-09-03 22:03:03 +02:00
parent 30fa43633f
commit 68c73ce8a8
6 changed files with 93 additions and 8 deletions

View File

@ -41,6 +41,7 @@ permissions:
brewery.cmd.copy: true brewery.cmd.copy: true
brewery.cmd.delete: true brewery.cmd.delete: true
brewery.cmd.persist: true brewery.cmd.persist: true
brewery.cmd.static: true
brewery.cmd.reload: true brewery.cmd.reload: true
# * # *
brewery.*: brewery.*:
@ -69,6 +70,8 @@ permissions:
description: Delete Potions description: Delete Potions
brewery.cmd.persist: brewery.cmd.persist:
description: Make Potions Persistent description: Make Potions Persistent
brewery.cmd.static:
description: Make Potions Static
brewery.cmd.reload: brewery.cmd.reload:
description: Reload config description: Reload config

View File

@ -187,7 +187,7 @@ public class BRecipe {
BIngredients bIngredients = new BIngredients(list, cookingTime); 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)); potion.setDurability(Brew.PotionColor.valueOf(getColor()).getColorId(false));
potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));

View File

@ -29,6 +29,7 @@ public class Brew {
private BRecipe currentRecipe; private BRecipe currentRecipe;
private boolean unlabeled; private boolean unlabeled;
private boolean persistent; private boolean persistent;
private boolean stat; // static potions should not be changed
public Brew(int uid, BIngredients ingredients) { public Brew(int uid, BIngredients ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
@ -44,7 +45,7 @@ public class Brew {
} }
// loading from file // 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); potions.put(uid, this);
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
@ -53,6 +54,7 @@ public class Brew {
this.wood = wood; this.wood = wood;
this.unlabeled = unlabeled; this.unlabeled = unlabeled;
this.persistent = persistent; this.persistent = persistent;
this.stat = stat;
setRecipeFromString(recipe); setRecipeFromString(recipe);
} }
@ -128,7 +130,9 @@ public class Brew {
if (quality > 0) { if (quality > 0) {
currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0); currentRecipe = ingredients.getBestRecipe(wood, ageTime, distillRuns > 0);
if (currentRecipe != null) { 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!"); P.p.log("Brew was made from Recipe: '" + name + "' which could not be found. '" + currentRecipe.getName(5) + "' used instead!");
return true; return true;
} else { } else {
@ -163,6 +167,9 @@ public class Brew {
brew.distillRuns = distillRuns; brew.distillRuns = distillRuns;
brew.ageTime = ageTime; brew.ageTime = ageTime;
brew.unlabeled = unlabeled; brew.unlabeled = unlabeled;
if (!brew.persistent) {
brew.stat = stat;
}
return brew; return brew;
} }
@ -278,6 +285,22 @@ public class Brew {
persistent = false; 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 --------------- // Distilling section ---------------
// distill all custom potions in the brewer // distill all custom potions in the brewer
@ -296,6 +319,10 @@ public class Brew {
// distill custom potion in given slot // distill custom potion in given slot
public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) { public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
if (stat) {
return;
}
distillRuns += 1; distillRuns += 1;
BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime); BRecipe recipe = ingredients.getdistillRecipe(wood, ageTime);
if (recipe != null) { if (recipe != null) {
@ -331,6 +358,10 @@ public class Brew {
// Ageing Section ------------------ // Ageing Section ------------------
public void age(ItemStack item, float time, byte woodType) { public void age(ItemStack item, float time, byte woodType) {
if (stat) {
return;
}
PotionMeta potionMeta = (PotionMeta) item.getItemMeta(); PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
ageTime += time; ageTime += time;
@ -605,6 +636,9 @@ public class Brew {
if (brew.persistent) { if (brew.persistent) {
idConfig.set("persist", true); idConfig.set("persist", true);
} }
if (brew.stat) {
idConfig.set("stat", true);
}
// save the ingredients // save the ingredients
idConfig.set("ingId", brew.ingredients.save(config.getParent())); idConfig.set("ingId", brew.ingredients.save(config.getParent()));
} }

View File

@ -82,11 +82,13 @@ public class LanguageReader {
defaults.put("CMD_Info_NotDrunk", "&v1 is not drunk"); 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_Info_Drunk", "&v1 is &6&v2% &fdrunk, with a quality of &6&v3");
defaults.put("CMD_UnLabel", "&aLabel removed!"); 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_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", "&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_PersistRemove", "&cPersistent Brews cannot be removed from the Database. It would render any copies of them useless!");
defaults.put("CMD_UnPersist", "&aPersistence Removed. &eEvery Potential copy NOT made with '/brew copy' could become useless now!"); 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_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 */ /* Error */
defaults.put("Error_UnknownCommand", "Unknown Command"); 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_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_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_ConfigUpdate", "Unknown Brewery config version: v&v1, config was not updated!");
defaults.put("Error_PersistStatic", "&cPersistent potions are always static!");
/* Permissions */ /* Permissions */
defaults.put("Error_NoPermissions", "&cYou don't have permissions to do this!"); 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 <id> &9Removes the wakeup point with <id>"); defaults.put("Help_WakeupRemove", "&6/brew wakeup remove <id> &9Removes the wakeup point with <id>");
defaults.put("Help_Reload", "&6/brew reload &9Reload config"); 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_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 <Recipe> <Quality> &9Create a Brew with optional quality (1-10)"); defaults.put("Help_Create", "&6/brew create <Recipe> <Quality> &9Create a Brew with optional quality (1-10)");
/* Etc. */ /* Etc. */

View File

@ -324,8 +324,9 @@ public class P extends JavaPlugin {
String recipe = section.getString(uid + ".recipe", null); String recipe = section.getString(uid + ".recipe", null);
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false); boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
boolean persistent = section.getBoolean(uid + ".persist", 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);
} }
} }

View File

@ -101,6 +101,14 @@ public class CommandListener implements CommandExecutor {
p.msg(sender, p.languageReader.get("Error_NoPermissions")); 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")) { } else if (cmd.equalsIgnoreCase("unlabel")) {
if (sender.hasPermission("brewery.cmd.unlabel")) { if (sender.hasPermission("brewery.cmd.unlabel")) {
@ -199,6 +207,10 @@ public class CommandListener implements CommandExecutor {
cmds.add(p.languageReader.get("Help_Persist")); 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")) { if (sender.hasPermission("brewery.cmd.create")) {
cmds.add(p.languageReader.get("Help_Create")); cmds.add(p.languageReader.get("Help_Create"));
} }
@ -411,9 +423,11 @@ public class CommandListener implements CommandExecutor {
if (brew != null) { if (brew != null) {
if (brew.isPersistent()) { if (brew.isPersistent()) {
brew.removePersistence(); brew.removePersistence();
brew.setStatic(false, hand);
p.msg(sender, p.languageReader.get("CMD_UnPersist")); p.msg(sender, p.languageReader.get("CMD_UnPersist"));
} else { } else {
brew.makePersistent(); brew.makePersistent();
brew.setStatic(true, hand);
p.msg(sender, p.languageReader.get("CMD_Persistent")); p.msg(sender, p.languageReader.get("CMD_Persistent"));
} }
return; 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) { public void cmdUnlabel(CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {