Store last updated time for brews

This commit is contained in:
Sn0wStorm 2016-05-18 22:31:32 +02:00
parent 024c05b817
commit bf57320057
6 changed files with 37 additions and 9 deletions

View File

@ -203,7 +203,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, true); Brew brew = new Brew(uid, bIngredients, quality, distillruns, getAge(), wood, getName(5), false, false, true, 0);
Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false); Brew.PotionColor.valueOf(getColor()).colorBrew(potionMeta, potion, false);
potionMeta.setDisplayName(P.p.color("&f" + getName(quality))); potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
@ -212,6 +212,7 @@ public class BRecipe {
brew.convertLore(potionMeta, false); brew.convertLore(potionMeta, false);
Brew.addOrReplaceEffects(potionMeta, effects, quality); Brew.addOrReplaceEffects(potionMeta, effects, quality);
brew.touch();
potion.setItemMeta(potionMeta); potion.setItemMeta(potionMeta);
return potion; return potion;

View File

@ -21,6 +21,7 @@ public class Brew {
// represents the liquid in the brewed Potions // represents the liquid in the brewed Potions
public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>(); public static Map<Integer, Brew> potions = new HashMap<Integer, Brew>();
public static long installTime = System.currentTimeMillis(); // plugin install time in millis after epoch
public static Boolean colorInBarrels; // color the Lore while in Barrels public static Boolean colorInBarrels; // color the Lore while in Barrels
public static Boolean colorInBrewer; // color the Lore while in Brewer public static Boolean colorInBrewer; // color the Lore while in Brewer
@ -33,9 +34,11 @@ public class Brew {
private boolean unlabeled; private boolean unlabeled;
private boolean persistent; private boolean persistent;
private boolean stat; // static potions should not be changed private boolean stat; // static potions should not be changed
private int lastUpdate; // last update in hours after install time
public Brew(int uid, BIngredients ingredients) { public Brew(int uid, BIngredients ingredients) {
this.ingredients = ingredients; this.ingredients = ingredients;
touch();
potions.put(uid, this); potions.put(uid, this);
} }
@ -44,11 +47,12 @@ public class Brew {
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
this.currentRecipe = recipe; this.currentRecipe = recipe;
touch();
potions.put(uid, this); potions.put(uid, this);
} }
// 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, boolean stat) { public Brew(int uid, BIngredients ingredients, int quality, int distillRuns, float ageTime, float wood, String recipe, boolean unlabeled, boolean persistent, boolean stat, int lastUpdate) {
potions.put(uid, this); potions.put(uid, this);
this.ingredients = ingredients; this.ingredients = ingredients;
this.quality = quality; this.quality = quality;
@ -58,6 +62,7 @@ public class Brew {
this.unlabeled = unlabeled; this.unlabeled = unlabeled;
this.persistent = persistent; this.persistent = persistent;
this.stat = stat; this.stat = stat;
this.lastUpdate = lastUpdate;
setRecipeFromString(recipe); setRecipeFromString(recipe);
} }
@ -273,6 +278,11 @@ public class Brew {
unlabeled = true; unlabeled = true;
} }
// Do some regular updates
public void touch() {
lastUpdate = (int) ((float) (System.currentTimeMillis() - installTime) / 3600000F);
}
public int getDistillRuns() { public int getDistillRuns() {
return distillRuns; return distillRuns;
} }
@ -315,6 +325,10 @@ public class Brew {
} }
} }
public int getLastUpdate() {
return lastUpdate;
}
// Distilling section --------------- // Distilling section ---------------
// distill all custom potions in the brewer // distill all custom potions in the brewer
@ -366,6 +380,7 @@ public class Brew {
prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns)); prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns));
} }
updateDistillLore(prefix, potionMeta); updateDistillLore(prefix, potionMeta);
touch();
slotItem.setItemMeta(potionMeta); slotItem.setItemMeta(potionMeta);
} }
@ -421,6 +436,7 @@ public class Brew {
updateWoodLore(potionMeta); updateWoodLore(potionMeta);
} }
} }
touch();
item.setItemMeta(potionMeta); item.setItemMeta(potionMeta);
} }
@ -650,6 +666,9 @@ public class Brew {
if (brew.stat) { if (brew.stat) {
idConfig.set("stat", true); idConfig.set("stat", true);
} }
if (brew.lastUpdate > 0) {
idConfig.set("lastUpdate", brew.lastUpdate);
}
// save the ingredients // save the ingredients
idConfig.set("ingId", brew.ingredients.save(config.getParent())); idConfig.set("ingId", brew.ingredients.save(config.getParent()));
} }

View File

@ -369,6 +369,8 @@ public class P extends JavaPlugin {
FileConfiguration data = YamlConfiguration.loadConfiguration(file); FileConfiguration data = YamlConfiguration.loadConfiguration(file);
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
// Check if data is the newest version // Check if data is the newest version
String version = data.getString("Version", null); String version = data.getString("Version", null);
if (version != null) { if (version != null) {
@ -410,8 +412,9 @@ public class P extends JavaPlugin {
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); boolean stat = section.getBoolean(uid + ".stat", false);
int lastUpdate = section.getInt("lastUpdate", 0);
new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat); new Brew(parseInt(uid), ingredients, quality, distillRuns, ageTime, wood, recipe, unlabeled, persistent, stat, lastUpdate);
} }
} }

View File

@ -59,6 +59,8 @@ public class DataSave extends BukkitRunnable {
FileConfiguration configFile = new YamlConfiguration(); FileConfiguration configFile = new YamlConfiguration();
configFile.set("installTime", Brew.installTime);
if (!Brew.potions.isEmpty()) { if (!Brew.potions.isEmpty()) {
Brew.save(configFile.createSection("Brew")); Brew.save(configFile.createSection("Brew"));
} }

View File

@ -430,6 +430,7 @@ public class CommandListener implements CommandExecutor {
brew.setStatic(true, hand); brew.setStatic(true, hand);
p.msg(sender, p.languageReader.get("CMD_Persistent")); p.msg(sender, p.languageReader.get("CMD_Persistent"));
} }
brew.touch();
return; return;
} }
} }
@ -459,6 +460,7 @@ public class CommandListener implements CommandExecutor {
brew.setStatic(true, hand); brew.setStatic(true, hand);
p.msg(sender, p.languageReader.get("CMD_Static")); p.msg(sender, p.languageReader.get("CMD_Static"));
} }
brew.touch();
return; return;
} }
} }
@ -478,6 +480,7 @@ public class CommandListener implements CommandExecutor {
Brew brew = Brew.get(hand); Brew brew = Brew.get(hand);
if (brew != null) { if (brew != null) {
brew.unLabel(hand); brew.unLabel(hand);
brew.touch();
p.msg(sender, p.languageReader.get("CMD_UnLabel")); p.msg(sender, p.languageReader.get("CMD_UnLabel"));
return; return;
} }

View File

@ -209,24 +209,24 @@ public class InventoryListener implements Listener {
return false; return false;
} }
// convert potions from 1.8 for color and to remove effect descriptions in 1.9 // Clicked a Brew somewhere, do some updating
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
public void onInventoryClickLow(InventoryClickEvent event) { public void onInventoryClickLow(InventoryClickEvent event) {
if (!P.use1_9) return;
if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.POTION)) { if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.POTION)) {
ItemStack item = event.getCurrentItem(); ItemStack item = event.getCurrentItem();
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
PotionMeta potion = ((PotionMeta) item.getItemMeta()); PotionMeta potion = ((PotionMeta) item.getItemMeta());
if (!potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
Brew brew = Brew.get(potion); Brew brew = Brew.get(potion);
if (brew != null) { if (brew != null) {
// convert potions from 1.8 to 1.9 for color and to remove effect descriptions
if (P.use1_9 && !potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
BRecipe recipe = brew.getCurrentRecipe(); BRecipe recipe = brew.getCurrentRecipe();
if (recipe != null) { if (recipe != null) {
Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill()); Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill());
item.setItemMeta(potion); item.setItemMeta(potion);
} }
} }
brew.touch();
} }
} }
} }