From 7828e81ea6b7a57ebe072d6423cb39ebc7d156a2 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 16 Sep 2015 16:45:05 +0200 Subject: [PATCH] Added Blacklist and "In Stock" in Shop Info Message --- config.yml | 28 ++++++++++++++----- plugin.yml | 2 +- src/de/epiceric/shopchest/Commands.java | 21 ++++++++++++-- src/de/epiceric/shopchest/config/Config.java | 9 ++++++ .../shopchest/event/InteractShop.java | 7 +++++ 5 files changed, 56 insertions(+), 11 deletions(-) diff --git a/config.yml b/config.yml index 35a2070..fed8369 100644 --- a/config.yml +++ b/config.yml @@ -55,6 +55,13 @@ minimum-prices: [] # "STONE:1": 0.5 # "DIAMOND_SWORD": 100 +# Set the items of which a player can't create a shop. +# To add an item DELETE THE '[]' after 'blacklist:' and follow format below. +# Important: You must have exactly 2 spaces between the text and edge. +# You can find the item names in the 'item_names.txt' file. +blacklist: [] +# - "STONE:1" +# - "DIAMOND_BLOCK" # Priority: default < group < player shop-limits: @@ -95,30 +102,34 @@ messages: shop-info: - # Set the message the player gets in the first row after entering '/shop info'. + # Set the vendor message the player gets after entering '/shop info'. # Usable regex: %VENDOR% vendor: "&6Vendor: %VENDOR%" - # Set the message the player gets in the second row after entering '/shop info'. + # Set the product message the player gets after entering '/shop info'. # Usable regex: %AMOUNT%, %ITEMNAME% product: "&6Product: %AMOUNT% x %ITEMNAME%" - # Set the message the player gets in the third row after entering '/shop info' if the item is enchanted + # Set the in-stock message the player after entering '/shop info'. + # Usable regex: %AMOUNT% + stock: "&6In Stock: %AMOUNT%" + + # Set the enchantments message the player gets after entering '/shop info' if the item is enchanted # Usable regex: %ENCHANTMENT% enchantments: "&6Enchantments: %ENCHANTMENT%" - # Set the message the player gets in the third/fourth row after entering '/shop info'. + # 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%" # 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" - # Set the message the player gets in the fourth/fifth row after entering '/shop info'... - # ...when the shop is infinite. + # Set the infinite message the player gets after entering '/shop info' ... + # ... when the shop is infinite. is-infinite: "&6Type: Infinite" - # ...when the shop is not infinite. + # ... when the shop is not infinite. is-not-infinite: "&6Type: Normal" # Set the message when the clicked block is not a chest. @@ -216,6 +227,9 @@ messages: # Usable regex: %LIMIT%, %AMOUNT% (Amount of shops) occupied-shop-slots: "&6You have &c%AMOUNT%/%LIMIT% &6shop slot/s occupied." + # Set the message when the player tries to create a shop with an item which is listed in the blacklist. + cannot-sell-item: "&cYou cannot create a shop with this item." + update: # Set the message when an update is available. diff --git a/plugin.yml b/plugin.yml index fece8c4..5884437 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.5.7 +version: 1.6.0-DEVELOPER author: EpicEric website: https://www.spigotmc.org/resources/shopchest.11431/ depend: [Vault] diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index 45b2605..082014d 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -37,8 +37,7 @@ public class Commands extends BukkitCommand { this.plugin = plugin; } - public static void registerCommand(Command command, ShopChest plugin) - throws ReflectiveOperationException { + public static void registerCommand(Command command, ShopChest plugin) throws ReflectiveOperationException { Method commandMap = plugin.getServer().getClass().getMethod("getCommandMap"); Object cmdmap = commandMap.invoke(plugin.getServer()); Method register = cmdmap.getClass().getMethod("register", String.class,Command.class); @@ -238,6 +237,22 @@ public class Commands extends BukkitCommand { return; } + for (String item : Config.blacklist()) { + + ItemStack itemStack; + + if (item.contains(":")) { + itemStack = new ItemStack(Material.getMaterial(item.split(":")[0]), 1, Short.parseShort(item.split(":")[1])); + } else { + itemStack = new ItemStack(Material.getMaterial(item), 1); + } + + if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) { + p.sendMessage(Config.cannot_sell_item()); + return; + } + } + for (String key : Config.minimum_prices()) { ItemStack itemStack; @@ -249,7 +264,7 @@ public class Commands extends BukkitCommand { itemStack = new ItemStack(Material.getMaterial(key), 1); } - if (itemStack.getType().equals(p.getItemInHand().getType())) { + if (itemStack.getType().equals(p.getItemInHand().getType()) && itemStack.getDurability() == p.getItemInHand().getDurability()) { if (buyEnabled) { if ((buyPrice <= amount * price) && (buyPrice > 0)) { p.sendMessage(Config.buyPrice_too_low(amount * price)); diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index c30ba24..51154f8 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -1,6 +1,8 @@ package de.epiceric.shopchest.config; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import de.epiceric.shopchest.ShopChest; @@ -13,6 +15,8 @@ public class Config { public static Set shopLimits_group() {return (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true);} public static Set shopLimits_player() {return (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true);} + public static List blacklist() {return (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist");}; + public static boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");} public static double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");} public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");} @@ -61,6 +65,7 @@ public class Config { public static String checking_update() {return plugin.getConfig().getString("messages.update.checking").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");} 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 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"); @@ -149,4 +154,8 @@ public class Config { public static String occupied_shop_slots(int limit, int amount) { return plugin.getConfig().getString("messages.occupied-shop-slots").replace(Regex.limit, String.valueOf(limit)).replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); } + + public static String shopInfo_stock(int amount) { + return plugin.getConfig().getString("messages.shop-info.stock").replace(Regex.amount, String.valueOf(amount)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); + } } diff --git a/src/de/epiceric/shopchest/event/InteractShop.java b/src/de/epiceric/shopchest/event/InteractShop.java index a59e901..df02214 100644 --- a/src/de/epiceric/shopchest/event/InteractShop.java +++ b/src/de/epiceric/shopchest/event/InteractShop.java @@ -16,6 +16,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.yi.acru.bukkit.Lockette.Lockette; @@ -257,11 +258,16 @@ public class InteractShop implements Listener{ private void info(Player executor, Shop shop) { + Chest c = (Chest) shop.getLocation().getBlock().getState(); + + int amount = Utils.getAmount(c.getInventory(), shop.getProduct().getType(), shop.getProduct().getDurability(), shop.getProduct().getItemMeta()); + String vendor = Config.shopInfo_vendor(shop.getVendor().getName()); String product = Config.shopInfo_product(shop.getProduct().getAmount(), ItemNames.lookup(shop.getProduct())); String enchantmentString = ""; String price = Config.shopInfo_price(shop.getBuyPrice(), shop.getSellPrice()); String infinite = (shop.isInfinite() ? Config.shopInfo_isInfinite() : Config.shopInfo_isNormal()); + String stock = Config.shopInfo_stock(amount); Map enchantmentMap; @@ -289,6 +295,7 @@ public class InteractShop implements Listener{ executor.sendMessage(" "); executor.sendMessage(vendor); executor.sendMessage(product); + executor.sendMessage(stock); if (enchantmentString.length() > 0) executor.sendMessage(Config.shopInfo_enchantment(enchantmentString)); executor.sendMessage(price); executor.sendMessage(infinite);