Skip to content

Commit

Permalink
Added "Static" Command
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0wStorm committed Sep 3, 2014
1 parent 30fa436 commit 68c73ce
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 8 deletions.
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.*:
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/com/dre/brewery/BRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public ItemStack create(int quality) {

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)));
Expand Down
38 changes: 36 additions & 2 deletions src/com/dre/brewery/Brew.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,7 +45,7 @@ public Brew(int uid, int quality, BRecipe recipe, BIngredients ingredients) {
}

// 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;
Expand All @@ -53,6 +54,7 @@ public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, flo
this.wood = wood;
this.unlabeled = unlabeled;
this.persistent = persistent;
this.stat = stat;
setRecipeFromString(recipe);
}

Expand Down Expand Up @@ -128,7 +130,9 @@ public boolean setRecipeFromString(String name) {
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 {
Expand Down Expand Up @@ -163,6 +167,9 @@ public Brew clone(int uid) {
brew.distillRuns = distillRuns;
brew.ageTime = ageTime;
brew.unlabeled = unlabeled;
if (!brew.persistent) {
brew.stat = stat;
}
return brew;
}

Expand Down Expand Up @@ -278,6 +285,22 @@ public void removePersistence() {
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
Expand All @@ -296,6 +319,10 @@ public static void distillAll(BrewerInventory inv, Boolean[] contents) {

// 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) {
Expand Down Expand Up @@ -331,6 +358,10 @@ public void distillSlot(ItemStack slotItem, PotionMeta potionMeta) {
// Ageing Section ------------------

public void age(ItemStack item, float time, byte woodType) {
if (stat) {
return;
}

PotionMeta potionMeta = (PotionMeta) item.getItemMeta();
ageTime += time;

Expand Down Expand Up @@ -605,6 +636,9 @@ public static void save(ConfigurationSection config) {
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()));
}
Expand Down
12 changes: 8 additions & 4 deletions src/com/dre/brewery/LanguageReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ private void setDefaults() {
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");
Expand All @@ -96,6 +98,7 @@ private void setDefaults() {
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!");
Expand All @@ -122,6 +125,7 @@ private void setDefaults() {
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_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)");

/* Etc. */
Expand Down
3 changes: 2 additions & 1 deletion src/com/dre/brewery/P.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ public void readData() {
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);
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/com/dre/brewery/listeners/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
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")) {
Expand Down Expand Up @@ -199,6 +207,10 @@ public ArrayList<String> getCommands(CommandSender sender) {
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"));
}
Expand Down Expand Up @@ -411,9 +423,11 @@ public void cmdPersist(CommandSender sender) {
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;
Expand All @@ -426,6 +440,35 @@ public void cmdPersist(CommandSender sender) {

}

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) {
Expand Down

0 comments on commit 68c73ce

Please sign in to comment.