From af5e41a8a34e192a10a80b93286a662b4434bb9d Mon Sep 17 00:00:00 2001 From: j502647092 Date: Tue, 6 Oct 2015 00:58:06 +0800 Subject: [PATCH] add config manager and fix some bug... Signed-off-by: j502647092 --- pom.xml | 2 +- .../org/maxgamer/QuickShop/Command/QS.java | 12 +- .../QuickShop/Config/ConfigManager.java | 134 ++++++++++++++++++ .../maxgamer/QuickShop/Config/ItemConfig.java | 4 + .../QuickShop/Listeners/BlockListener.java | 19 +-- .../QuickShop/Listeners/PlayerListener.java | 19 +-- .../org/maxgamer/QuickShop/QuickShop.java | 109 +++++--------- .../QuickShop/Shop/ContainerShop.java | 6 +- .../maxgamer/QuickShop/Shop/DisplayItem.java | 7 - .../maxgamer/QuickShop/Shop/ShopManager.java | 10 +- .../org/maxgamer/QuickShop/Util/MarkUtil.java | 5 +- .../org/maxgamer/QuickShop/Util/MsgUtil.java | 10 +- .../java/org/maxgamer/QuickShop/Util/NMS.java | 10 -- .../org/maxgamer/QuickShop/Util/Util.java | 39 ++--- src/main/resources/config.yml | 5 + src/main/resources/item.yml | 43 +++--- 16 files changed, 264 insertions(+), 170 deletions(-) create mode 100644 src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java diff --git a/pom.xml b/pom.xml index c79349d..af24ada 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.maxgamer QuickShop - 1.0 + 1.1 ${project.name} diff --git a/src/main/java/org/maxgamer/QuickShop/Command/QS.java b/src/main/java/org/maxgamer/QuickShop/Command/QS.java index ab635b3..355f656 100644 --- a/src/main/java/org/maxgamer/QuickShop/Command/QS.java +++ b/src/main/java/org/maxgamer/QuickShop/Command/QS.java @@ -406,7 +406,7 @@ public class QS implements CommandExecutor { final Block b = bIt.next(); final Shop shop = plugin.getShopManager().getShop(b.getLocation()); if (shop != null) { - if (shop.getOwner().equals(p.getUniqueId())) { + if (shop.getOwner().equals(p.getName())) { shop.delete(); sender.sendMessage(ChatColor.GREEN + "Success. Deleted shop."); } else { @@ -424,7 +424,7 @@ public class QS implements CommandExecutor { while (bIt.hasNext()) { final Block b = bIt.next(); final Shop shop = plugin.getShopManager().getShop(b.getLocation()); - if (shop != null && shop.getOwner().equals(((Player) sender).getUniqueId())) { + if (shop != null && shop.getOwner().equals(((Player) sender).getName())) { shop.setShopType(ShopType.BUYING); shop.setSignText(); shop.update(); @@ -486,9 +486,9 @@ public class QS implements CommandExecutor { return; } double fee = 0; - if (plugin.priceChangeRequiresFee) { - fee = plugin.getConfig().getDouble("shop.fee-for-price-change"); - if (fee > 0 && plugin.getEcon().getBalance(p.getUniqueId()) < fee) { + if (plugin.getConfigManager().isPriceChangeRequiresFee()) { + fee = plugin.getConfigManager().getFeeForPriceChange(); + if (fee > 0 && plugin.getEcon().getBalance(p.getName()) < fee) { sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee))); return; } @@ -505,7 +505,7 @@ public class QS implements CommandExecutor { return; } if (fee > 0) { - if (!plugin.getEcon().withdraw(p.getUniqueId(), fee)) { + if (!plugin.getEcon().withdraw(p.getName(), fee)) { sender.sendMessage(MsgUtil.p("you-cant-afford-to-change-price", plugin.getEcon().format(fee))); return; } diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java new file mode 100644 index 0000000..2b9f96c --- /dev/null +++ b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java @@ -0,0 +1,134 @@ +package org.maxgamer.QuickShop.Config; + +import java.util.HashMap; +import java.util.HashSet; + +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.maxgamer.QuickShop.QuickShop; + +public class ConfigManager { + /** Whether debug info should be shown in the console */ + protected boolean debug = false; + /** + * A set of players who have been warned + * ("Your shop isn't automatically locked") + */ + protected HashSet warnings = new HashSet(); + /** Whether players are required to sneak to create/buy from a shop */ + protected boolean sneak; + /** Whether players are required to sneak to create a shop */ + protected boolean sneakCreate; + /** Whether players are required to sneak to trade with a shop */ + protected boolean sneakTrade; + /** Whether we should use display items or not */ + protected boolean display = true; + /** + * Whether we players are charged a fee to change the price on their shop + * (To help deter endless undercutting + */ + protected boolean priceChangeRequiresFee = false; + /** 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; + protected boolean shopLock = true; + protected int findDistance = 30; + protected Material superItem = Material.GOLD_AXE; + protected double feeForPriceChange = 0.0; + + /** Use SpoutPlugin to get item / block names */ + protected boolean useSpout = false; + + public ConfigManager(final QuickShop plugin) { + + ConfigurationSection limitCfg = plugin.getConfig().getConfigurationSection("limits"); + if (limitCfg != null) { + this.limit = limitCfg.getBoolean("use", false); + this.limitdefault = plugin.getConfig().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")); + } catch (final Exception e) { + } + 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"); + } + + public double getFeeForPriceChange() { + return feeForPriceChange; + } + + public int getFindDistance() { + return findDistance; + } + + public int getLimitdefault() { + return limitdefault; + } + + public HashMap getLimits() { + return limits; + } + + public Material getSuperItem() { + return superItem; + } + + public HashSet getWarnings() { + return warnings; + } + + public boolean isDebug() { + return debug; + } + + public boolean isDisplay() { + return display; + } + + public boolean isLimit() { + return limit; + } + + public boolean isLogAction() { + return logAction; + } + + public boolean isPriceChangeRequiresFee() { + return priceChangeRequiresFee; + } + + public boolean isShopLock() { + return shopLock; + } + + public boolean isSneak() { + return sneak; + } + + public boolean isSneakCreate() { + return sneakCreate; + } + + public boolean isSneakTrade() { + return sneakTrade; + } + + public boolean isUseSpout() { + return useSpout; + } + +} diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ItemConfig.java b/src/main/java/org/maxgamer/QuickShop/Config/ItemConfig.java index 15b26c7..d10983e 100644 --- a/src/main/java/org/maxgamer/QuickShop/Config/ItemConfig.java +++ b/src/main/java/org/maxgamer/QuickShop/Config/ItemConfig.java @@ -37,4 +37,8 @@ public class ItemConfig { config = new FileConfig(p, CONFIG_NAME); } + public static void reload() { + config.reload(); + } + } diff --git a/src/main/java/org/maxgamer/QuickShop/Listeners/BlockListener.java b/src/main/java/org/maxgamer/QuickShop/Listeners/BlockListener.java index f00750a..34198d8 100644 --- a/src/main/java/org/maxgamer/QuickShop/Listeners/BlockListener.java +++ b/src/main/java/org/maxgamer/QuickShop/Listeners/BlockListener.java @@ -14,6 +14,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.Info; import org.maxgamer.QuickShop.Shop.Shop; @@ -42,18 +43,20 @@ public class BlockListener implements Listener { return; } // If they're either survival or the owner, they can break it - if (p.getGameMode() == GameMode.CREATIVE && !p.getUniqueId().equals(shop.getOwner())) { + final ItemStack pinh = p.getItemInHand(); + if (p.getName().equals(shop.getOwner()) || (pinh != null && pinh.getType() == plugin.getConfigManager().getSuperItem()) || (p.getGameMode() == GameMode.SURVIVAL)) { + // Cancel their current menu... Doesnt cancel other's menu's. + final Info action = plugin.getShopManager().getActions().get(p.getName()); + if (action != null) { + action.setAction(ShopAction.CANCELLED); + } + shop.delete(); + p.sendMessage(MsgUtil.p("success-removed-shop")); + } else { e.setCancelled(true); p.sendMessage(MsgUtil.p("no-creative-break")); return; } - // Cancel their current menu... Doesnt cancel other's menu's. - final Info action = plugin.getShopManager().getActions().get(p.getName()); - if (action != null) { - action.setAction(ShopAction.CANCELLED); - } - shop.delete(); - p.sendMessage(MsgUtil.p("success-removed-shop")); } else if (b.getType() == Material.WALL_SIGN) { final Shop shop = getShopNextTo(b.getLocation()); if (shop == null) { diff --git a/src/main/java/org/maxgamer/QuickShop/Listeners/PlayerListener.java b/src/main/java/org/maxgamer/QuickShop/Listeners/PlayerListener.java index ba67e81..ba9529c 100644 --- a/src/main/java/org/maxgamer/QuickShop/Listeners/PlayerListener.java +++ b/src/main/java/org/maxgamer/QuickShop/Listeners/PlayerListener.java @@ -13,7 +13,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -53,7 +52,7 @@ public class PlayerListener implements Listener { return; } final Player p = e.getPlayer(); - if (plugin.sneak && !p.isSneaking()) { + if (plugin.getConfigManager().isSneak() != p.isSneaking()) { // Sneak only return; } @@ -69,7 +68,7 @@ public class PlayerListener implements Listener { } } // Purchase handling - if (shop != null && p.hasPermission("quickshop.use") && (plugin.sneakTrade == false || p.isSneaking())) { + if (shop != null && p.hasPermission("quickshop.use") && (plugin.getConfigManager().isSneakTrade() == p.isSneaking())) { shop.onClick(); // Text menu MsgUtil.sendShopInfo(p, shop); @@ -86,8 +85,8 @@ public class PlayerListener implements Listener { return; } // Handles creating shops - else if (!e.isCancelled() && shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) - && p.getGameMode() != GameMode.CREATIVE && (plugin.sneakCreate == false || p.isSneaking())) { + else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE + && (plugin.getConfigManager().isSneakCreate() == p.isSneaking())) { if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) { // As of the new checking system, most plugins will tell the // player why they can't create a shop there. @@ -131,20 +130,12 @@ public class PlayerListener implements Listener { try { if (MarkUtil.hasMark(ci)) { inv.setItem(solt, new ItemStack(Material.AIR)); - p.chat("§c非法获取快捷商店悬浮物品 已清理..."); + Bukkit.broadcastMessage("§6[§b快捷商店§6] §4警告 " + p.getDisplayName() + " §c非法获取快捷商店悬浮物品 已清理..."); } } catch (final Exception ex) { } } - @EventHandler - public void onItemMove(final InventoryMoveItemEvent e) { - final ItemStack ci = e.getItem(); - if (MarkUtil.hasMark(ci)) { - e.setItem(new ItemStack(Material.AIR)); - } - } - @EventHandler public void onJoin(final PlayerJoinEvent e) { // Notify the player any messages they were sent diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index 4bf7976..3b8d8be 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -9,8 +9,6 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; import java.util.Map.Entry; import org.bukkit.Bukkit; @@ -18,12 +16,14 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.maxgamer.QuickShop.Command.QS; +import org.maxgamer.QuickShop.Config.ConfigManager; import org.maxgamer.QuickShop.Config.ItemConfig; import org.maxgamer.QuickShop.Database.Database; import org.maxgamer.QuickShop.Database.DatabaseCore; @@ -49,25 +49,23 @@ import org.maxgamer.QuickShop.Watcher.ItemWatcher; import org.maxgamer.QuickShop.Watcher.LogWatcher; import org.mcstats.Metrics; +import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; public class QuickShop extends JavaPlugin { /** The active instance of QuickShop */ public static QuickShop instance; - // private Metrics metrics; - /** Whether debug info should be shown in the console */ - public static boolean debug = false; + /** The plugin default config */ + public FileConfig config; /** The economy we hook into for transactions */ private Economy economy; /** The Shop Manager used to store shops */ private ShopManager shopManager; - /** - * A set of players who have been warned - * ("Your shop isn't automatically locked") - */ - public HashSet warnings = new HashSet(); + /** The Config Manager used to read config */ + private ConfigManager configManager; /** The database for storing all our data for persistence */ private Database database; + // Listeners - We decide which one to use at runtime private ChatListener chatListener; // private HeroChatListener heroChatListener; @@ -78,24 +76,6 @@ public class QuickShop extends JavaPlugin { private final WorldListener worldListener = new WorldListener(this); private BukkitTask itemWatcherTask; private LogWatcher logWatcher; - /** Whether players are required to sneak to create/buy from a shop */ - public boolean sneak; - /** Whether players are required to sneak to create a shop */ - public boolean sneakCreate; - /** Whether players are required to sneak to trade with a shop */ - public boolean sneakTrade; - /** Whether we should use display items or not */ - public boolean display = true; - /** - * Whether we players are charged a fee to change the price on their shop - * (To help deter endless undercutting - */ - public boolean priceChangeRequiresFee = false; - /** Whether or not to limit players shop amounts */ - public boolean limit = false; - private final HashMap limits = new HashMap(); - /** Use SpoutPlugin to get item / block names */ - public boolean useSpout = false; /** * Prints debug information if QuickShop is configured to do so. @@ -104,12 +84,21 @@ public class QuickShop extends JavaPlugin { * The string to print. */ public void debug(final String s) { - if (!debug) { + if (!configManager.isDebug()) { return; } this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s); } + @Override + public FileConfiguration getConfig() { + return config; + } + + public ConfigManager getConfigManager() { + return configManager; + } + /** * @return Returns the database handler for queries etc. */ @@ -129,8 +118,8 @@ public class QuickShop extends JavaPlugin { /** The plugin metrics from Hidendra */ // public Metrics getMetrics(){ return metrics; } public int getShopLimit(final Player p) { - int max = getConfig().getInt("limits.default"); - for (final Entry entry : limits.entrySet()) { + int max = configManager.getLimitdefault(); + for (final Entry entry : configManager.getLimits().entrySet()) { if (entry.getValue() > max && p.hasPermission(entry.getKey())) { max = entry.getValue(); } @@ -204,47 +193,30 @@ public class QuickShop extends JavaPlugin { } catch (final SQLException e) { e.printStackTrace(); } - this.warnings.clear(); + configManager.getWarnings().clear(); } @Override public void onEnable() { instance = this; - saveDefaultConfig(); // Creates the config folder and copies config.yml - // (If one doesn't exist) as required. - reloadConfig(); // Reloads messages.yml too, aswell as config.yml and - // others. - getConfig().options().copyDefaults(true); // Load defaults. - if (getConfig().contains("debug")) { - debug = true; - } if (loadEcon() == false) { return; } // Initialize Util Util.initialize(); - ItemConfig.load(this); // Create the shop manager. - this.shopManager = new ShopManager(this); - if (this.getConfig().getBoolean("log-actions")) { + configManager = new ConfigManager(this); + shopManager = new ShopManager(this); + if (configManager.isLogAction()) { // Logger Handler this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log")); logWatcher.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, this.logWatcher, 150, 150); } - if (getConfig().getBoolean("shop.lock")) { + if (configManager.isShopLock()) { final LockListener ll = new LockListener(this); getServer().getPluginManager().registerEvents(ll, this); } - ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits"); - if (limitCfg != null) { - this.limit = limitCfg.getBoolean("use", false); - getLogger().info("商店创建限制: " + limit); - limitCfg = limitCfg.getConfigurationSection("ranks"); - for (final String key : limitCfg.getKeys(true)) { - limits.put(key, limitCfg.getInt(key)); - } - getLogger().info(limits.toString()); - } + try { final ConfigurationSection dbCfg = getConfig().getConfigurationSection("database"); DatabaseCore dbCore; @@ -347,23 +319,19 @@ public class QuickShop extends JavaPlugin { Bukkit.getServer().getPluginManager().registerEvents(blockListener, this); Bukkit.getServer().getPluginManager().registerEvents(playerListener, this); Bukkit.getServer().getPluginManager().registerEvents(worldListener, this); - if (this.display) { + if (configManager.isDisplay()) { Bukkit.getServer().getPluginManager().registerEvents(chunkListener, this); // Display item handler thread getLogger().info("开启悬浮物品刷新线程..."); final ItemWatcher itemWatcher = new ItemWatcher(this); itemWatcherTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 20, 600); } - if (this.getConfig().getBoolean("force-bukkit-chat-handler", false) && Bukkit.getPluginManager().getPlugin("Herochat") != null) { - this.getLogger().info("Found Herochat... Hooking!"); - } else { - this.chatListener = new ChatListener(this); - Bukkit.getServer().getPluginManager().registerEvents(chatListener, this); - } + this.chatListener = new ChatListener(this); + Bukkit.getServer().getPluginManager().registerEvents(chatListener, this); // Command handlers final QS commandExecutor = new QS(this); getCommand("qs").setExecutor(commandExecutor); - if (getConfig().getInt("shop.find-distance") > 100) { + if (configManager.getFindDistance() > 100) { getLogger().warning("商店查找半径过大 可能导致服务器Lag! 推荐使用低于 100 的配置!"); } new VersionChecker(this); @@ -374,16 +342,17 @@ public class QuickShop extends JavaPlugin { } } + @Override + public void onLoad() { + config = new FileConfig(this); + ItemConfig.load(this); + MsgUtil.init(this); + } + /** Reloads QuickShops config */ @Override public void reloadConfig() { - super.reloadConfig(); - // Load quick variables - this.display = this.getConfig().getBoolean("shop.display-items"); - this.sneak = this.getConfig().getBoolean("shop.sneak-only"); - this.sneakCreate = this.getConfig().getBoolean("shop.sneak-to-create"); - this.sneakTrade = this.getConfig().getBoolean("shop.sneak-to-trade"); - this.priceChangeRequiresFee = this.getConfig().getBoolean("shop.price-change-requires-fee"); - MsgUtil.loadCfgMessages(); + config.reload(); + ItemConfig.reload(); } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java index bf3e3ef..a20a4ae 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java @@ -52,7 +52,7 @@ public class ContainerShop implements Shop { this.item = item.clone(); this.plugin = (QuickShop) Bukkit.getPluginManager().getPlugin("QuickShop"); this.item.setAmount(1); - if (plugin.display) { + if (plugin.getConfigManager().isDisplay()) { this.displayItem = new DisplayItem(this, this.item); } this.shopType = ShopType.SELLING; @@ -371,7 +371,7 @@ public class ContainerShop implements Shop { continue; } final Sign sign = (Sign) b.getState(); - if (sign.getLine(0).contains("[QuickShop")) { + if (sign.getLine(0).contains("[QuickShop]")) { signs.add(sign); } else { boolean text = false; @@ -669,7 +669,7 @@ public class ContainerShop implements Shop { } private void checkDisplay() { - if (plugin.display == false) { + if (plugin.getConfigManager().isDisplay() == false) { return; } if (getLocation().getWorld() == null) { diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java index 08831b2..622e2f9 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/DisplayItem.java @@ -6,7 +6,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Util.NMS; /** @@ -85,9 +84,6 @@ public class DisplayItem { if (this.shop.matches(near)) { e.remove(); removed = true; - if (QuickShop.debug) { - System.out.println("Removed rogue item: " + near.getType()); - } } } } @@ -116,8 +112,5 @@ public class DisplayItem { NMS.safeGuard(this.item); } catch (final Exception e) { } - if (QuickShop.debug) { - System.out.println("Spawned item. Safeguarding."); - } } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java b/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java index 0389b5d..3e9ad58 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ShopManager.java @@ -1,6 +1,7 @@ package org.maxgamer.QuickShop.Shop; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.NoSuchElementException; @@ -108,7 +109,7 @@ public class ShopManager { * @return True if they're allowed to place a shop there. */ public boolean canBuildShop(final Player p, final Block b, final BlockFace bf) { - if (plugin.limit) { + if (plugin.getConfigManager().isLimit()) { int owned = 0; final Iterator it = getShopIterator(); while (it.hasNext()) { @@ -142,7 +143,7 @@ public class ShopManager { * the database. Call this on plugin disable ONLY. */ public void clear() { - if (plugin.display) { + if (plugin.getConfigManager().isDisplay()) { for (final World world : Bukkit.getWorlds()) { for (final Chunk chunk : world.getLoadedChunks()) { final HashMap inChunk = this.getShops(chunk); @@ -347,9 +348,10 @@ public class ShopManager { if (!plugin.getConfig().getBoolean("shop.lock")) { // Warn them if they haven't been warned since // reboot - if (!plugin.warnings.contains(p.getName())) { + final HashSet warings = plugin.getConfigManager().getWarnings(); + if (!warings.contains(p.getName())) { p.sendMessage(MsgUtil.p("shops-arent-locked")); - plugin.warnings.add(p.getName()); + warings.add(p.getName()); } } // Figures out which way we should put the sign on and diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MarkUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MarkUtil.java index da9bb7c..73b9879 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MarkUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MarkUtil.java @@ -4,11 +4,12 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; public class MarkUtil { - static String mark = "§q§s§r"; + static String mark = "§q§s§6[§b快捷商店§6] §c悬浮物品§r "; + static int conut = 0; public static void addMark(final ItemStack ci) { final ItemMeta meta = ci.getItemMeta(); - meta.setDisplayName(mark + Util.getName(ci)); + meta.setDisplayName(mark + " " + Util.getName(ci) + " " + conut++); ci.setItemMeta(meta); } diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java index bd579ea..4d23faa 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java @@ -22,10 +22,6 @@ public class MsgUtil { private static FileConfig messages; private static HashMap> player_messages = new HashMap>(); - static { - plugin = QuickShop.instance; - } - /** * Deletes any messages that are older than a week in the database, to save * on space. @@ -60,10 +56,8 @@ public class MsgUtil { return false; } - /** - * Loads all the messages from messages.yml - */ - public static void loadCfgMessages() { + public static void init(final QuickShop plugin) { + MsgUtil.plugin = plugin; // Load messages.yml messages = new FileConfig(plugin, "messages.yml"); // Parse colour codes diff --git a/src/main/java/org/maxgamer/QuickShop/Util/NMS.java b/src/main/java/org/maxgamer/QuickShop/Util/NMS.java index 7f40985..b86d1ed 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/NMS.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/NMS.java @@ -5,22 +5,12 @@ import java.lang.reflect.Method; import org.bukkit.entity.Item; import org.bukkit.inventory.ItemStack; -import org.maxgamer.QuickShop.QuickShop; public class NMS { public static void safeGuard(final Item item) throws ClassNotFoundException { - if (QuickShop.debug) { - System.out.println("Renaming"); - } rename(item.getItemStack()); - if (QuickShop.debug) { - System.out.println("Protecting"); - } protect(item); - if (QuickShop.debug) { - System.out.println("Seting pickup delay"); - } item.setPickupDelay(2147483647); } diff --git a/src/main/java/org/maxgamer/QuickShop/Util/Util.java b/src/main/java/org/maxgamer/QuickShop/Util/Util.java index f92d72e..bc701ac 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/Util.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/Util.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -169,25 +168,29 @@ public class Util { // Let's make very long names shorter for our sign public static String getNameForSign(final ItemStack itemStack) { // final String name = getDataName(itemStack.getType(), itemStack.getDurability()); - final String name = getName(itemStack); + String name = getName(itemStack); - final String[] nameParts = name.split("_"); - if (nameParts.length == 1) { - return firstUppercase(nameParts[0]); + if (name.length() > 16) { + name = name.substring(0, 16); } - - for (int i = 0; i < nameParts.length - 1; i++) { - final int length = StringUtils.join(nameParts).length(); - if (length > 16) { - nameParts[i] = nameParts[i].substring(0, 1) + "."; - } else { - nameParts[i] = firstUppercase(nameParts[i]); - } - } - - nameParts[nameParts.length - 1] = firstUppercase(nameParts[nameParts.length - 1]); - - return StringUtils.join(nameParts); + return name; + // final String[] nameParts = name.split("_"); + // if (nameParts.length == 1) { + // return firstUppercase(nameParts[0]); + // } + // + // for (int i = 0; i < nameParts.length - 1; i++) { + // final int length = StringUtils.join(nameParts).length(); + // if (length > 16) { + // nameParts[i] = nameParts[i].substring(0, 1) + "."; + // } else { + // nameParts[i] = firstUppercase(nameParts[i]); + // } + // } + // + // nameParts[nameParts.length - 1] = firstUppercase(nameParts[nameParts.length - 1]); + // + // return StringUtils.join(nameParts); } /** diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d17ae7d..48138f1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,8 @@ +Version: 1.0 + +#超级工具(OP可以用该工具在创造模式打破所有商店) +superitem: GOLD_AXE + #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.05 #The fake player who money from taxing people goes to diff --git a/src/main/resources/item.yml b/src/main/resources/item.yml index 3a0d045..abf2243 100644 --- a/src/main/resources/item.yml +++ b/src/main/resources/item.yml @@ -1,4 +1,4 @@ -Version: 1.0 +Version: 1.1 AIR_-1: 爪子 AIR: 爪子 @@ -7,7 +7,12 @@ GRASS: 草方块 DIRT: 泥土 COBBLESTONE: 圆石 WOOD: 木板 -SAPLING: 树苗 +SAPLING: 橡木树苗 +SAPLING_1: 云杉树苗 +SAPLING_2: 白桦树苗 +SAPLING_3: 丛林树苗 +SAPLING_4: 金合欢树苗 +SAPLING_5: 深色橡木树苗 BEDROCK: 基岩 WATER: 水 STATIONARY_WATER: 静态的水 @@ -27,7 +32,7 @@ LAPIS_BLOCK: 青金石块 DISPENSER: 发射器 SANDSTONE: 沙石 NOTE_BLOCK: 音符盒 -BED_BLOCK: BED_BLOCK +BED_BLOCK: 床 POWERED_RAIL: 动力铁轨 DETECTOR_RAIL: 探测铁轨 PISTON_STICKY_BASE: 粘性活塞 @@ -117,10 +122,10 @@ WATER_LILY: 睡莲 NETHER_BRICK: 地狱砖块 NETHER_FENCE: 地狱栅栏 NETHER_BRICK_STAIRS: 地狱砖楼梯 -NETHER_WARTS: NETHER_WARTS +NETHER_WARTS: 地狱疣 ENCHANTMENT_TABLE: 附魔台 -BREWING_STAND: BREWING_STAND -CAULDRON: CAULDRON +BREWING_STAND: 酿造台 +CAULDRON: 炼药锅 ENDER_PORTAL: 末地传送门 ENDER_PORTAL_FRAME: 末地传送框架 ENDER_STONE: 末地石 @@ -142,13 +147,13 @@ JUNGLE_WOOD_STAIRS: 丛林木楼梯 COMMAND: 命令方块 BEACON: 信标 COBBLE_WALL: 圆石墙 -FLOWER_POT: FLOWER_POT +FLOWER_POT: 花盆 CARROT: 胡萝卜 POTATO: 土豆 WOOD_BUTTON: 木按钮 -SKULL: SKULL +SKULL: 头颅 ANVIL: 铁毡 -TRAPPED_CHEST: TRAPPED_CHEST +TRAPPED_CHEST: 陷阱箱 GOLD_PLATE: 测重压力板(轻质) IRON_PLATE: 测重压力板(重质) REDSTONE_COMPARATOR_OFF: 红石比较器(关闭) @@ -156,7 +161,7 @@ REDSTONE_COMPARATOR_ON: 红石比较器(打开) DAYLIGHT_DETECTOR: 阳光传感器 REDSTONE_BLOCK: 红石块 QUARTZ_ORE: 下界石英矿石 -HOPPER: 漏洞 +HOPPER: 漏斗 QUARTZ_BLOCK: 石英块 QUARTZ_STAIRS: 石英楼梯 ACTIVATOR_RAIL: 激活铁轨 @@ -236,8 +241,8 @@ GOLD_CHESTPLATE: 金外套 GOLD_LEGGINGS: 金护腿 GOLD_BOOTS: 金靴子 FLINT: 燧石 -PORK: 猪排 -GRILLED_PORK: GRILLED_PORK +PORK: 生猪排 +GRILLED_PORK: 熟猪排 PAINTING: 画 GOLDEN_APPLE: 金苹果 SIGN: 木牌 @@ -253,8 +258,8 @@ SNOW_BALL: 雪球 BOAT: 船 LEATHER: 皮革 MILK_BUCKET: 牛奶桶 -CLAY_BRICK: CLAY_BRICK -CLAY_BALL: 粘土 +CLAY_BRICK: 红砖 +CLAY_BALL: 粘土球 SUGAR_CANE: 甘蔗 PAPER: 纸 BOOK: 书 @@ -294,8 +299,8 @@ POTION: 药水 GLASS_BOTTLE: 玻璃瓶 SPIDER_EYE: 蜘蛛眼 FERMENTED_SPIDER_EYE: 发酵蛛眼 -BLAZE_POWDER: BLAZE_POWDER -MAGMA_CREAM: MAGMA_CREAM +BLAZE_POWDER: 烈焰粉 +MAGMA_CREAM: 岩浆膏 BREWING_STAND_ITEM: 酿造台 CAULDRON_ITEM: 炼药锅 BREWING_STAND: 酿造台 @@ -309,7 +314,7 @@ BOOK_AND_QUILL: 书和笔 WRITTEN_BOOK: 成书 EMERALD: 绿宝石 ITEM_FRAME: 物品展示框 -FLOWER_POT_ITEM: FLOWER_POT_ITEM +FLOWER_POT_ITEM: 花盆 CARROT_ITEM: 胡萝卜 POTATO_ITEM: 马铃薯 BAKED_POTATO: 烤马铃薯 @@ -317,11 +322,11 @@ POISONOUS_POTATO: 毒马铃薯 EMPTY_MAP: 空地图 GOLDEN_CARROT: 金萝卜 SKULL_ITEM: 头颅 -CARROT_STICK: CARROT_STICK +CARROT_STICK: 胡萝卜 NETHER_STAR: 下界之星 PUMPKIN_PIE: 南瓜派 FIREWORK: 烟花 -FIREWORK_CHARGE: FIREWORK_CHARGE +FIREWORK_CHARGE: 烟花 ENCHANTED_BOOK: 附魔书 REDSTONE_COMPARATOR: 红石比较器 NETHER_BRICK_ITEM: 地狱砖块