mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-22 11:35:16 +01:00
Store last updated time for brews
This commit is contained in:
parent
024c05b817
commit
bf57320057
@ -203,7 +203,7 @@ public class BRecipe {
|
||||
|
||||
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);
|
||||
potionMeta.setDisplayName(P.p.color("&f" + getName(quality)));
|
||||
@ -212,6 +212,7 @@ public class BRecipe {
|
||||
|
||||
brew.convertLore(potionMeta, false);
|
||||
Brew.addOrReplaceEffects(potionMeta, effects, quality);
|
||||
brew.touch();
|
||||
|
||||
potion.setItemMeta(potionMeta);
|
||||
return potion;
|
||||
|
@ -21,6 +21,7 @@ public class Brew {
|
||||
// represents the liquid in the brewed Potions
|
||||
|
||||
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 colorInBrewer; // color the Lore while in Brewer
|
||||
|
||||
@ -33,9 +34,11 @@ public class Brew {
|
||||
private boolean unlabeled;
|
||||
private boolean persistent;
|
||||
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) {
|
||||
this.ingredients = ingredients;
|
||||
touch();
|
||||
potions.put(uid, this);
|
||||
}
|
||||
|
||||
@ -44,11 +47,12 @@ public class Brew {
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
this.currentRecipe = recipe;
|
||||
touch();
|
||||
potions.put(uid, this);
|
||||
}
|
||||
|
||||
// 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);
|
||||
this.ingredients = ingredients;
|
||||
this.quality = quality;
|
||||
@ -58,6 +62,7 @@ public class Brew {
|
||||
this.unlabeled = unlabeled;
|
||||
this.persistent = persistent;
|
||||
this.stat = stat;
|
||||
this.lastUpdate = lastUpdate;
|
||||
setRecipeFromString(recipe);
|
||||
}
|
||||
|
||||
@ -273,6 +278,11 @@ public class Brew {
|
||||
unlabeled = true;
|
||||
}
|
||||
|
||||
// Do some regular updates
|
||||
public void touch() {
|
||||
lastUpdate = (int) ((float) (System.currentTimeMillis() - installTime) / 3600000F);
|
||||
}
|
||||
|
||||
public int getDistillRuns() {
|
||||
return distillRuns;
|
||||
}
|
||||
@ -315,6 +325,10 @@ public class Brew {
|
||||
}
|
||||
}
|
||||
|
||||
public int getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
// Distilling section ---------------
|
||||
|
||||
// distill all custom potions in the brewer
|
||||
@ -366,6 +380,7 @@ public class Brew {
|
||||
prefix = getQualityColor(ingredients.getDistillQuality(recipe, distillRuns));
|
||||
}
|
||||
updateDistillLore(prefix, potionMeta);
|
||||
touch();
|
||||
|
||||
slotItem.setItemMeta(potionMeta);
|
||||
}
|
||||
@ -421,6 +436,7 @@ public class Brew {
|
||||
updateWoodLore(potionMeta);
|
||||
}
|
||||
}
|
||||
touch();
|
||||
item.setItemMeta(potionMeta);
|
||||
}
|
||||
|
||||
@ -650,6 +666,9 @@ public class Brew {
|
||||
if (brew.stat) {
|
||||
idConfig.set("stat", true);
|
||||
}
|
||||
if (brew.lastUpdate > 0) {
|
||||
idConfig.set("lastUpdate", brew.lastUpdate);
|
||||
}
|
||||
// save the ingredients
|
||||
idConfig.set("ingId", brew.ingredients.save(config.getParent()));
|
||||
}
|
||||
|
@ -369,6 +369,8 @@ public class P extends JavaPlugin {
|
||||
|
||||
FileConfiguration data = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
Brew.installTime = data.getLong("installTime", System.currentTimeMillis());
|
||||
|
||||
// Check if data is the newest version
|
||||
String version = data.getString("Version", null);
|
||||
if (version != null) {
|
||||
@ -410,8 +412,9 @@ public class P extends JavaPlugin {
|
||||
boolean unlabeled = section.getBoolean(uid + ".unlabeled", false);
|
||||
boolean persistent = section.getBoolean(uid + ".persist", 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,8 @@ public class DataSave extends BukkitRunnable {
|
||||
|
||||
FileConfiguration configFile = new YamlConfiguration();
|
||||
|
||||
configFile.set("installTime", Brew.installTime);
|
||||
|
||||
if (!Brew.potions.isEmpty()) {
|
||||
Brew.save(configFile.createSection("Brew"));
|
||||
}
|
||||
|
@ -430,6 +430,7 @@ public class CommandListener implements CommandExecutor {
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Persistent"));
|
||||
}
|
||||
brew.touch();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -459,6 +460,7 @@ public class CommandListener implements CommandExecutor {
|
||||
brew.setStatic(true, hand);
|
||||
p.msg(sender, p.languageReader.get("CMD_Static"));
|
||||
}
|
||||
brew.touch();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -478,6 +480,7 @@ public class CommandListener implements CommandExecutor {
|
||||
Brew brew = Brew.get(hand);
|
||||
if (brew != null) {
|
||||
brew.unLabel(hand);
|
||||
brew.touch();
|
||||
p.msg(sender, p.languageReader.get("CMD_UnLabel"));
|
||||
return;
|
||||
}
|
||||
|
@ -209,24 +209,24 @@ public class InventoryListener implements Listener {
|
||||
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)
|
||||
public void onInventoryClickLow(InventoryClickEvent event) {
|
||||
if (!P.use1_9) return;
|
||||
|
||||
if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.POTION)) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
if (item.hasItemMeta()) {
|
||||
PotionMeta potion = ((PotionMeta) item.getItemMeta());
|
||||
if (!potion.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
Brew brew = Brew.get(potion);
|
||||
if (brew != null) {
|
||||
Brew brew = Brew.get(potion);
|
||||
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();
|
||||
if (recipe != null) {
|
||||
Brew.PotionColor.valueOf(recipe.getColor()).colorBrew(potion, item, brew.canDistill());
|
||||
item.setItemMeta(potion);
|
||||
}
|
||||
}
|
||||
brew.touch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user