From 49c0b8ecd7e34642c8485a0b47efe0b8fc49614b Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 13 Dec 2016 19:07:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E7=B1=BB=E5=BA=93=20?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=96=E7=95=8C=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 27 ++----- .../QuickShop/Command/QuickShopCommands.java | 40 +++++----- .../QuickShop/Config/ConfigManager.java | 9 ++- .../maxgamer/QuickShop/Database/Database.java | 5 +- .../QuickShop/Database/DatabaseCore.java | 8 +- .../QuickShop/Database/DatabaseHelper.java | 6 +- .../QuickShop/Database/MySQLCore.java | 5 +- .../QuickShop/Database/SQLiteCore.java | 15 ++-- .../QuickShop/Economy/Economy_Vault.java | 4 +- .../org/maxgamer/QuickShop/QuickShop.java | 33 ++------ .../QuickShop/Shop/ContainerShop.java | 79 +++++-------------- .../QuickShop/Shop/Item/DisplayItem.java | 4 +- .../QuickShop/Shop/Item/FakeItem.java | 39 ++++----- .../QuickShop/Shop/Item/NormalItem.java | 14 +--- .../org/maxgamer/QuickShop/Shop/Shop.java | 68 ++++++++-------- .../maxgamer/QuickShop/Shop/ShopAction.java | 2 +- .../org/maxgamer/QuickShop/Shop/ShopType.java | 2 +- .../org/maxgamer/QuickShop/Util/MsgUtil.java | 16 ++-- 18 files changed, 141 insertions(+), 235 deletions(-) diff --git a/pom.xml b/pom.xml index 3c6b123..354f6aa 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.maxgamer QuickShop - 1.9.5 + 2.0 快捷商店重置版本... ${project.name} @@ -71,6 +71,10 @@ yumc-repo http://repo.yumc.pw/content/groups/public/ + + dmulloy + http://repo.dmulloy2.net/content/groups/public/ + @@ -80,23 +84,11 @@ - - org.spigotmc - spigot-api - jar - 1.10.2-R0.1-SNAPSHOT - - - net.milkbowl.vault - Vault - jar - 1.5.6 - pw.yumc YumCore jar - 1.1 + 1.5 io.github.Cnly.WowSuchCleaner @@ -110,12 +102,5 @@ system ${project.basedir}/lib/WorldEdit.jar - - com.comphenix.protocol - ProtocolLib - 4.1 - system - ${project.basedir}/lib/ProtocolLib-4.1.jar - \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Command/QuickShopCommands.java b/src/main/java/org/maxgamer/QuickShop/Command/QuickShopCommands.java index b35ff8e..f13c83d 100644 --- a/src/main/java/org/maxgamer/QuickShop/Command/QuickShopCommands.java +++ b/src/main/java/org/maxgamer/QuickShop/Command/QuickShopCommands.java @@ -1,5 +1,9 @@ package org.maxgamer.QuickShop.Command; +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; @@ -10,37 +14,33 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.util.BlockIterator; +import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Database.Database; import org.maxgamer.QuickShop.Database.MySQLCore; import org.maxgamer.QuickShop.Database.SQLiteCore; -import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.ContainerShop; import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.ShopChunk; import org.maxgamer.QuickShop.Shop.ShopType; import org.maxgamer.QuickShop.Util.MsgUtil; + import pw.yumc.YumCore.bukkit.P; -import pw.yumc.YumCore.commands.CommandManager; +import pw.yumc.YumCore.commands.CommandSub; import pw.yumc.YumCore.commands.annotation.Cmd; -import pw.yumc.YumCore.commands.annotation.Cmd.Executor; import pw.yumc.YumCore.commands.annotation.Help; import pw.yumc.YumCore.commands.annotation.Sort; -import pw.yumc.YumCore.commands.interfaces.CommandExecutor; -import pw.yumc.YumCore.commands.interfaces.CommandHelpParse; +import pw.yumc.YumCore.commands.interfaces.Executor; +import pw.yumc.YumCore.commands.interfaces.HelpParse; -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; - -public class QuickShopCommands implements CommandExecutor, CommandHelpParse { +public class QuickShopCommands implements Executor, HelpParse { QuickShop plugin = P.getPlugin(); public QuickShopCommands() { - new CommandManager("qs", this).setHelpParse(this); + new CommandSub("qs", this).setHelpParse(this); } @Sort(1) - @Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Executor.PLAYER) + @Cmd(aliases = "b", permission = "quickshop.create.buy", executor = Cmd.Executor.PLAYER) @Help("command.description.buy") public void buy(Player player) { changeShopType(player, ShopType.BUYING); @@ -73,7 +73,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(5) - @Cmd(aliases = "e", permission = "quickshop.empty", executor = Executor.PLAYER) + @Cmd(aliases = "e", permission = "quickshop.empty", executor = Cmd.Executor.PLAYER) @Help("command.description.empty") public void empty(Player player) { final BlockIterator bIt = new BlockIterator(player, 10); @@ -141,7 +141,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } } - @Cmd(aliases = "f", minimumArguments = 1, permission = "quickshop.find", executor = Executor.PLAYER) + @Cmd(aliases = "f", minimumArguments = 1, permission = "quickshop.find", executor = Cmd.Executor.PLAYER) @Help("command.description.find") public void find(Player p, String lookFor) { lookFor = lookFor.toLowerCase(); @@ -218,7 +218,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(4) - @Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Executor.PLAYER) + @Cmd(aliases = "p", minimumArguments = 1, permission = "quickshop.create.changeprice", executor = Cmd.Executor.PLAYER) @Help(value = "command.description.price", possibleArguments = "<价格>") public void price(Player sender, Double price) { if (price < 0.01) { @@ -281,7 +281,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(6) - @Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Executor.PLAYER) + @Cmd(minimumArguments = 1, permission = "quickshop.refill", executor = Cmd.Executor.PLAYER) @Help(value = "command.description.refill", possibleArguments = "<数量>") public void refill(Player sender, Integer add) { final BlockIterator bIt = new BlockIterator(sender, 10); @@ -307,7 +307,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(6) - @Cmd(aliases = "r", permission = "quickshop.delete", executor = Executor.PLAYER) + @Cmd(aliases = "r", permission = "quickshop.delete", executor = Cmd.Executor.PLAYER) @Help("command.description.remove") public void remove(Player p) { final BlockIterator bIt = new BlockIterator(p, 10); @@ -328,14 +328,14 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(2) - @Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Executor.PLAYER) + @Cmd(aliases = "s", permission = "quickshop.create.sell", executor = Cmd.Executor.PLAYER) @Help("command.description.sell") public void sell(Player player) { changeShopType(player, ShopType.SELLING); } @Sort(3) - @Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Executor.PLAYER) + @Cmd(aliases = "so", minimumArguments = 1, permission = "quickshop.setowner", executor = Cmd.Executor.PLAYER) @Help("command.description.setowner") public void setowner(CommandSender sender, String owner) { final BlockIterator bIt = new BlockIterator((Player) sender, 10); @@ -353,7 +353,7 @@ public class QuickShopCommands implements CommandExecutor, CommandHelpParse { } @Sort(0) - @Cmd(permission = "quickshop.unlimited", executor = Executor.PLAYER) + @Cmd(permission = "quickshop.unlimited", executor = Cmd.Executor.PLAYER) @Help("command.description.unlimited") public void unlimited(Player sender) { final BlockIterator bIt = new BlockIterator(sender, 10); diff --git a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java index 40e61ec..506a25e 100644 --- a/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java +++ b/src/main/java/org/maxgamer/QuickShop/Config/ConfigManager.java @@ -1,17 +1,18 @@ package org.maxgamer.QuickShop.Config; +import java.util.*; + import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import org.maxgamer.QuickShop.QuickShop; import org.maxgamer.QuickShop.Shop.Item.FakeItem_17_18; import org.maxgamer.QuickShop.Shop.Item.FakeItem_19_110; + import pw.yumc.YumCore.bukkit.Log; import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.tellraw.Tellraw; -import java.util.*; - public class ConfigManager { private boolean enableMagicLib = false; /** Whether debug info should be shown in the console */ @@ -91,7 +92,7 @@ public class ConfigManager { plugin.getLogger().info("虚拟悬浮物功能测试正常(1.8-1.10.2)..."); fakeItem = true; } catch (final Throwable e) { - Log.debug(e); + Log.d(e); try { FakeItem_17_18.register(plugin); plugin.getLogger().info("虚拟悬浮物功能测试正常(1.7)..."); @@ -100,7 +101,7 @@ public class ConfigManager { plugin.getLogger().warning("+========================================="); plugin.getLogger().warning("| 警告: 启动虚拟物品失败 使用原版悬浮物品..."); plugin.getLogger().warning("+========================================="); - Log.debug(e2); + Log.d(e2); } } } diff --git a/src/main/java/org/maxgamer/QuickShop/Database/Database.java b/src/main/java/org/maxgamer/QuickShop/Database/Database.java index e33adb5..d09c458 100644 --- a/src/main/java/org/maxgamer/QuickShop/Database/Database.java +++ b/src/main/java/org/maxgamer/QuickShop/Database/Database.java @@ -112,8 +112,7 @@ public class Database { PreparedStatement ps = this.getConnection().prepareStatement(query); ResultSet rs = ps.executeQuery(); while (rs.next()) { - rs.getString(column); // Throws an exception if it can't find - // that column + rs.getString(column); // Throws an exception if it can't find that column return true; } } catch (SQLException e) { @@ -149,7 +148,7 @@ public class Database { */ public void copyTo(Database db) throws SQLException { ResultSet rs = getConnection().getMetaData().getTables(null, null, "%", null); - List tables = new LinkedList(); + List tables = new LinkedList<>(); while (rs.next()) { tables.add(rs.getString("TABLE_NAME")); } diff --git a/src/main/java/org/maxgamer/QuickShop/Database/DatabaseCore.java b/src/main/java/org/maxgamer/QuickShop/Database/DatabaseCore.java index b89289b..efb537b 100644 --- a/src/main/java/org/maxgamer/QuickShop/Database/DatabaseCore.java +++ b/src/main/java/org/maxgamer/QuickShop/Database/DatabaseCore.java @@ -3,11 +3,11 @@ package org.maxgamer.QuickShop.Database; import java.sql.Connection; public interface DatabaseCore { - public Connection getConnection(); + Connection getConnection(); - public void queue(BufferStatement bs); + void queue(BufferStatement bs); - public void flush(); + void flush(); - public void close(); + void close(); } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Database/DatabaseHelper.java b/src/main/java/org/maxgamer/QuickShop/Database/DatabaseHelper.java index cbaaf5b..07194c4 100644 --- a/src/main/java/org/maxgamer/QuickShop/Database/DatabaseHelper.java +++ b/src/main/java/org/maxgamer/QuickShop/Database/DatabaseHelper.java @@ -19,20 +19,20 @@ public class DatabaseHelper { * Verifies that all required columns exist. */ public static void checkColumns(Database db) { - PreparedStatement ps = null; + PreparedStatement ps; try { // V3.4.2 ps = db.getConnection().prepareStatement("ALTER TABLE shops MODIFY COLUMN price double(32,2) NOT NULL AFTER owner"); ps.execute(); ps.close(); - } catch (SQLException e) { + } catch (SQLException ignored) { } try { // V3.4.3 ps = db.getConnection().prepareStatement("ALTER TABLE messages MODIFY COLUMN time BIGINT(32) NOT NULL AFTER message"); ps.execute(); ps.close(); - } catch (SQLException e) { + } catch (SQLException ignored) { } } diff --git a/src/main/java/org/maxgamer/QuickShop/Database/MySQLCore.java b/src/main/java/org/maxgamer/QuickShop/Database/MySQLCore.java index 10f1c62..deebecb 100644 --- a/src/main/java/org/maxgamer/QuickShop/Database/MySQLCore.java +++ b/src/main/java/org/maxgamer/QuickShop/Database/MySQLCore.java @@ -12,7 +12,7 @@ public class MySQLCore implements DatabaseCore { /** The connection properties... user, pass, autoReconnect.. */ private Properties info; private static final int MAX_CONNECTIONS = 8; - private static ArrayList pool = new ArrayList(); + private static ArrayList pool = new ArrayList<>(); public MySQLCore(String host, String user, String pass, String database, String port) { info = new Properties(); @@ -59,7 +59,7 @@ public class MySQLCore implements DatabaseCore { while (con == null) { try { Thread.sleep(15); - } catch (InterruptedException e) { + } catch (InterruptedException ignored) { } // Try again this.getConnection(); @@ -69,7 +69,6 @@ public class MySQLCore implements DatabaseCore { ps.close(); } catch (SQLException e) { e.printStackTrace(); - return; } } diff --git a/src/main/java/org/maxgamer/QuickShop/Database/SQLiteCore.java b/src/main/java/org/maxgamer/QuickShop/Database/SQLiteCore.java index 51b56ca..82bb42f 100644 --- a/src/main/java/org/maxgamer/QuickShop/Database/SQLiteCore.java +++ b/src/main/java/org/maxgamer/QuickShop/Database/SQLiteCore.java @@ -12,7 +12,7 @@ public class SQLiteCore implements DatabaseCore { private Connection connection; private final File dbFile; private volatile Thread watcher; - private volatile LinkedList queue = new LinkedList(); + private final LinkedList queue = new LinkedList(); public SQLiteCore(final File dbFile) { this.dbFile = dbFile; @@ -25,7 +25,7 @@ public class SQLiteCore implements DatabaseCore { @Override public void flush() { - while (queue.isEmpty() == false) { + while (!queue.isEmpty()) { BufferStatement bs; synchronized (queue) { bs = queue.removeFirst(); @@ -51,9 +51,7 @@ public class SQLiteCore implements DatabaseCore { public Connection getConnection() { try { // If we have a current connection, fetch it - if (this.connection != null && !this.connection.isClosed()) { - return this.connection; - } + if (this.connection != null && !this.connection.isClosed()) { return this.connection; } } catch (final SQLException e) { e.printStackTrace(); } @@ -63,10 +61,7 @@ public class SQLiteCore implements DatabaseCore { Class.forName("org.sqlite.JDBC"); this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.dbFile); return this.connection; - } catch (final ClassNotFoundException e) { - e.printStackTrace(); - return null; - } catch (final SQLException e) { + } catch (final ClassNotFoundException | SQLException e) { e.printStackTrace(); return null; } @@ -100,7 +95,7 @@ public class SQLiteCore implements DatabaseCore { public void run() { try { Thread.sleep(30000); - } catch (final InterruptedException e) { + } catch (final InterruptedException ignored) { } flush(); } diff --git a/src/main/java/org/maxgamer/QuickShop/Economy/Economy_Vault.java b/src/main/java/org/maxgamer/QuickShop/Economy/Economy_Vault.java index af91816..4c30253 100644 --- a/src/main/java/org/maxgamer/QuickShop/Economy/Economy_Vault.java +++ b/src/main/java/org/maxgamer/QuickShop/Economy/Economy_Vault.java @@ -36,7 +36,7 @@ public class Economy_Vault implements EconomyCore { public String format(final double balance) { try { return this.vault.format(balance); - } catch (final NumberFormatException e) { + } catch (final NumberFormatException ignored) { } return "" + balance; } @@ -109,7 +109,7 @@ public class Economy_Vault implements EconomyCore { if (economyProvider != null) { vault = (economyProvider.getProvider()); } - } catch (final Exception e) { + } catch (final Exception ignored) { } return vault != null; } diff --git a/src/main/java/org/maxgamer/QuickShop/QuickShop.java b/src/main/java/org/maxgamer/QuickShop/QuickShop.java index 90467d1..d689572 100644 --- a/src/main/java/org/maxgamer/QuickShop/QuickShop.java +++ b/src/main/java/org/maxgamer/QuickShop/QuickShop.java @@ -1,20 +1,12 @@ package org.maxgamer.QuickShop; import java.io.File; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; +import java.sql.*; import java.util.Calendar; import java.util.Date; 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.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -26,22 +18,11 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; import org.maxgamer.QuickShop.Command.QuickShopCommands; import org.maxgamer.QuickShop.Config.ConfigManager; -import org.maxgamer.QuickShop.Database.Database; -import org.maxgamer.QuickShop.Database.DatabaseCore; -import org.maxgamer.QuickShop.Database.DatabaseHelper; -import org.maxgamer.QuickShop.Database.MySQLCore; -import org.maxgamer.QuickShop.Database.SQLiteCore; +import org.maxgamer.QuickShop.Database.*; import org.maxgamer.QuickShop.Economy.Economy; import org.maxgamer.QuickShop.Economy.EconomyCore; import org.maxgamer.QuickShop.Economy.Economy_Vault; -import org.maxgamer.QuickShop.Listeners.BlockListener; -import org.maxgamer.QuickShop.Listeners.ChatListener; -import org.maxgamer.QuickShop.Listeners.ChunkListener; -import org.maxgamer.QuickShop.Listeners.LockListener; -import org.maxgamer.QuickShop.Listeners.PlayerListener; -import org.maxgamer.QuickShop.Listeners.ProtectListener; -import org.maxgamer.QuickShop.Listeners.WorldListener; -import org.maxgamer.QuickShop.Listeners.WowSuchCleanerListener; +import org.maxgamer.QuickShop.Listeners.*; import org.maxgamer.QuickShop.Shop.ContainerShop; import org.maxgamer.QuickShop.Shop.Shop; import org.maxgamer.QuickShop.Shop.ShopManager; @@ -177,7 +158,7 @@ public class QuickShop extends JavaPlugin { final double price = rs.getDouble("price"); final Location loc = new Location(world, x, y, z); /* Skip invalid shops, if we know of any */ - if (world != null && loc.getChunk().isLoaded() && (loc.getBlock().getState() instanceof InventoryHolder) == false) { + if (world != null && loc.getChunk().isLoaded() && !(loc.getBlock().getState() instanceof InventoryHolder)) { getLogger().info("商店不是一个可存储的方块 坐标 " + rs.getString("world") + ", " + x + ", " + y + ", " + z + ". 删除..."); database.execute("DELETE FROM shops WHERE x = ? AND y = ? and z = ? and world = ?", x, y, z, worldName); continue; @@ -248,7 +229,7 @@ public class QuickShop extends JavaPlugin { database.close(); try { database.getConnection().close(); - } catch (final SQLException e) { + } catch (final SQLException ignored) { } } if (configManager != null) { @@ -258,7 +239,7 @@ public class QuickShop extends JavaPlugin { @Override public void onEnable() { - if (loadEcon() == false) { + if (!loadEcon()) { return; } configManager = new ConfigManager(this); diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java index 67e7477..299382a 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ContainerShop.java @@ -79,9 +79,7 @@ public class ContainerShop implements Shop { */ @Override public void add(final ItemStack item, final int amount) { - if (this.unlimited) { - return; - } + if (this.unlimited) { return; } final Inventory inv = this.getInventory(); int remains = amount; while (remains > 0) { @@ -98,8 +96,6 @@ public class ContainerShop implements Shop { * * @param p * The player to buy from - * @param item - * The itemStack to buy * @param amount * The amount to buy */ @@ -217,13 +213,9 @@ public class ContainerShop implements Shop { * null if this shop is not attached to another. */ public ContainerShop getAttachedShop() { - if (this.getLocation() != null) { - return null; - } + if (this.getLocation() != null) { return null; } final Block c = Util.getSecondHalf(this.getLocation().getBlock()); - if (c == null) { - return null; - } + if (c == null) { return null; } final Shop shop = plugin.getShopManager().getShop(c.getLocation()); return shop == null ? null : (ContainerShop) shop; } @@ -316,15 +308,11 @@ public class ContainerShop implements Shop { /** * Returns the number of free spots in the chest for the particular item. - * - * @param stackSize * @return */ @Override public int getRemainingSpace() { - if (this.unlimited) { - return 10000; - } + if (this.unlimited) { return 10000; } return Util.countSpace(this.getInventory(), item); } @@ -335,9 +323,7 @@ public class ContainerShop implements Shop { */ @Override public int getRemainingStock() { - if (this.unlimited) { - return 10000; - } + if (this.unlimited) { return 10000; } return Util.countItems(this.getInventory(), this.getItem()); } @@ -356,9 +342,7 @@ public class ContainerShop implements Shop { @Override public List getSigns() { final ArrayList signs = new ArrayList<>(1); - if (this.getLocation().getWorld() == null) { - return signs; - } + if (this.getLocation().getWorld() == null) { return signs; } final Block[] blocks = new Block[4]; blocks[0] = loc.getBlock().getRelative(1, 0, 0); blocks[1] = loc.getBlock().getRelative(-1, 0, 0); @@ -412,9 +396,7 @@ public class ContainerShop implements Shop { */ public boolean isDoubleShop() { final ContainerShop nextTo = this.getAttachedShop(); - if (nextTo == null) { - return false; - } + if (nextTo == null) { return false; } if (nextTo.matches(this.getItem())) { // They're both trading the same item if (this.getShopType() == nextTo.getShopType()) { @@ -485,9 +467,7 @@ public class ContainerShop implements Shop { */ @Override public void remove(final ItemStack item, final int amount) { - if (this.unlimited) { - return; - } + if (this.unlimited) { return; } final Inventory inv = this.getInventory(); int remains = amount; while (remains > 0) { @@ -548,8 +528,8 @@ public class ContainerShop implements Shop { // We now have to update the chests inventory manually. this.getInventory().setContents(chestContents); } - for (int i = 0; i < floor.size(); i++) { - p.getWorld().dropItem(p.getLocation(), floor.get(i)); + for (ItemStack aFloor : floor) { + p.getWorld().dropItem(p.getLocation(), aFloor); } } @@ -594,9 +574,7 @@ public class ContainerShop implements Shop { */ @Override public void setSignText() { - if (Util.isLoaded(this.getLocation()) == false) { - return; - } + if (!Util.isLoaded(this.getLocation())) { return; } final ContainerShop shop = this; // 1.9不能异步修改木牌 Bukkit.getScheduler().runTask(plugin, new Runnable() { @@ -627,9 +605,7 @@ public class ContainerShop implements Shop { */ @Override public void setSignText(final String[] lines) { - if (Util.isLoaded(this.getLocation()) == false) { - return; - } + if (!Util.isLoaded(this.getLocation())) { return; } final List signs = this.getSigns(); // 1.9不能异步修改木牌 Bukkit.getScheduler().runTask(plugin, new Runnable() { @@ -652,21 +628,14 @@ public class ContainerShop implements Shop { @Override public String toString() { - final StringBuilder sb = new StringBuilder("商店 " - + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) - + "(" - + loc.getBlockX() - + ", " - + loc.getBlockY() - + ", " - + loc.getBlockZ() - + ")"); - sb.append(" 所有者: " + getOwner()); + final StringBuilder sb = new StringBuilder("商店 " + (loc.getWorld() == null ? "世界尚未载入" : "坐标: " + loc.getWorld().getName()) + "(" + loc.getBlockX() + ", " + loc.getBlockY() + ", " + + loc.getBlockZ() + ")"); + sb.append(" 所有者: ").append(getOwner()); if (isUnlimited()) { sb.append(" 无限模式: true"); } - sb.append(" 价格: " + getPrice()); - sb.append(" 物品: " + getItem().toString()); + sb.append(" 价格: ").append(getPrice()); + sb.append(" 物品: ").append(getItem().toString()); return sb.toString(); } @@ -691,11 +660,8 @@ public class ContainerShop implements Shop { } private void checkDisplay() { - if (plugin.getConfigManager().isDisplay() == false) { - return; - } - if (getLocation().getWorld() == null) { - return; // not loaded + if (!plugin.getConfigManager().isDisplay()) { return; } + if (getLocation().getWorld() == null) { return; // not loaded } final boolean trans = Util.isTransparent(getLocation().clone().add(0.5, 1.2, 0.5).getBlock().getType()); if (trans && this.getDisplayItem() == null) { @@ -709,14 +675,11 @@ public class ContainerShop implements Shop { this.displayItem = null; return; } - if (this.getLocation().getWorld() == null) { - return;// Ignore if world not loaded... + if (this.getLocation().getWorld() == null) { return;// Ignore if world not loaded... } final DisplayItem disItem = this.getDisplayItem(); final Location dispLoc = disItem.getDisplayLocation(); - if (dispLoc.getWorld() == null) { - return; - } + if (dispLoc.getWorld() == null) { return; } if (dispLoc.getBlock() != null && dispLoc.getBlock().getType() == Material.WATER) { // Flowing // water.Stationery water does not move items. disItem.remove(); diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java index 46397c7..2eab29e 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/DisplayItem.java @@ -21,11 +21,11 @@ public abstract class DisplayItem { try { return new FakeItem_19_110(shop, shop.getItem()); } catch (final Throwable e) { - Log.debug(e); + Log.d(e); try { return new FakeItem_17_18(shop, shop.getItem()); } catch (final Throwable e2) { - Log.debug(e2); + Log.d(e2); } } } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java index 16ddab8..e8c59af 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/FakeItem.java @@ -1,10 +1,7 @@ package org.maxgamer.QuickShop.Shop.Item; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.lang.reflect.InvocationTargetException; +import java.util.*; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -76,14 +73,8 @@ public abstract class FakeItem extends DisplayItem { final int chunkX = packet.getIntegers().read(0); final int chunkZ = packet.getIntegers().read(1); final List fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunkX, chunkZ))); - if (fakesInChunk != null) { - for (final FakeItem fake : fakesInChunk) { - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket()); - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket()); - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket()); - } - } - } catch (final Exception e) { + sendChunkPacket(p, fakesInChunk); + } catch (final Exception ignored) { } } }; @@ -97,16 +88,9 @@ public abstract class FakeItem extends DisplayItem { final int[] chunksZ = packet.getIntegerArrays().read(1); for (int i = 0; i < chunksX.length; i++) { final List fakesInChunk = fakes.get(getChunkIdentifyString(p.getWorld().getChunkAt(chunksX[i], chunksZ[i]))); - if (fakesInChunk != null) { - for (final FakeItem fake : fakesInChunk) { - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket()); - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket()); - ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket()); - } - - } + sendChunkPacket(p, fakesInChunk); } - } catch (final Exception e) { + } catch (final Exception ignored) { } } }; @@ -115,6 +99,17 @@ public abstract class FakeItem extends DisplayItem { registered = true; } + private static void sendChunkPacket(Player p, List fakesInChunk) throws InvocationTargetException { + if (fakesInChunk != null) { + for (final FakeItem fake : fakesInChunk) { + ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getSpawnPacket()); + ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getVelocityPacket()); + ProtocolLibrary.getProtocolManager().sendServerPacket(p, fake.getMetadataPacket()); + } + + } + } + private static String getChunkIdentifyString(final Chunk chunk) { return chunk.getWorld().getName() + "@@" + chunk.getX() + "@@" + chunk.getZ(); } diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Item/NormalItem.java b/src/main/java/org/maxgamer/QuickShop/Shop/Item/NormalItem.java index 2870da5..9e85217 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Item/NormalItem.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Item/NormalItem.java @@ -55,9 +55,7 @@ public class NormalItem extends DisplayItem { */ @Override public void remove() { - if (this.item == null) { - return; - } + if (this.item == null) { return; } this.item.remove(); } @@ -67,9 +65,7 @@ public class NormalItem extends DisplayItem { */ @Override public boolean removeDupe() { - if (shop.getLocation().getWorld() == null) { - return false; - } + if (shop.getLocation().getWorld() == null) { return false; } final Location displayLoc = shop.getLocation().getBlock().getRelative(0, 1, 0).getLocation(); boolean removed = false; final Chunk c = displayLoc.getChunk(); @@ -103,15 +99,13 @@ public class NormalItem extends DisplayItem { */ @Override public void spawn() { - if (shop.getLocation().getWorld() == null) { - return; - } + if (shop.getLocation().getWorld() == null) { return; } final Location dispLoc = this.getDisplayLocation(); try { this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack); this.item.setVelocity(new Vector(0, 0.1, 0)); NMS.safeGuard(this.item); - } catch (final Exception e) { + } catch (final Exception ignored) { } } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/Shop.java b/src/main/java/org/maxgamer/QuickShop/Shop/Shop.java index a6b89f9..121cfb2 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/Shop.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/Shop.java @@ -8,70 +8,70 @@ import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public abstract interface Shop { - public abstract void add(ItemStack paramItemStack, int paramInt); +public interface Shop { + void add(ItemStack paramItemStack, int paramInt); - public abstract void buy(Player paramPlayer, int paramInt); + void buy(Player paramPlayer, int paramInt); - public abstract Shop clone(); + Shop clone(); - public abstract void delete(); + void delete(); - public abstract void delete(boolean paramBoolean); + void delete(boolean paramBoolean); - public abstract String getDataName(); + String getDataName(); - public abstract short getDurability(); + short getDurability(); - public abstract ItemStack getItem(); + ItemStack getItem(); - public abstract Location getLocation(); + Location getLocation(); - public abstract String getOwner(); + String getOwner(); - public abstract double getPrice(); + double getPrice(); - public abstract int getRemainingSpace(); + int getRemainingSpace(); - public abstract int getRemainingStock(); + int getRemainingStock(); - public abstract ShopType getShopType(); + ShopType getShopType(); - public abstract List getSigns(); + List getSigns(); - public abstract boolean isAttached(Block paramBlock); + boolean isAttached(Block paramBlock); - public abstract boolean isBuying(); + boolean isBuying(); - public abstract boolean isSelling(); + boolean isSelling(); - public abstract boolean isUnlimited(); + boolean isUnlimited(); - public abstract boolean isValid(); + boolean isValid(); - public abstract boolean matches(ItemStack paramItemStack); + boolean matches(ItemStack paramItemStack); - public abstract void onClick(); + void onClick(); - public abstract void onLoad(); + void onLoad(); - public abstract void onUnload(); + void onUnload(); - public abstract void remove(ItemStack paramItemStack, int paramInt); + void remove(ItemStack paramItemStack, int paramInt); - public abstract void sell(Player paramPlayer, int paramInt); + void sell(Player paramPlayer, int paramInt); - public abstract void setOwner(String paramString); + void setOwner(String paramString); - public abstract void setPrice(double paramDouble); + void setPrice(double paramDouble); - public abstract void setShopType(ShopType paramShopType); + void setShopType(ShopType paramShopType); - public abstract void setSignText(); + void setSignText(); - public abstract void setSignText(String[] paramArrayOfString); + void setSignText(String[] paramArrayOfString); - public abstract void setUnlimited(boolean paramBoolean); + void setUnlimited(boolean paramBoolean); - public abstract void update(); + void update(); } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ShopAction.java b/src/main/java/org/maxgamer/QuickShop/Shop/ShopAction.java index 7a4d593..55df9da 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ShopAction.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ShopAction.java @@ -3,5 +3,5 @@ package org.maxgamer.QuickShop.Shop; public enum ShopAction { BUY(), CREATE(), - CANCELLED(); + CANCELLED() } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/QuickShop/Shop/ShopType.java b/src/main/java/org/maxgamer/QuickShop/Shop/ShopType.java index 4f3cca6..9e1d387 100644 --- a/src/main/java/org/maxgamer/QuickShop/Shop/ShopType.java +++ b/src/main/java/org/maxgamer/QuickShop/Shop/ShopType.java @@ -5,7 +5,7 @@ public enum ShopType { BUYING(1); private int id; - private ShopType(int id) { + ShopType(int id) { this.id = id; } diff --git a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java index 00b063c..1562c05 100644 --- a/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/QuickShop/Util/MsgUtil.java @@ -88,12 +88,8 @@ public class MsgUtil { public static String p(final String loc, final Object... args) { String raw = messages.getString(loc); - if (raw == null || raw.isEmpty()) { - return ChatColor.RED + "语言文件词条丢失: " + loc; - } - if (args == null) { - return raw; - } + if (raw == null || raw.isEmpty()) { return ChatColor.RED + "语言文件词条丢失: " + loc; } + if (args == null) { return raw; } for (int i = 0; i < args.length; i++) { raw = raw.replace("{" + i + "}", args[i] == null ? "null" : args[i].toString()); } @@ -127,7 +123,7 @@ public class MsgUtil { } msgs.add(message); final String q = "INSERT INTO messages (owner, message, time) VALUES (?, ?, ?)"; - plugin.getDB().execute(q, player.toString(), message, System.currentTimeMillis()); + plugin.getDB().execute(q, player, message, System.currentTimeMillis()); } else { p.getPlayer().sendMessage(message); } @@ -186,10 +182,8 @@ public class MsgUtil { p.sendMessage(""); p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+"); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.shop-information")); - p.sendMessage(ChatColor.DARK_PURPLE - + "| " - + MsgUtil.p("menu.owner", - Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName())); + p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.owner", + Bukkit.getOfflinePlayer(shop.getOwner()).getName() == null ? (shop.isUnlimited() ? "系统商店" : "未知") : Bukkit.getOfflinePlayer(shop.getOwner()).getName())); final String msg = ChatColor.DARK_PURPLE + "| " + MsgUtil.p("menu.item", shop.getDataName()); sendItemMessage(p, shop.getItem(), msg); if (Util.isTool(item.getType())) {