From 12b0a3c115022ab55ea48ebeedbd7150d3ec149e Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Sun, 5 Apr 2020 22:47:46 +0200 Subject: [PATCH] Added Brew Sealing: Equalize Brews for Shops Craftable Brew Sealing Table Equalizes Brews that are similar, for support in Shop Plugins Sealed Brews are also always unlabeled and immutable --- resources/languages/de.yml | 3 + resources/languages/en.yml | 3 + src/com/dre/brewery/BSealer.java | 106 ++++++++++++++++++ src/com/dre/brewery/Brew.java | 74 +++++++++++- src/com/dre/brewery/MCBarrel.java | 10 +- src/com/dre/brewery/P.java | 4 + .../api/events/brew/BrewModifyEvent.java | 5 + .../dre/brewery/listeners/BlockListener.java | 30 +++-- .../brewery/listeners/CommandListener.java | 40 ++++--- .../brewery/listeners/InventoryListener.java | 21 +++- .../dre/brewery/listeners/PlayerListener.java | 11 ++ src/com/dre/brewery/lore/BrewLore.java | 53 +++++++-- src/com/dre/brewery/utility/SQLSync.java | 12 +- 13 files changed, 327 insertions(+), 45 deletions(-) create mode 100644 src/com/dre/brewery/BSealer.java diff --git a/resources/languages/de.yml b/resources/languages/de.yml index b4f009a..af59be5 100644 --- a/resources/languages/de.yml +++ b/resources/languages/de.yml @@ -4,6 +4,7 @@ Brew_BadPotion: Verdorbenes Gebräu Brew_BarrelRiped: Fassgereift Brew_DistillUndefined: Graues Destillat Brew_Distilled: Destilliert +Brew_LessDistilled: Wenig Destilliert Brew_HundredsOfYears: Hunderte Jahre Brew_Ingredients: Zutaten Brew_MinutePluralPostfix: n @@ -33,6 +34,8 @@ CMD_NonStatic: '&eTrank ist wieder veränderlich und kann normal gereift oder de # Error Error_ConfigUpdate: 'Unbekannte Brewery Config Version: v&v1, Config wurde nicht geupdated!' Error_ItemNotPotion: '&cDas Item in deiner Hand konnte nicht als Trank identifiziert werden' +Error_SealedAlwaysStatic: 'Versiegelte Tränke sind immer unveränderlich!' +Error_AlreadyUnlabeled: '&cDer Trank in deiner Hand ist bereits Entlabelt!' Error_NoBarrelAccess: '&cDu hast keine Rechte dieses Fass zu öffnen!' Error_NoBrewName: '&cKein Rezept mit Namen: "&v1&c" gefunden!' Error_NoPermissions: '&cDu hast keine Rechte dies zu tun!' diff --git a/resources/languages/en.yml b/resources/languages/en.yml index b328e82..f4971fb 100644 --- a/resources/languages/en.yml +++ b/resources/languages/en.yml @@ -4,6 +4,7 @@ Brew_BadPotion: Ruined Potion Brew_BarrelRiped: Barrel aged Brew_DistillUndefined: Murky Distillate Brew_Distilled: Distilled +Brew_LessDistilled: Less Distilled Brew_HundredsOfYears: Hundreds of Years Brew_Ingredients: Ingredients Brew_MinutePluralPostfix: s @@ -33,6 +34,8 @@ CMD_UnLabel: '&aLabel removed!' # Error Error_ConfigUpdate: 'Unknown Brewery config version: v&v1, config was not updated!' Error_ItemNotPotion: '&cThe item in your hand could not be identified as a potion!' +Error_SealedAlwaysStatic: 'Sealed Brews are always static!' +Error_AlreadyUnlabeled: '&cThe Brew in your hand is already unlabeled!' Error_NoBarrelAccess: '&cYou don''t have permissions to access this barrel!' Error_NoBrewName: '&cNo Recipe with Name: ''&v1&c'' found!' Error_NoPermissions: '&cYou don''t have permissions to do this!' diff --git a/src/com/dre/brewery/BSealer.java b/src/com/dre/brewery/BSealer.java new file mode 100644 index 0000000..d45be9e --- /dev/null +++ b/src/com/dre/brewery/BSealer.java @@ -0,0 +1,106 @@ +package com.dre.brewery; + +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Sound; +import org.bukkit.Tag; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; +import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.inventory.meta.BlockStateMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; + +public class BSealer implements InventoryHolder { + public static final String TABLE_NAME = "§eBrew Sealing Table"; + + private final Inventory inventory; + private final Player player; + private short[] slotTime = new short[9]; + ItemStack[] contents = null; + BukkitTask task; + + public BSealer(Player player) { + this.player = player; + inventory = P.p.getServer().createInventory(this, InventoryType.DISPENSER, "Brew Sealing Table"); + } + + @Override + public @NotNull Inventory getInventory() { + return inventory; + } + + + public void clickInv() { + contents = null; + if (task == null) { + task = P.p.getServer().getScheduler().runTaskTimer(P.p, this::itemChecking, 1, 1); + } + } + + public void closeInv() { + if (task != null) { + task.cancel(); + task = null; + } + contents = inventory.getContents(); + for (ItemStack item : contents) { + if (item != null && item.getType() != Material.AIR) { + player.getWorld().dropItemNaturally(player.getLocation(), item); + } + } + contents = null; + inventory.clear(); + } + + private void itemChecking() { + if (contents == null) { + contents = inventory.getContents(); + for (int i = 0; i < slotTime.length; i++) { + if (contents[i] == null || contents[i].getType() != Material.POTION) { + slotTime[i] = -1; + } else if (slotTime[i] < 0) { + slotTime[i] = 0; + } + } + } + boolean playerValid = player.isValid() && !player.isDead(); + for (int i = 0; i < slotTime.length; i++) { + if (slotTime[i] > 20) { + slotTime[i] = -1; + Brew brew = Brew.get(contents[i]); + if (brew != null && !brew.isStripped()) { + brew.seal(contents[i]); + if (playerValid) { + player.playSound(player.getLocation(), Sound.ITEM_BOTTLE_FILL_DRAGONBREATH, 1, 1.5f + (float) (Math.random() * 0.2)); + } + } + } else if (slotTime[i] >= 0) { + slotTime[i]++; + } + } + } + + + public static void registerRecipe() { + ItemStack sealingTableItem = new ItemStack(Material.SMOKER); + ItemMeta meta = P.p.getServer().getItemFactory().getItemMeta(Material.SMOKER); + if (meta == null) return; + meta.setDisplayName(TABLE_NAME); + sealingTableItem.setItemMeta(meta); + + ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(P.p, "SealingTable"), sealingTableItem); + recipe.shape("bb ", + "ww ", + "ww "); + recipe.setIngredient('b', Material.GLASS_BOTTLE); + recipe.setIngredient('w', new RecipeChoice.MaterialChoice(Tag.PLANKS)); + + P.p.getServer().addRecipe(recipe); + } +} diff --git a/src/com/dre/brewery/Brew.java b/src/com/dre/brewery/Brew.java index 429d9dc..e8ef874 100644 --- a/src/com/dre/brewery/Brew.java +++ b/src/com/dre/brewery/Brew.java @@ -46,10 +46,11 @@ public class Brew implements Cloneable { private byte distillRuns; private float ageTime; private float wood; - private BRecipe currentRecipe; // Recipe this Brew is currently Based off. May change between modifications and is often null when not modifying + private BRecipe currentRecipe; // Recipe this Brew is currently based off. May change between modifications and is often null when not modifying private boolean unlabeled; private boolean persistent; // Only for legacy private boolean immutable; // static/immutable potions should not be changed + private boolean stripped; // Most Brewing information removed, only drinking and rough quality information available. Brew should not change anymore private int lastUpdate; // last update in hours after install time private boolean needsSave; // There was a change that has not yet been saved @@ -291,6 +292,7 @@ public class Brew implements Cloneable { unlabeled == brew.unlabeled && persistent == brew.persistent && immutable == brew.immutable && + stripped == brew.stripped && ingredients.equals(brew.ingredients) && (Objects.equals(currentRecipe, brew.currentRecipe)); } @@ -321,6 +323,7 @@ public class Brew implements Cloneable { ", currentRecipe=" + currentRecipe + ", unlabeled=" + unlabeled + ", immutable=" + immutable + + ", stripped=" + stripped + '}'; } @@ -422,6 +425,7 @@ public class Brew implements Cloneable { * @param item The Item this Brew is on */ public void unLabel(ItemStack item) { + if (unlabeled) return; unlabeled = true; ItemMeta meta = item.getItemMeta(); if (meta instanceof PotionMeta && meta.hasLore()) { @@ -439,6 +443,49 @@ public class Brew implements Cloneable { } } + /** + * Sealing the Brew to make it Immutable, Unlabeled and Stripped + *

This makes it easier to sell in shops as Brews that are mostly the same will be equal after + * + * @param potion The Item this Brew is on + */ + public void seal(ItemStack potion) { + if (stripped) return; + ItemMeta origMeta = potion.getItemMeta(); + if (!(origMeta instanceof PotionMeta)) return; + + if (quality == 1) { + quality = 2; + } else if (quality % 2 == 1) { + quality--; + } + alc = calcAlcohol(); + + setStatic(true, potion); + unLabel(potion); + PotionMeta meta = (PotionMeta) potion.getItemMeta(); + BrewLore lore = new BrewLore(this, meta); + lore.updateQualityStars(false, true); + lore.write(); + + stripped = true; + ingredients = new BIngredients(); + ageTime = 0; + wood = -1; + touch(); + + BrewModifyEvent modifyEvent = new BrewModifyEvent(this, meta, BrewModifyEvent.Type.SEAL); + P.p.getServer().getPluginManager().callEvent(modifyEvent); + if (modifyEvent.isCancelled()) { + // As the brew and everything connected to it is only saved on the meta from now on, + // restoring the origMeta is enough in this case + potion.setItemMeta(origMeta); + return; + } + save(meta); + potion.setItemMeta(meta); + } + /** * Do some regular updates. *

Not really used, apart from legacy potion timed purge @@ -491,6 +538,14 @@ public class Brew implements Cloneable { return unlabeled; } + public boolean isStripped() { + return stripped; + } + + public boolean isSealed() { + return stripped && immutable; + } + public boolean needsSave() { return needsSave; } @@ -503,14 +558,17 @@ public class Brew implements Cloneable { * Set the Static flag, so potion is unchangeable */ public void setStatic(boolean immutable, ItemStack potion) { - this.immutable = immutable; - if (currentRecipe != null && canDistill()) { + if (!immutable && isStripped()) { + throw new IllegalStateException("Cannot make stripped Brews non-static"); + } + if (!P.use1_9 && currentRecipe != null && canDistill()) { if (immutable) { currentRecipe.getColor().colorBrew(((PotionMeta) potion.getItemMeta()), potion, false); } else { currentRecipe.getColor().colorBrew(((PotionMeta) potion.getItemMeta()), potion, true); } } + this.immutable = immutable; } public int getLastUpdate() { @@ -671,6 +729,7 @@ public class Brew implements Cloneable { * Slowly shift the wood of the Brew to the new Type */ public void woodShift(float time, byte to) { + if (immutable) return; float factor = 1; if (ageTime > 5) { factor = 2; @@ -815,7 +874,7 @@ public class Brew implements Cloneable { if (parityFailed) { P.p.errorLog("Failed to load Brew. Maybe something corrupted the Lore of the Item?"); } else { - P.p.errorLog("Brew has data stored in v" + ver + " this Plugin version supports up to v1"); + P.p.errorLog("Brew has data stored in v" + ver + " this Plugin version supports up to v" + SAVE_VER); } return null; } @@ -824,7 +883,7 @@ public class Brew implements Cloneable { if (successType == XORUnscrambleStream.SuccessType.PREV_SEED) { P.p.debugLog("Converting Brew from previous Seed"); brew.setNeedsSave(true); - } else if (BConfig.enableEncode != (successType == XORUnscrambleStream.SuccessType.MAIN_SEED)) { + } else if ((BConfig.enableEncode && !brew.isStripped()) != (successType == XORUnscrambleStream.SuccessType.MAIN_SEED)) { // We have either enabled encode and the data was not encoded or the other way round P.p.debugLog("Converting Brew to new encode setting"); brew.setNeedsSave(true); @@ -866,6 +925,7 @@ public class Brew implements Cloneable { } unlabeled = (bools & 16) != 0; immutable = (bools & 32) != 0; + stripped = (bools & 128) != 0; ingredients = BIngredients.load(in, dataVersion); setRecipeFromString(recipe); } @@ -885,7 +945,8 @@ public class Brew implements Cloneable { try (DataOutputStream out = new DataOutputStream(scrambler)) { out.writeByte(86); // Parity/sanity out.writeByte(SAVE_VER); // Version - if (BConfig.enableEncode) { + // If Stripped of data, we can save everything unscrambled + if (BConfig.enableEncode && !isStripped()) { scrambler.start(); } else { scrambler.startUnscrambled(); @@ -928,6 +989,7 @@ public class Brew implements Cloneable { bools |= (unlabeled ? 16 : 0); bools |= (immutable ? 32 : 0); bools |= (alc > 0 ? 64 : 0); + bools |= (stripped ? 128 : 0); out.writeByte(bools); if (alc > 0) { out.writeShort(alc); diff --git a/src/com/dre/brewery/MCBarrel.java b/src/com/dre/brewery/MCBarrel.java index 6fda3c3..2c0308b 100644 --- a/src/com/dre/brewery/MCBarrel.java +++ b/src/com/dre/brewery/MCBarrel.java @@ -57,7 +57,7 @@ public class MCBarrel { for (ItemStack item : inv.getContents()) { if (item != null) { Brew brew = Brew.get(item); - if (brew != null) { + if (brew != null && !brew.isStatic()) { if (brews < maxBrews || maxBrews < 0) { // The time is in minutes, but brew.age() expects time in mc-days brew.age(item, ((float) time) / 20f, OAK); @@ -66,9 +66,11 @@ public class MCBarrel { } } } - loadTime = System.nanoTime() - loadTime; - float ftime = (float) (loadTime / 1000000.0); - P.p.debugLog("opening MC Barrel with potions (" + ftime + "ms)"); + if (P.debug) { + loadTime = System.nanoTime() - loadTime; + float ftime = (float) (loadTime / 1000000.0); + P.p.debugLog("opening MC Barrel with potions (" + ftime + "ms)"); + } } } } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index b215773..8b99f50 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -125,6 +125,10 @@ public class P extends JavaPlugin { p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200); p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120); + if (P.use1_14) { + BSealer.registerRecipe(); + } + if (BConfig.updateCheck) { try { p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135); diff --git a/src/com/dre/brewery/api/events/brew/BrewModifyEvent.java b/src/com/dre/brewery/api/events/brew/BrewModifyEvent.java index 74bed88..94b55c0 100644 --- a/src/com/dre/brewery/api/events/brew/BrewModifyEvent.java +++ b/src/com/dre/brewery/api/events/brew/BrewModifyEvent.java @@ -101,6 +101,11 @@ public class BrewModifyEvent extends BrewEvent implements Cancellable { */ STATIC, + /** + * Sealing the Brew (unlabel & static & stripped) With Command or Machine + */ + SEAL, + /** * Unknown modification, unused. */ diff --git a/src/com/dre/brewery/listeners/BlockListener.java b/src/com/dre/brewery/listeners/BlockListener.java index 37a5a4a..382c937 100644 --- a/src/com/dre/brewery/listeners/BlockListener.java +++ b/src/com/dre/brewery/listeners/BlockListener.java @@ -1,21 +1,22 @@ package com.dre.brewery.listeners; import com.dre.brewery.BPlayer; -import com.dre.brewery.utility.BUtil; +import com.dre.brewery.BSealer; import com.dre.brewery.Barrel; -import com.dre.brewery.P; import com.dre.brewery.DistortChat; +import com.dre.brewery.P; import com.dre.brewery.api.events.barrel.BarrelDestroyEvent; +import com.dre.brewery.utility.BUtil; +import org.bukkit.Material; +import org.bukkit.Nameable; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.Directional; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockBurnEvent; -import org.bukkit.event.block.BlockPistonExtendEvent; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.block.*; public class BlockListener implements Listener { @@ -44,6 +45,21 @@ public class BlockListener implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if (!P.use1_14) return; + if (event.getBlock().getType() == Material.SMOKER) { + BlockState state = event.getBlock().getState(); + Nameable name = (Nameable) state; + if (name.getCustomName() != null && name.getCustomName().equals(BSealer.TABLE_NAME)) { + // Rotate the Block 180° so it doesn't look like a Smoker + Directional dir = (Directional) state.getBlockData(); + dir.setFacing(dir.getFacing().getOppositeFace()); + event.getBlock().setBlockData(dir); + } + } + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (!BUtil.blockDestroy(event.getBlock(), event.getPlayer(), BarrelDestroyEvent.Reason.PLAYER)) { diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index f5fbfb1..70861ac 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -430,8 +430,13 @@ public class CommandListener implements CommandExecutor { Brew brew = Brew.get(hand); if (brew != null) { if (brew.isStatic()) { - brew.setStatic(false, hand); - p.msg(sender, p.languageReader.get("CMD_NonStatic")); + if (!brew.isStripped()) { + brew.setStatic(false, hand); + p.msg(sender, p.languageReader.get("CMD_NonStatic")); + } else { + p.msg(sender, p.languageReader.get("Error_SealedAlwaysStatic")); + return; + } } else { brew.setStatic(true, hand); p.msg(sender, p.languageReader.get("CMD_Static")); @@ -465,21 +470,26 @@ public class CommandListener implements CommandExecutor { if (hand != null) { Brew brew = Brew.get(hand); if (brew != null) { - ItemMeta origMeta = hand.getItemMeta(); - brew.unLabel(hand); - brew.touch(); - ItemMeta meta = hand.getItemMeta(); - assert meta != null; - BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.UNLABEL); - P.p.getServer().getPluginManager().callEvent(modifyEvent); - if (modifyEvent.isCancelled()) { - hand.setItemMeta(origMeta); + if (!brew.isUnlabeled()) { + ItemMeta origMeta = hand.getItemMeta(); + brew.unLabel(hand); + brew.touch(); + ItemMeta meta = hand.getItemMeta(); + assert meta != null; + BrewModifyEvent modifyEvent = new BrewModifyEvent(brew, meta, BrewModifyEvent.Type.UNLABEL); + P.p.getServer().getPluginManager().callEvent(modifyEvent); + if (modifyEvent.isCancelled()) { + hand.setItemMeta(origMeta); + return; + } + brew.save(meta); + hand.setItemMeta(meta); + p.msg(sender, p.languageReader.get("CMD_UnLabel")); + return; + } else { + p.msg(sender, p.languageReader.get("Error_AlreadyUnlabeled")); return; } - brew.save(meta); - hand.setItemMeta(meta); - p.msg(sender, p.languageReader.get("CMD_UnLabel")); - return; } } p.msg(sender, p.languageReader.get("Error_ItemNotPotion")); diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 6484c22..dfaeb1d 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -1,10 +1,6 @@ package com.dre.brewery.listeners; -import com.dre.brewery.BDistiller; -import com.dre.brewery.Barrel; -import com.dre.brewery.Brew; -import com.dre.brewery.MCBarrel; -import com.dre.brewery.P; +import com.dre.brewery.*; import com.dre.brewery.filedata.BConfig; import com.dre.brewery.lore.BrewLore; import org.bukkit.Material; @@ -16,6 +12,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.*; import org.bukkit.inventory.BrewerInventory; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; @@ -193,6 +190,16 @@ public class InventoryListener implements Listener { barrel.clickInv(event); } + // Handle the Brew Sealer Inventory + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onInventoryClickBSealer(InventoryClickEvent event) { + InventoryHolder holder = event.getInventory().getHolder(); + if (!(holder instanceof BSealer)) { + return; + } + ((BSealer) holder).clickInv(); + } + //public static boolean opening = false; @SuppressWarnings("deprecation") @@ -289,6 +296,10 @@ public class InventoryListener implements Listener { @EventHandler public void onInventoryClose(InventoryCloseEvent event) { + if (event.getInventory().getHolder() instanceof BSealer) { + ((BSealer) event.getInventory().getHolder()).closeInv(); + } + if (!P.use1_14) return; // Barrel Closing Sound diff --git a/src/com/dre/brewery/listeners/PlayerListener.java b/src/com/dre/brewery/listeners/PlayerListener.java index d92504c..0ac5c7b 100644 --- a/src/com/dre/brewery/listeners/PlayerListener.java +++ b/src/com/dre/brewery/listeners/PlayerListener.java @@ -6,6 +6,7 @@ import com.dre.brewery.filedata.UpdateChecker; import com.dre.brewery.utility.LegacyUtil; import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.Nameable; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -40,6 +41,16 @@ public class PlayerListener implements Listener { return; } + if (P.use1_14 && type == Material.SMOKER) { + Nameable smoker = (Nameable) clickedBlock.getState(); + if (smoker.getCustomName() != null && smoker.getCustomName().equals(BSealer.TABLE_NAME)) { + event.setCancelled(true); + BSealer sealer = new BSealer(player); + event.getPlayer().openInventory(sealer.getInventory()); + return; + } + } + // Do not process Off Hand for Barrel interaction if (P.use1_9 && event.getHand() != EquipmentSlot.HAND) { return; diff --git a/src/com/dre/brewery/lore/BrewLore.java b/src/com/dre/brewery/lore/BrewLore.java index 8dba914..81f6537 100644 --- a/src/com/dre/brewery/lore/BrewLore.java +++ b/src/com/dre/brewery/lore/BrewLore.java @@ -111,7 +111,7 @@ public class BrewLore { * @param qualityColor If the lore should have colors according to quality */ public void updateIngredientLore(boolean qualityColor) { - if (qualityColor && brew.hasRecipe()) { + if (qualityColor && brew.hasRecipe() && !brew.isStripped()) { String prefix = getQualityColor(brew.getIngredients().getIngredientQuality(brew.getCurrentRecipe())); addOrReplaceLore(Type.INGR, prefix, P.p.languageReader.get("Brew_Ingredients")); } else { @@ -125,7 +125,7 @@ public class BrewLore { * @param qualityColor If the lore should have colors according to quality */ public void updateCookLore(boolean qualityColor) { - if (qualityColor && brew.hasRecipe() && brew.getDistillRuns() > 0 == brew.getCurrentRecipe().needsDistilling()) { + if (qualityColor && brew.hasRecipe() && brew.getDistillRuns() > 0 == brew.getCurrentRecipe().needsDistilling() && !brew.isStripped()) { BIngredients ingredients = brew.getIngredients(); int quality = ingredients.getCookingQuality(brew.getCurrentRecipe(), brew.getDistillRuns() > 0); String prefix = getQualityColor(quality) + ingredients.getCookedTime() + " " + P.p.languageReader.get("Brew_minute"); @@ -157,7 +157,11 @@ public class BrewLore { prefix = prefix + distillRuns + P.p.languageReader.get("Brew_-times") + " "; } } - addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_Distilled")); + if (brew.isUnlabeled() && brew.hasRecipe() && distillRuns < brew.getCurrentRecipe().getDistillRuns()) { + addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_LessDistilled")); + } else { + addOrReplaceLore(Type.DISTILL, prefix, P.p.languageReader.get("Brew_Distilled")); + } } /** @@ -166,6 +170,7 @@ public class BrewLore { * @param qualityColor If the lore should have colors according to quality */ public void updateAgeLore(boolean qualityColor) { + if (brew.isStripped()) return; String prefix; float age = brew.getAgeTime(); if (qualityColor && !brew.isUnlabeled() && brew.hasRecipe()) { @@ -221,19 +226,30 @@ public class BrewLore { } public void updateQualityStars(boolean qualityColor) { + updateQualityStars(qualityColor, false); + } + + + public void updateQualityStars(boolean qualityColor, boolean withBars) { + if (brew.isStripped()) return; if (brew.hasRecipe() && brew.getCurrentRecipe().needsToAge() && brew.getAgeTime() < 0.5) { return; } - if (!brew.isUnlabeled() && brew.getQuality() > 0 && (qualityColor || BConfig.alwaysShowQuality)) { - int stars = (brew.getQuality()) / 2; - boolean half = (brew.getQuality()) % 2 > 0; + int quality = brew.getQuality(); + if (quality > 0 && (qualityColor || BConfig.alwaysShowQuality)) { + int stars = quality / 2; + boolean half = quality % 2 > 0; + int noStars = 5 - stars - (half ? 1 : 0); StringBuilder b = new StringBuilder(24); String color; if (qualityColor) { - color = getQualityColor(brew.getQuality()); + color = getQualityColor(quality); } else { color = "§7"; } + if (withBars) { + color = "§8[" + color; + } for (; stars > 0; stars--) { b.append("⭑"); } @@ -243,12 +259,35 @@ public class BrewLore { } b.append("⭒"); } + if (withBars) { + if (noStars > 0) { + b.append("§0"); + for (; noStars > 0; noStars--) { + b.append("⭑"); + } + } + b.append("§8]"); + } addOrReplaceLore(Type.STARS, color, b.toString()); } else { removeLore(Type.STARS); } } + /** + * Show the Seal-bars |*****| around the Lore Quality-Stars + */ + /*public void showSeal() { + int starsLine = Type.STARS.findInLore(lore); + if (starsLine > -1) { + StringBuilder lineEdit = new StringBuilder(lore.get(starsLine)); + int index = Type.STARS.id.length(); + lineEdit.insert(index, "§8["); + lineEdit.append("§8]"); + lore.set(starsLine, lineEdit.toString()); + } + }*/ + public void updateAlc(boolean inDistiller) { if (!brew.isUnlabeled() && (inDistiller || BConfig.alwaysShowAlc) && (!brew.hasRecipe() || brew.getCurrentRecipe().getAlcohol() > 0)) { int alc = brew.getOrCalcAlc(); diff --git a/src/com/dre/brewery/utility/SQLSync.java b/src/com/dre/brewery/utility/SQLSync.java index 0098d6f..3087b01 100644 --- a/src/com/dre/brewery/utility/SQLSync.java +++ b/src/com/dre/brewery/utility/SQLSync.java @@ -133,8 +133,18 @@ public class SQLSync { "PRIMARY KEY (id));"); connector = str; + } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); + if (P.debug) { + e.printStackTrace(); + } else { + P.p.errorLog("SQL Exception occured, set 'debug: true' for more info"); + P.p.errorLog(e.getMessage()); + Throwable cause = e.getCause(); + if (cause != null) { + P.p.errorLog(cause.getMessage()); + } + } return false; }