From d99f63a8e5169e74c1e1ab56bd57a92271c94496 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 5 Aug 2016 22:16:14 +0200 Subject: [PATCH] Now displays if a potion is extended --- .../de/epiceric/shopchest/config/Regex.java | 3 ++- .../shopchest/language/LanguageUtils.java | 3 ++- .../shopchest/language/LocalizedMessage.java | 1 + .../listeners/ShopInteractListener.java | 18 +++++++++++++++++- src/main/resources/lang/de_DE.lang | 3 ++- src/main/resources/lang/en_US.lang | 8 ++++++-- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/config/Regex.java b/src/main/java/de/epiceric/shopchest/config/Regex.java index 3d5abfd..5f523f3 100644 --- a/src/main/java/de/epiceric/shopchest/config/Regex.java +++ b/src/main/java/de/epiceric/shopchest/config/Regex.java @@ -17,7 +17,8 @@ public enum Regex { POTION_EFFECT("%POTION-EFFECT%"), MUSIC_TITLE("%MUSIC-TITLE%"), PROPERTY("%PROPERTY%"), - VALUE("%VALUE%"); + VALUE("%VALUE%"), + EXTENDED("%EXTENDED%"); private String name; diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 9999218..e03664f 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -856,13 +856,14 @@ public class LanguageUtils { messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT, langConfig.getString("message.shopInfo.product", "&6Product: &e%AMOUNT% x %ITEMNAME%"), Regex.AMOUNT, Regex.ITEM_NAME)); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_STOCK, langConfig.getString("message.shopInfo.stock", "&6In Stock: &e%AMOUNT%"), Regex.AMOUNT)); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, langConfig.getString("message.shopInfo.enchantments", "&6Enchantments: &e%ENCHANTMENT%"), Regex.ENCHANTMENT)); - messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, langConfig.getString("message.shopInfo.potion-effect", "&6Potion Effect: &e%POTION-EFFECT%"), Regex.POTION_EFFECT)); + messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, langConfig.getString("message.shopInfo.potion-effect", "&6Potion Effect: &e%POTION-EFFECT% %EXTENDED%"), Regex.POTION_EFFECT, Regex.EXTENDED)); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, langConfig.getString("message.shopInfo.music-disc-title", "&6Music Disc Title: &e%MUSIC-TITLE%"), Regex.MUSIC_TITLE)); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_NONE, langConfig.getString("message.shopInfo.none", "&7None"))); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRICE, langConfig.getString("message.shopInfo.price", "&6Price: Buy: &e%BUY-PRICE%&6 Sell: &e%SELL-PRICE%"), Regex.BUY_PRICE, Regex.SELL_PRICE)); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED, langConfig.getString("message.shopInfo.disabled", "&7Disabled"))); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_NORMAL, langConfig.getString("message.shopInfo.is-normal", "&6Type: &eNormal"))); messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ADMIN, langConfig.getString("message.shopInfo.is-admin", "&6Type: &eAdmin"))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED, langConfig.getString("message.shopInfo.extended", "(Extended)"))); messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SELL_DISABLED, langConfig.getString("message.buy-and-sell-disabled", "&cYou can't create a shop with buying and selling disabled."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCCESS, langConfig.getString("message.buy-success", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a from &6%VENDOR%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.BUY_PRICE, Regex.VENDOR)); messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCESS_ADMIN, langConfig.getString("message.buy-success-admin", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.BUY_PRICE)); diff --git a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java index 83740e1..4bfee30 100644 --- a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java +++ b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java @@ -60,6 +60,7 @@ public class LocalizedMessage { SHOP_INFO_DISABLED, SHOP_INFO_NORMAL, SHOP_INFO_ADMIN, + SHOP_INFO_EXTENDED, BUY_SELL_DISABLED, BUY_SUCCESS, BUY_SUCESS_ADMIN, diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 9341f79..1f01431 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -35,6 +35,8 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.Potion; import java.util.HashMap; import java.util.Map; @@ -331,11 +333,16 @@ public class ShopInteractListener implements Listener { String shopType = LanguageUtils.getMessage(shop.getShopType() == ShopType.NORMAL ? LocalizedMessage.Message.SHOP_INFO_NORMAL : LocalizedMessage.Message.SHOP_INFO_ADMIN); String stock = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_STOCK, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(amount))); + boolean potionExtended = false; + Map enchantmentMap; if (Utils.getMajorVersion() >= 9) { if (type == Material.TIPPED_ARROW || type == Material.LINGERING_POTION || type == Material.SPLASH_POTION) { potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct()); + PotionMeta potionMeta = (PotionMeta) shop.getProduct().getItemMeta(); + potionExtended = potionMeta.getBasePotionData().isExtended(); + if (potionEffectString == null) potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE); } @@ -343,6 +350,14 @@ public class ShopInteractListener implements Listener { if (type == Material.POTION) { potionEffectString = LanguageUtils.getPotionEffectName(shop.getProduct()); + if (Utils.getMajorVersion() < 9) { + Potion potion = Potion.fromItemStack(shop.getProduct()); + potionExtended = potion.hasExtendedDuration(); + } else { + PotionMeta potionMeta = (PotionMeta) shop.getProduct().getItemMeta(); + potionExtended = potionMeta.getBasePotionData().isExtended(); + } + if (potionEffectString == null) potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_NONE); } @@ -374,7 +389,8 @@ public class ShopInteractListener implements Listener { if (enchantmentString.length() > 0) executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, new LocalizedMessage.ReplacedRegex(Regex.ENCHANTMENT, enchantmentString))); if (potionEffectString.length() > 0) - executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, new LocalizedMessage.ReplacedRegex(Regex.POTION_EFFECT, potionEffectString))); + executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, new LocalizedMessage.ReplacedRegex(Regex.POTION_EFFECT, potionEffectString), + new LocalizedMessage.ReplacedRegex(Regex.EXTENDED, (potionExtended ? LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED) : "")))); if (musicDiscName.length() > 0) executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, new LocalizedMessage.ReplacedRegex(Regex.MUSIC_TITLE, musicDiscName))); executor.sendMessage(price); diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index 1819d5c..858c088 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -9,13 +9,14 @@ message.shopInfo.vendor=&6Verkäufer: &e%VENDOR% message.shopInfo.product=&6Produkt: &e%AMOUNT% x %ITEMNAME% message.shopInfo.stock=&6Auf Lager: &e%AMOUNT% message.shopInfo.enchantments=&6Verzauberungen: &e%ENCHANTMENT% -message.shopInfo.potion-effect=&6Trank-Effekte: &e%POTION-EFFECT% +message.shopInfo.potion-effect=&6Trank-Effekte: &e%POTION-EFFECT% %EXTENDED% message.shopInfo.music-disc-title=&6Schallplattentitel: &e%MUSIC-TITLE% message.shopInfo.none=&7Keine message.shopInfo.price=&6Preis: Kauf: &e%BUY-PRICE%&6 Verkauf: &e%SELL-PRICE% message.shopInfo.disabled=&7Deaktiviert message.shopInfo.is-normal=&6Typ: &eNormal message.shopInfo.is-admin=&6Typ: &eAdmin +message.shopInfo.extended=(Verlängert) message.buy-and-sell-disabled=&cDu kannst keinen Shop ohne Kauf- und Verkaufspreis erstellen. message.buy-success=&aDu hast &6%AMOUNT% x %ITEMNAME%&a für &6%BUY-PRICE%&a von &6%VENDOR% &agekauft. message.buy-success-admin=&aDu hast &6%AMOUNT% x %ITEMNAME%&a für &6%BUY-PRICE% &agekauft. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index 3b1641b..3233c4c 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -38,8 +38,8 @@ message.shopInfo.stock=&6In Stock: &e%AMOUNT% message.shopInfo.enchantments=&6Enchantments: &e%ENCHANTMENT% # Set the potion effect message the player gets after entering '/shop info' if the product has a potion effect -# Usable regex: %POTION-EFFECT% -message.shopInfo.potion-effect=&6Potion Effect: &e%POTION-EFFECT% +# Usable regex: %POTION-EFFECT%, %EXTENDED% +message.shopInfo.potion-effect=&6Potion Effect: &e%POTION-EFFECT% %EXTENDED% # Set the music disc title message the player gets after entering '/shop info' if the product is a music disc # Usable regex: %MUSIC-TITLE% @@ -62,6 +62,10 @@ message.shopInfo.is-normal=&6Type: &eNormal # ... when the shop is an admin shop. message.shopInfo.is-admin=&6Type: &eAdmin +# If the potion effect it extended, %EXTENDED% will be replaced by this. +# If not, this will be empty. +message.shopInfo.extended=(Extended) + # Set the message when the player tries to create a shop with sell price and buy price set to 0 message.buy-and-sell-disabled=&cYou can't create a shop with buying and selling disabled.