From f807c054d46b46e0f4da3e485d9389289a8bb7bc Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 16 Oct 2015 16:02:48 +0800 Subject: [PATCH] add config usemagiclib... Signed-off-by: 502647092 --- .../QuickShop/Config/ConfigManager.java | 25 ++++- .../org/maxgamer/QuickShop/QuickShop.java | 24 ----- .../org/maxgamer/QuickShop/Util/MsgUtil.java | 2 +- src/main/resources/config.yml | 2 + src/main/resources/plugin.yml | 99 ++++++++++--------- 5 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java index bf71a14..7f4608a 100644 --- a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java @@ -5,11 +5,14 @@ import java.util.HashSet; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.inventory.ItemStack; import org.maxgamer.QuickShop.QuickShop; import cn.citycraft.PluginHelper.config.FileConfig; +import mkremins.fanciful.FancyMessage; public class ConfigManager { + private boolean enableMagicLib; /** Whether debug info should be shown in the console */ protected boolean debug = false; /** Whether we should use display items or not */ @@ -17,9 +20,9 @@ public class ConfigManager { protected double feeForPriceChange = 0.0; protected int findDistance = 30; protected String guiTitle = "§6[§b快捷商店§6]"; + /** 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; @@ -77,6 +80,22 @@ public class ConfigManager { this.feeForPriceChange = config.getDouble("shop.fee-for-price-change"); this.preventhopper = config.getBoolean("preventhopper"); this.guiTitle = config.getMessage("guititle"); + try { + plugin.getLogger().info("尝试启动魔改库..."); + final FancyMessage fm = new FancyMessage("test"); + fm.then("item").itemTooltip(new ItemStack(Material.DIAMOND_SWORD)); + fm.then("link").link("ci.citycraft.cn"); + fm.then("suggest").suggest("qs help"); + fm.toJSONString(); + plugin.getLogger().info("魔改库功能测试正常..."); + this.enableMagicLib = true; + } catch (final NoClassDefFoundError | NoSuchMethodError | Exception e) { + plugin.getLogger().warning("+========================================="); + plugin.getLogger().warning("| 警告: 启动魔改库失败 将使用GUI界面..."); + plugin.getLogger().warning("+========================================="); + this.enableMagicLib = false; + } + this.enableMagicLib = enableMagicLib && config.getBoolean("usemagiclib", true); } public double getFeeForPriceChange() { @@ -123,6 +142,10 @@ public class ConfigManager { return display; } + public boolean isEnableMagicLib() { + return enableMagicLib; + } + public boolean isLimit() { return limit; } diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index a4e6de7..7100644 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -14,7 +14,6 @@ import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -54,7 +53,6 @@ import org.mcstats.Metrics; import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; -import mkremins.fanciful.FancyMessage; public class QuickShop extends JavaPlugin { /** The active instance of QuickShop */ @@ -74,7 +72,6 @@ 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; @@ -144,10 +141,6 @@ 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. @@ -226,23 +219,6 @@ public class QuickShop extends JavaPlugin { final LockListener ll = new LockListener(this); getServer().getPluginManager().registerEvents(ll, this); } - - try { - getLogger().info("尝试启动魔改库..."); - final FancyMessage fm = new FancyMessage("test"); - fm.then("item").itemTooltip(new ItemStack(Material.DIAMOND_SWORD)); - fm.then("link").link("ci.citycraft.cn"); - 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("+========================================="); - this.enableMagicLib = false; - } - try { final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database"); DatabaseCore dbCore; diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java index f20a962..15b647b 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java @@ -193,7 +193,7 @@ public class MsgUtil { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.this-shop-is-selling")); } p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); - if (!plugin.isEnableMagicLib()) { + if (!plugin.getConfigManager().isEnableMagicLib()) { final Inventory in = Bukkit.createInventory(null, 9, plugin.getConfigManager().getGuiTitle()); in.setItem(4, items); p.openInventory(in); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7230179..0ec7dac 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,6 +6,8 @@ superitem: GOLD_AXE preventhopper: false #商店GUI的标题 guititle: '&6[&b快捷商店&6]&r' +#启用魔改库支持 +usemagiclib: true #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 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9f8bad1..231883f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,53 +2,58 @@ name: ${project.artifactId} description: ${project.description} main: ${project.groupId}.${project.artifactId}.${project.artifactId} version: ${project.version} -authors: [Netherfoam,Timtower, KaiNoMood,喵♂呜] -softdepend: [Vault] +authors: +- Netherfoam +- Timtower +- KaiNoMood +- 喵♂呜 +softdepend: +- Vault website: http://ci.sumcraft.net:8080/job/${project.artifactId}/ - commands: - qs: - description: QuickShop command - usage: '§c未知的子命令 请输入 §b/qs help §c查看帮助!' - aliases: [quickshop,shop] - + qs: + description: QuickShop command + usage: §c未知的子命令 请输入 §b/qs help §c查看帮助! + aliases: + - quickshop + - shop permissions: - quickshop.create.sell: - description: Allows a player to sell from a shop - default: op - quickshop.create.buy: - description: Allows a player to buy from a shop - default: op - quickshop.create.double: - description: Allows a player to create a double shop - default: op - quickshop.use: - description: Allows a player to buy/sell using other players shops - default: true - quickshop.unlimited: - description: Allows a Staff Member to use /qs unlimited and make a shop infinite - quickshop.bypass.: - description: Allows a player to sell , even if its blacklisted - quickshop.other.destroy: - description: Allows a Staff Member to destroy other players shops if they are locked in the config - quickshop.other.open: - description: Allows a Staff Member to open someone elses shop if they are locked in the config - quickshop.other.price: - description: Allows a Staff Member to change the price of someone elses shop - quickshop.setowner: - description: Allows a Staff Member to change the owner of any shop - quickshop.find: - description: Allows a player to locate the nearest shop of a specific item type. Works in a 3 chunk radius. - default: true - quickshop.refill: - description: Allows a Staff Member to refill the shop theyre looking at with the given number of items. - default: op - quickshop.empty: - description: Allows a Staff Member to empty the shop theyre looking at of all items. - default: op - quickshop.debug: - description: Enables debug info to console - default: op - quickshop.export: - description: Allows exporting database to mysql or sqlite - default: op \ No newline at end of file + quickshop.create.sell: + description: Allows a player to sell from a shop + default: op + quickshop.create.buy: + description: Allows a player to buy from a shop + default: op + quickshop.create.double: + description: Allows a player to create a double shop + default: op + quickshop.use: + description: Allows a player to buy/sell using other players shops + default: true + quickshop.unlimited: + description: Allows a Staff Member to use /qs unlimited and make a shop infinite + quickshop.bypass.: + description: Allows a player to sell , even if its blacklisted + quickshop.other.destroy: + description: Allows a Staff Member to destroy other players shops if they are locked in the config + quickshop.other.open: + description: Allows a Staff Member to open someone elses shop if they are locked in the config + quickshop.other.price: + description: Allows a Staff Member to change the price of someone elses shop + quickshop.setowner: + description: Allows a Staff Member to change the owner of any shop + quickshop.find: + description: Allows a player to locate the nearest shop of a specific item type. Works in a 3 chunk radius. + default: true + quickshop.refill: + description: Allows a Staff Member to refill the shop theyre looking at with the given number of items. + default: op + quickshop.empty: + description: Allows a Staff Member to empty the shop theyre looking at of all items. + default: op + quickshop.debug: + description: Enables debug info to console + default: op + quickshop.export: + description: Allows exporting database to mysql or sqlite + default: op \ No newline at end of file