diff --git a/pom.xml b/pom.xml index 0ccba8a..cc30412 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 cn.CityCraft RealBackpacks - 0.1.2-SNAPSHOT + 0.1.3-SNAPSHOT RealBackpacks src diff --git a/src/cn/citycraft/plugins/RealBackpacks.java b/src/cn/citycraft/plugins/RealBackpacks.java index 6f0168c..d2adc15 100644 --- a/src/cn/citycraft/plugins/RealBackpacks.java +++ b/src/cn/citycraft/plugins/RealBackpacks.java @@ -122,9 +122,11 @@ public class RealBackpacks extends JavaPlugin { new InventoryListener(this), this); getServer().getPluginManager().registerEvents( new EntityListener(this), this); - getCommand("rb").setExecutor(new MainCommand(this)); getServer().getScheduler().runTaskTimer(this, new WalkSpeedRunnable(this), 20, 20); + + getCommand("rb").setExecutor(new MainCommand(this)); + getLogger().info("真实背包已加载 By: 喵♂呜."); } } diff --git a/src/cn/citycraft/plugins/listeners/InventoryListener.java b/src/cn/citycraft/plugins/listeners/InventoryListener.java index f223655..5854fad 100644 --- a/src/cn/citycraft/plugins/listeners/InventoryListener.java +++ b/src/cn/citycraft/plugins/listeners/InventoryListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import cn.citycraft.plugins.RealBackpacks; import cn.citycraft.plugins.util.MysqlFunctions; @@ -193,8 +194,8 @@ public class InventoryListener implements Listener { if (potentialBackpack != null && plugin.backpackItems .containsKey(potentialBackpack)) { - if (curItem.isSimilar(plugin.backpackItems - .get(potentialBackpack))) { + if (isSimilar(curItem, + plugin.backpackItems.get(potentialBackpack))) { e.setCancelled(true); p.sendMessage(ChatColor.RED + "当前物品不能放入背包..."); return; @@ -235,4 +236,44 @@ public class InventoryListener implements Listener { } } + + @SuppressWarnings("deprecation") + public boolean isSimilar(ItemStack origin, ItemStack compare) { + if (compare == null) { + return false; + } + if (compare == origin) { + return true; + } + return compare.getTypeId() == origin.getTypeId() + && compare.getDurability() == origin.getDurability() + && compare.hasItemMeta() == origin.hasItemMeta() + && (compare.hasItemMeta() ? isSimilarMeta( + compare.getItemMeta(), origin.getItemMeta()) : true); + } + + public boolean isSimilarMeta(ItemMeta origin, ItemMeta compare) { + if (origin.hasDisplayName() != compare.hasDisplayName()) + return false; + if (origin.hasEnchants() != compare.hasEnchants()) + return false; + if (origin.hasLore() != compare.hasLore()) + return false; + + if (origin.hasDisplayName() && compare.hasDisplayName()) { + if (!origin.getDisplayName().equals(compare.getDisplayName())) + return false; + } + if (origin.hasEnchants() && compare.hasEnchants()) { + if (!origin.getEnchants().equals(compare.getEnchants())) + return false; + } + if (origin.hasLore() && compare.hasLore()) { + if (!(origin.getLore().containsAll(compare.getLore()) || compare + .getLore().containsAll(origin.getLore()))) + return false; + } + return true; + } + } diff --git a/src/cn/citycraft/plugins/util/MysqlFunctions.java b/src/cn/citycraft/plugins/util/MysqlFunctions.java index d7ed0e4..9a74ba4 100644 --- a/src/cn/citycraft/plugins/util/MysqlFunctions.java +++ b/src/cn/citycraft/plugins/util/MysqlFunctions.java @@ -24,7 +24,10 @@ public class MysqlFunctions { public static boolean checkIfTableExists(final String table) { try { - final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); + //final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); + String url = plugin.getUrl()+"?" + + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; + final Connection conn = DriverManager.getConnection(url); final Statement state = conn.createStatement(); final DatabaseMetaData dbm = conn.getMetaData(); final ResultSet tables = dbm.getTables(null, null, "rb_data", null); @@ -43,8 +46,10 @@ public class MysqlFunctions { public static void createTables() { try { - final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); - final PreparedStatement state = conn.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT);"); + String url = plugin.getUrl()+"?" + + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; + final Connection conn = DriverManager.getConnection(url); + final PreparedStatement state = conn.prepareStatement("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;"); state.executeUpdate(); state.close(); conn.close(); @@ -58,7 +63,9 @@ public class MysqlFunctions { @Override public void run() { try { - final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); + String url = plugin.getUrl()+"?" + + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; + final Connection conn = DriverManager.getConnection(url); PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);"); statement.setString(1, playerName); statement.setString(2, backpack); @@ -92,7 +99,9 @@ public class MysqlFunctions { public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException { Inventory returnInv = null; try { - final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); + String url = plugin.getUrl()+"?" + + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; + final Connection conn = DriverManager.getConnection(url); final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;"); state.setString(1, playerName); state.setString(2, backpack); @@ -118,7 +127,9 @@ public class MysqlFunctions { @Override public void run() { try { - final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); + String url = plugin.getUrl()+"?" + + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; + final Connection conn = DriverManager.getConnection(url); final PreparedStatement state = conn.prepareStatement("DELETE FROM rb_data WHERE player = ? AND backpack = ?;"); state.setString(1, playerName); state.setString(2, backpack); diff --git a/src/plugin.yml b/src/plugin.yml index a1a4276..2538eff 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -2,9 +2,9 @@ name: RealBackpacks main: cn.citycraft.plugins.RealBackpacks version: 1.6.5 author: Slayr288,喵♂呜 -softdepend: [Vault] +softdepend: [Vault,BVLib] commands: - rb: + rb: description: Main commands. aliases: [realbackpacks, realb, rbs] permissions: