From 40e4922acdf03a4ba7dbacff2b11e17f808e1ca8 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Thu, 15 Oct 2015 19:04:15 +0800 Subject: [PATCH] add new show item Handler... Signed-off-by: 502647092 --- .../QuickShop/Config/ConfigManager.java | 43 +++++++++++-------- .../QuickShop/Listeners/ProtectListener.java | 5 +++ .../org/maxgamer/QuickShop/QuickShop.java | 14 ++++-- .../maxgamer/QuickShop/Shop/DisplayItem.java | 6 +-- .../org/maxgamer/QuickShop/Util/MsgUtil.java | 6 +++ src/main/resources/config.yml | 2 + 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java index 0d832a5..343f04c 100644 --- a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java @@ -7,6 +7,8 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.maxgamer.QuickShop.QuickShop; +import cn.citycraft.PluginHelper.config.FileConfig; + public class ConfigManager { /** Whether debug info should be shown in the console */ protected boolean debug = false; @@ -14,8 +16,10 @@ public class ConfigManager { protected boolean display = true; protected double feeForPriceChange = 0.0; protected int findDistance = 30; + protected String guiTitle; /** Whether or not to limit players shop amounts */ protected boolean limit = false; + protected int limitdefault = 0; protected final HashMap limits = new HashMap(); protected boolean logAction = true; @@ -45,33 +49,34 @@ public class ConfigManager { protected HashSet warnings = new HashSet(); public ConfigManager(final QuickShop plugin) { - - ConfigurationSection limitCfg = plugin.getConfig().getConfigurationSection("limits"); + final FileConfig config = (FileConfig) plugin.getConfig(); + ConfigurationSection limitCfg = config.getConfigurationSection("limits"); if (limitCfg != null) { this.limit = limitCfg.getBoolean("use", false); - this.limitdefault = plugin.getConfig().getInt("limits.default"); + this.limitdefault = config.getInt("limits.default"); limitCfg = limitCfg.getConfigurationSection("ranks"); for (final String key : limitCfg.getKeys(true)) { limits.put(key, limitCfg.getInt(key)); } } try { - this.superItem = Enum.valueOf(Material.class, plugin.getConfig().getString("superitem")); + this.superItem = Enum.valueOf(Material.class, config.getString("superitem")); } catch (final Exception e) { } - this.tax = plugin.getConfig().getDouble("tax"); - this.showTax = plugin.getConfig().getBoolean("show-tax"); - this.taxAccount = plugin.getConfig().getString("tax-account"); - this.logAction = plugin.getConfig().getBoolean("log-actions"); - this.shopLock = plugin.getConfig().getBoolean("shop.lock"); - this.display = plugin.getConfig().getBoolean("shop.display-items"); - this.sneak = plugin.getConfig().getBoolean("shop.sneak-only"); - this.sneakCreate = plugin.getConfig().getBoolean("shop.sneak-to-create"); - this.sneakTrade = plugin.getConfig().getBoolean("shop.sneak-to-trade"); - this.priceChangeRequiresFee = plugin.getConfig().getBoolean("shop.price-change-requires-fee"); - this.findDistance = plugin.getConfig().getInt("shop.find-distance"); - this.feeForPriceChange = plugin.getConfig().getDouble("shop.fee-for-price-change"); - this.preventhopper = plugin.getConfig().getBoolean("preventhopper"); + this.tax = config.getDouble("tax"); + this.showTax = config.getBoolean("show-tax"); + this.taxAccount = config.getString("tax-account"); + this.logAction = config.getBoolean("log-actions"); + this.shopLock = config.getBoolean("shop.lock"); + this.display = config.getBoolean("shop.display-items"); + this.sneak = config.getBoolean("shop.sneak-only"); + this.sneakCreate = config.getBoolean("shop.sneak-to-create"); + this.sneakTrade = config.getBoolean("shop.sneak-to-trade"); + this.priceChangeRequiresFee = config.getBoolean("shop.price-change-requires-fee"); + this.findDistance = config.getInt("shop.find-distance"); + this.feeForPriceChange = config.getDouble("shop.fee-for-price-change"); + this.preventhopper = config.getBoolean("preventhopper"); + this.guiTitle = config.getMessage("guititle"); } public double getFeeForPriceChange() { @@ -82,6 +87,10 @@ public class ConfigManager { return findDistance; } + public String getGuiTitle() { + return guiTitle; + } + public int getLimitdefault() { return limitdefault; } diff --git a/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java b/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java index d1b4146..7684ca8 100644 --- a/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java +++ b/src/main/java/org/maxgamer/QuickShop/Listeners/ProtectListener.java @@ -59,12 +59,17 @@ public class ProtectListener implements Listener { final Inventory inv = e.getInventory(); final int solt = e.getSlot(); if (inv.getType() != InventoryType.PLAYER && inv.getType() != InventoryType.HOPPER) { + if (inv.getTitle().equalsIgnoreCase(plugin.getConfigManager().getGuiTitle())) { + e.setCancelled(true); + p.closeInventory(); + } return; } try { if (MarkUtil.hasMark(ci)) { inv.setItem(solt, new ItemStack(Material.AIR)); Bukkit.broadcastMessage("§6[§b快捷商店§6] §4警告 " + p.getDisplayName() + " §c非法 §d§l获取 " + ci.getItemMeta().getDisplayName() + " §a已清理..."); + p.closeInventory(); } } catch (final Exception ex) { } diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index 8b614e9..a4e6de7 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -74,7 +74,9 @@ public class QuickShop extends JavaPlugin { private Database database; /** The economy we hook into for transactions */ private Economy economy; + private boolean enableMagicLib; private BukkitTask itemWatcherTask; + private LogWatcher logWatcher; private final PlayerListener playerListener = new PlayerListener(this); private final ProtectListener protectListener = new ProtectListener(this); @@ -142,6 +144,10 @@ public class QuickShop extends JavaPlugin { return this.shopManager; } + public boolean isEnableMagicLib() { + return enableMagicLib; + } + /** * Tries to load the economy and its core. If this fails, it will try to use * vault. If that fails, it will return false. @@ -229,10 +235,12 @@ public class QuickShop extends JavaPlugin { fm.then("suggest").suggest("qs help"); fm.toJSONString(); getLogger().info("魔改库功能测试正常..."); + this.enableMagicLib = true; } catch (final NoClassDefFoundError | NoSuchMethodError | Exception e) { - getLogger().warning("========================================"); - getLogger().warning("警告: 启动魔改库失败 部分功能将被禁用..."); - getLogger().warning("========================================"); + getLogger().warning("+========================================="); + getLogger().warning("| 警告: 启动魔改库失败 部分功能将被禁用..."); + getLogger().warning("+========================================="); + this.enableMagicLib = false; } try { diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java index c95a079..d36cecc 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java @@ -65,8 +65,6 @@ public class DisplayItem { if (shop.getLocation().getWorld() == null) { return false; } - // QuickShop qs = (QuickShop) - // Bukkit.getPluginManager().getPlugin("QuickShop"); final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation(); boolean removed = false; final Chunk c = displayLoc.getChunk(); @@ -95,9 +93,7 @@ public class DisplayItem { */ public void respawn() { remove(); - if (item.isValid()) { - spawn(); - } + spawn(); } /** diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java index 584b9b6..f20a962 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java @@ -9,6 +9,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.Shop; @@ -192,5 +193,10 @@ public class MsgUtil { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling")); } p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); + if (!plugin.isEnableMagicLib()) { + final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle()); + in.setItem(4, items); + p.openInventory(in); + } } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9c0d68f..7230179 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,8 @@ Version: 1.1 superitem: GOLD_AXE #阻止漏斗吸取商店物品(非特殊情况不要开启) preventhopper: false +#商店GUI的标题 +guititle: '&6[&b快捷商店&6]&r' #Tax amount (decimal) - Eg, P1 buys $50 worth of stuff from P2. Therefore, P1 loses $50, P2 gains $(1-0.05)*50, and tax-account gains $(0.05)*50. tax: 0.00