From 756abaddae2fdbbe3aa03197c2efa751f43bfdeb Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 16 Apr 2016 16:49:45 +0200 Subject: [PATCH] Add 1.9 and missing 1.8 Item Names and support for Tipped Arrows Tipped Arrow Effect will be displayed in the shop info message. A configuration section is also available. --- config.yml | 51 +++++++------ plugin.yml | 2 +- src/de/epiceric/shopchest/config/Config.java | 6 ++ src/de/epiceric/shopchest/config/Regex.java | 1 + .../shopchest/event/InteractShop.java | 11 +++ .../shopchest/utils/ArrowEffectNames.java | 73 +++++++++++++++++++ .../epiceric/shopchest/utils/ItemNames.java | 54 ++++++++++++++ 7 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 src/de/epiceric/shopchest/utils/ArrowEffectNames.java diff --git a/config.yml b/config.yml index 90c3e9a..a74fda6 100644 --- a/config.yml +++ b/config.yml @@ -41,10 +41,10 @@ main-command-name: "shop" # Value MUST be a number (e.g. 1, 1.5, 2.75, ...) maximal-distance: 1.75 -# Set whether the shops' chest should be protected by hoppers +# Set whether the shop's chest should be protected by hoppers hopper-protection: true -# Set whether the shops' chest should be protected by explosions +# Set whether the shop's chest should be protected by explosions explosion-protection: true # Set the currency symbol after price values @@ -110,36 +110,43 @@ messages: # Set the vendor message the player gets after entering '/shop info'. # Usable regex: %VENDOR% - vendor: "&6Vendor: %VENDOR%" + vendor: "&6Vendor: &e%VENDOR%" # Set the product message the player gets after entering '/shop info'. # Usable regex: %AMOUNT%, %ITEMNAME% - product: "&6Product: %AMOUNT% x %ITEMNAME%" + product: "&6Product: &e%AMOUNT% x %ITEMNAME%" # Set the in-stock message the player after entering '/shop info'. # Usable regex: %AMOUNT% - stock: "&6In Stock: %AMOUNT%" + stock: "&6In Stock: &e%AMOUNT%" - # Set the enchantments message the player gets after entering '/shop info' if the item is enchanted + # Set the enchantments message the player gets after entering '/shop info' if the product is enchanted # Usable regex: %ENCHANTMENT% - enchantments: "&6Enchantments: %ENCHANTMENT%" + enchantments: "&6Enchantments: &e%ENCHANTMENT%" + + # Set the arrow effect message the player gets after entering '/shop info' if the product is a tipped arrow (1.9 and later) + # Usable regex: %ARROW-EFFECT% + arrow-effect: "&6Arrow Effect: &e%ARROW-EFFECT%" + + # If the product is a tipped arrow but it doesn't have an effect, this gets displayed instead of the arrow effect + none: "&7None" # Set the price message the player gets after entering '/shop info'. # Usable regex: %BUY-PRICE%, %SELL-PRICE%, %CURRENCY-SYMBOL% - price: "&6Price: Buy: %BUY-PRICE%%CURRENCY-SYMBOL%, Sell: %SELL-PRICE%%CURRENCY-SYMBOL%" + price: "&6Price: Buy: &e%BUY-PRICE%%CURRENCY-SYMBOL%, &6Sell: &e%SELL-PRICE%%CURRENCY-SYMBOL%" # If the sell price or buy price is disabled, this message will be displayed instead of the price and the currency symbol in the message above. - disabled: "&7Disabled&6" + disabled: "&7Disabled&e" # Set the infinite message the player gets after entering '/shop info' ... # ... when the shop is infinite. - is-infinite: "&6Type: Infinite" + is-infinite: "&6Type: &eInfinite" # ... when the shop is normal. - is-normal: "&6Type: Normal" + is-normal: "&6Type: &eNormal" # ... when the shop is an admin shop. - is-admin: "&6Type: Admin" + is-admin: "&6Type: &eAdmin" # Set the message when the clicked block is not a chest. block-no-chest: "&cBlock is not a chest" @@ -163,18 +170,18 @@ messages: # Usable regex: %AMOUNT%, %ITEMNAME%, %SELL-PRICE%, %CURRENCY-SYMBOL% sell-success-admin: "&aYou sold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%%CURRENCY-SYMBOL%&a." - # Set the message when a player bought something from the players' shop. + # Set the message when a player bought something from the player's shop. # Usable regex: %AMOUNT%, %ITEMNAME%, %BUY-PRICE%, %CURRENCY-SYMBOL%, %PLAYER% someone-bought: "&6%PLAYER% &abought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%%CURRENCY-SYMBOL%&a from your shop." - # Set the message when a player sold something to the players' shop. + # Set the message when a player sold something to the player's shop. # Usable regex: %AMOUNT%, %ITEMNAME%, %SELL-PRICE%, %CURRENCY-SYMBOL%, %PLAYER% someone-sold: "&6%PLAYER% &asold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%%CURRENCY-SYMBOL%&a from your shop." # Set the message when the inventory is full when the player is buying something. not-enough-inventory-space: "&cNot enough space in inventory." - # Set the message when the shops' inventory is full when the player is selling something. + # Set the message when the shop's inventory is full when the player is selling something. chest-not-enough-inventory-space: "&cShop is full." # Set the message when the player doesn't have enough money to buy something. @@ -236,7 +243,7 @@ messages: # Usable regex: %AMOUNT% (Amount of shops) reloaded-shops: "&aSuccessfully reloaded %AMOUNT% shop/s." - # Set the message when the players' shop limit is reached. + # Set the message when the player's shop limit is reached. # Usable regex: %LIMIT% shop-limit-reached: "&cYou reached your limit of &6%LIMIT% &cshop/s." @@ -264,19 +271,19 @@ messages: hologram: - # Set the text in the first row of the shops' hologram + # Set the text in the first row of the shop's hologram # Usable regex: %ITEMNAME%, %AMOUNT% format: "%AMOUNT% * %ITEMNAME%" - # Set the text in the second row of the shops' hologram when the player can buy and sell an item. + # Set the text in the second row of the shop's hologram when the player can buy and sell an item. # Usable regex: %BUY-PRICE%, %SELL-PRICE%, %CURRENCY-SYMBOL% buy-and-sell: "Buy %BUY-PRICE%%CURRENCY-SYMBOL% | %SELL-PRICE%%CURRENCY-SYMBOL% Sell" - # Set the text in the second row of the shops' hologram when the player can only buy an item. + # Set the text in the second row of the shop's hologram when the player can only buy an item. # Usable regex: %BUY-PRICE%, %CURRENCY-SYMBOL% only-buy: "Buy %BUY-PRICE%%CURRENCY-SYMBOL%" - # Set the text in the second row of the shops' hologram when the player can only sell an item. + # Set the text in the second row of the shop's hologram when the player can only sell an item. # Usable regex: %SELL-PRICE%, %CURRENCY-SYMBOL% only-sell: "Sell %SELL-PRICE%%CURRENCY-SYMBOL%" @@ -291,7 +298,7 @@ messages: # Set the message when a not permitted player tries to create an admin shop. create-admin: "&cYou don't have permission to create an admin shop." - # Set the message when a not permitted player tries to open another players' shop. + # Set the message when a not permitted player tries to open another player's shop. open-others: "&cYou don't have permission to open this chest." # Set the message when a not permitted player tries to buy something. @@ -300,7 +307,7 @@ messages: # Set the message when a not permitted player tries to sell something. sell: "&cYou don't have permission to sell something." - # Set the message when a not permitted player tries to remove another players' shop. + # Set the message when a not permitted player tries to remove another player's shop. remove-others: "&cYou don't have permission to remove this shop." # Set the message when a not permitted player tries to reload the shops. diff --git a/plugin.yml b/plugin.yml index e72f4f5..55a113a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.7.1.1 +version: 1.7.2 author: EpicEric website: https://www.spigotmc.org/resources/shopchest.11431/ depend: [Vault] diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index 98aca99..444e13c 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -71,6 +71,8 @@ public class Config { public static String no_new_update() {return plugin.getConfig().getString("messages.update.no-update").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String click_to_download() {return plugin.getConfig().getString("messages.update.click-to-download").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} public static String cannot_sell_item() {return plugin.getConfig().getString("messages.cannot-sell-item").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} + public static String none() {return plugin.getConfig().getString("messages.shop-info.none").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} + public static String limit_reached(int limit) { return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); @@ -128,6 +130,10 @@ public class Config { return plugin.getConfig().getString("messages.shop-info.enchantments").replace(Regex.enchantment, enchantment).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); } + public static String shopInfo_arrowEffect(String arrowEffect) { + return plugin.getConfig().getString("messages.shop-info.arrow-effect").replace(Regex.arrowEffect, arrowEffect).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); + } + public static String shopInfo_price(double buyPrice, double sellPrice) { if ((buyPrice <= 0) && (sellPrice > 0)) { return plugin.getConfig().getString("messages.shop-info.price").replace(Regex.currencySymbol, currency_symbol()).replace(Regex.buyPrice + currency_symbol(), disabled()).replace(Regex.sellPrice, String.valueOf(sellPrice)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); diff --git a/src/de/epiceric/shopchest/config/Regex.java b/src/de/epiceric/shopchest/config/Regex.java index fa91133..9d84054 100644 --- a/src/de/epiceric/shopchest/config/Regex.java +++ b/src/de/epiceric/shopchest/config/Regex.java @@ -15,5 +15,6 @@ public class Regex { public static String sellPrice = "%SELL-PRICE%"; public static String limit = "%LIMIT%"; public static String player = "%PLAYER%"; + public static String arrowEffect = "%ARROW-EFFECT%"; } diff --git a/src/de/epiceric/shopchest/event/InteractShop.java b/src/de/epiceric/shopchest/event/InteractShop.java index c93729c..b1d0976 100644 --- a/src/de/epiceric/shopchest/event/InteractShop.java +++ b/src/de/epiceric/shopchest/event/InteractShop.java @@ -18,6 +18,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.PotionMeta; import org.yi.acru.bukkit.Lockette.Lockette; import com.griefcraft.model.Protection; @@ -27,6 +28,7 @@ import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.sql.SQLite; +import de.epiceric.shopchest.utils.ArrowEffectNames; import de.epiceric.shopchest.utils.ClickType; import de.epiceric.shopchest.utils.EnchantmentNames; import de.epiceric.shopchest.utils.ItemNames; @@ -263,6 +265,7 @@ public class InteractShop implements Listener{ String vendor = Config.shopInfo_vendor(shop.getVendor().getName()); String product = Config.shopInfo_product(shop.getProduct().getAmount(), ItemNames.lookup(shop.getProduct())); String enchantmentString = ""; + String arrowEffectString = ""; String price = Config.shopInfo_price(shop.getBuyPrice(), shop.getSellPrice()); String shopType; String stock = Config.shopInfo_stock(amount); @@ -273,6 +276,13 @@ public class InteractShop implements Listener{ Map enchantmentMap; + if (Utils.getVersion(Bukkit.getServer()).contains("1_9")) { + if (shop.getProduct().getType() == Material.TIPPED_ARROW) { + arrowEffectString = ArrowEffectNames.getTippedArrowName(shop.getProduct()); + if (arrowEffectString == null) arrowEffectString = Config.none(); + } + } + if (shop.getProduct().getItemMeta() instanceof EnchantmentStorageMeta) { EnchantmentStorageMeta esm = (EnchantmentStorageMeta) shop.getProduct().getItemMeta(); enchantmentMap = esm.getStoredEnchants(); @@ -299,6 +309,7 @@ public class InteractShop implements Listener{ executor.sendMessage(product); executor.sendMessage(stock); if (enchantmentString.length() > 0) executor.sendMessage(Config.shopInfo_enchantment(enchantmentString)); + if (arrowEffectString.length() > 0) executor.sendMessage(Config.shopInfo_arrowEffect(arrowEffectString)); executor.sendMessage(price); executor.sendMessage(shopType); executor.sendMessage(" "); diff --git a/src/de/epiceric/shopchest/utils/ArrowEffectNames.java b/src/de/epiceric/shopchest/utils/ArrowEffectNames.java new file mode 100644 index 0000000..92cf389 --- /dev/null +++ b/src/de/epiceric/shopchest/utils/ArrowEffectNames.java @@ -0,0 +1,73 @@ +package de.epiceric.shopchest.utils; + +import java.util.Map; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; + +import com.google.common.collect.ImmutableMap; + +public class ArrowEffectNames { + + private static final Map effectMap = ImmutableMap.builder() + .put("FIRE_RESISTANCE", "Fire Resistance") + .put("INSTANT_DAMAGE", "Instant Damage") + .put("INSTANT_HEAL", "Instant Health") + .put("INVISIBILITY", "Invisibility") + .put("JUMP", "Jump Boost") + .put("LUCK", "Luck") + .put("NIGHT_VISION", "Night Vision") + .put("POISION", "Poison") + .put("REGEN", "Regeneration") + .put("SLOWNESS", "Slowness") + .put("SPEED", "Speed") + .put("STRENGTH", "Strength") + .put("WATER_BREATHING", "Water Breathing") + .put("WEAKNESS", "Weakness") + .build(); + + + public static String getTippedArrowName(ItemStack itemStack) { + + if (!(itemStack.getItemMeta() instanceof PotionMeta)){ + return null; + } + + String name; + + PotionMeta meta = (PotionMeta) itemStack.getItemMeta(); + + name = effectMap.get(meta.getBasePotionData().getType().toString()); + + if (meta.getBasePotionData().isUpgraded()){ + name += " II"; + switch (meta.getBasePotionData().getType()) { + case JUMP: name += " (0:11)"; break; + case SPEED: name += " (0:11)"; break; + case POISON: name += " (0:02)"; break; + case REGEN: name += " (0:02)"; break; + case STRENGTH: name += " (0:11)"; break; + default: break; + } + } else { + switch (meta.getBasePotionData().getType()) { + case FIRE_RESISTANCE: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case INVISIBILITY: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case JUMP: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case LUCK: name += " (0:37)"; break; + case NIGHT_VISION: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case POISON: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; + case REGEN: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:11" : "0:05") + ")"; break; + case SLOWNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; + case SPEED: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case STRENGTH: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case WATER_BREATHING: name += " (" + ((meta.getBasePotionData().isExtended()) ? "1:00" : "0:22") + ")"; break; + case WEAKNESS: name += " (" + ((meta.getBasePotionData().isExtended()) ? "0:30" : "0:11") + ")"; break; + default: break; + } + } + + return name; + } + +} diff --git a/src/de/epiceric/shopchest/utils/ItemNames.java b/src/de/epiceric/shopchest/utils/ItemNames.java index 37ab444..f14d79e 100644 --- a/src/de/epiceric/shopchest/utils/ItemNames.java +++ b/src/de/epiceric/shopchest/utils/ItemNames.java @@ -283,6 +283,36 @@ public class ItemNames { .put("175:3", "Large Fern") .put("175:4", "Rose Bush") .put("175:5", "Peony") + .put("178", "Daylight Sensor (inverted)") + .put("179", "Red Sandstone") + .put("179:1", "Chiseled Red Sandstone") + .put("179:2", "Smooth Red Sandstone") + .put("180", "Red Sandstone Stairs") + .put("182", "Red Sandstone Slab") + .put("183", "Spruce Fence Gate") + .put("184", "Birch Fence Gate") + .put("185", "Jungle Fence Gate") + .put("186", "Dark Oak Fence Gate") + .put("187", "Acacia Fence Gate") + .put("188", "Spruce Fence") + .put("189", "Birch Fence") + .put("190", "Jungle Fence") + .put("191", "Dark Oak Fence") + .put("192", "Acacia Fence") + .put("198", "End Rod") + .put("199", "Chorus Plant") + .put("200", "Chorus Flower") + .put("201", "Purpur Block") + .put("202", "Purpur Pillar") + .put("203", "Purpur Stairs") + .put("205", "Purpur Slab") + .put("206", "End Stone Bricks") + .put("208", "Grass Path") + .put("209", "End Gateway") + .put("210", "Repeating Command Block") + .put("211", "Chain Command Block") + .put("212", "Frosted Ice") + .put("255", "Structure Block") .put("256", "Iron Shovel") .put("257", "Iron Pickaxe") .put("258", "Iron Axe") @@ -565,6 +595,30 @@ public class ItemNames { .put("422", "Minecart with Command Block") .put("423", "Raw Mutton") .put("424", "Cooked Mutton") + .put("425", "Banner") + .put("426", "End Crystal") + .put("427", "Spruce Door") + .put("428", "Birch Door") + .put("429", "Jungle Door") + .put("430", "Acacia Door") + .put("431", "Dark Oak Door") + .put("432", "Chorus Fruit") + .put("433", "Popped Chorus Fruit") + .put("434", "Beetroot") + .put("435", "Beetroot Seeds") + .put("436", "Beetroot Soup") + .put("437", "Dragon Breath") + .put("438", "Splash Potion") + .put("439", "Spectral Arrow") + .put("440", "Tipped Arrow") + .put("441", "Lingering Potion") + .put("442", "Shield") + .put("443", "Elytra") + .put("444", "Spruce Boat") + .put("445", "Birch Boat") + .put("446", "Jungle Boat") + .put("447", "Acacia Boat") + .put("448", "Dark Oak Boat") .put("2256", "Music Disk (13)") .put("2257", "Music Disk (Cat)") .put("2258", "Music Disk (Blocks)")