mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2025-11-24 21:36:12 +00:00
@@ -28,10 +28,12 @@ public class MainCommand implements CommandExecutor {
|
||||
|
||||
private boolean exist = false;
|
||||
|
||||
private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
|
||||
"§4* §a查看可购买列表 §7/rb list ", "§4* §a购买背包 §7/rb buy <背包名称> ",
|
||||
private final String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
|
||||
"§4* §a查看可购买列表 §7/rb list ",
|
||||
"§4* §a购买背包 §7/rb buy <背包名称> ",
|
||||
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>",
|
||||
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>", "§4* §a数据转移至MySQL §7/rb filetomysql" };
|
||||
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>",
|
||||
"§4* §a数据转移至MySQL §7/rb filetomysql" };
|
||||
|
||||
public MainCommand(final RealBackpacks plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -56,8 +58,7 @@ public class MainCommand implements CommandExecutor {
|
||||
plugin.setupLists();
|
||||
plugin.getServer().resetRecipes();
|
||||
plugin.setup();
|
||||
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW
|
||||
+ (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
|
||||
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW + (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
|
||||
return true;
|
||||
} else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) {
|
||||
if (!plugin.isUsingVault()) {
|
||||
@@ -69,8 +70,7 @@ public class MainCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
if (!(args.length == 2)) {
|
||||
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY
|
||||
+ " /rb buy <backpack>");
|
||||
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb buy <backpack>");
|
||||
return false;
|
||||
}
|
||||
String backpack = null;
|
||||
@@ -83,13 +83,11 @@ public class MainCommand implements CommandExecutor {
|
||||
sender.sendMessage("没有购买的权限.");
|
||||
return false;
|
||||
}
|
||||
if (plugin.backpackData.get(backpack).get(13) != null
|
||||
&& !plugin.backpackData.get(backpack).get(13).equals("true")) {
|
||||
if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equals("true")) {
|
||||
sender.sendMessage("不能被购买.");
|
||||
return false;
|
||||
}
|
||||
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(
|
||||
14));
|
||||
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(14));
|
||||
if (RealBackpacks.econ.getBalance(sender.getName()) < price) {
|
||||
sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包.");
|
||||
return false;
|
||||
@@ -99,31 +97,21 @@ public class MainCommand implements CommandExecutor {
|
||||
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
||||
if (inv.firstEmpty() != -1) {
|
||||
RealBackpacks.econ.withdrawPlayer(p.getName(), price);
|
||||
if (plugin.backpackData.get(backpack).get(18) != null
|
||||
&& plugin.backpackData.get(backpack).get(18)
|
||||
.equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow
|
||||
&& plugin.backpackData.get(backpack).get(17) != null
|
||||
&& plugin.backpackData.get(backpack).get(17)
|
||||
.equalsIgnoreCase("true")) {
|
||||
inv.setItem(inv.firstEmpty(),
|
||||
RealBackpacks.NMS.addGlow(backpackItem));
|
||||
if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
|
||||
inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
|
||||
} else {
|
||||
inv.setItem(inv.firstEmpty(), backpackItem);
|
||||
}
|
||||
} else {
|
||||
if (RealBackpacks.globalGlow
|
||||
&& plugin.backpackData.get(backpack).get(17) != null
|
||||
&& plugin.backpackData.get(backpack).get(17)
|
||||
.equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
|
||||
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
|
||||
} else {
|
||||
inv.addItem(backpackItem);
|
||||
}
|
||||
}
|
||||
p.updateInventory();
|
||||
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price
|
||||
+ ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
|
||||
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price + ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "你的背包是空的.");
|
||||
@@ -134,53 +122,35 @@ public class MainCommand implements CommandExecutor {
|
||||
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
|
||||
return false;
|
||||
}
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|"
|
||||
+ ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN
|
||||
+ " 价格 ");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" + ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN + " 价格 ");
|
||||
sender.sendMessage(ChatColor.GOLD + "-----------------------------------");
|
||||
if (plugin.isUsingPerms()) {
|
||||
for (final String backpack : plugin.backpacks) {
|
||||
final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy");
|
||||
final List<String> key = plugin.backpackData.get(backpack);
|
||||
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true")
|
||||
&& hasPerm) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
|
||||
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
|
||||
+ ChatColor.GOLD + " | " + ChatColor.GREEN
|
||||
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
|
||||
+ Double.parseDouble(key.get(14)));
|
||||
} else if (plugin.backpackData.get(backpack).get(13) != null
|
||||
&& !plugin.backpackData.get(backpack).get(13)
|
||||
.equalsIgnoreCase("true") && hasPerm) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
|
||||
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
|
||||
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
|
||||
} else if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
|
||||
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
|
||||
+ ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (final String backpack : plugin.backpacks) {
|
||||
final List<String> key = plugin.backpackData.get(backpack);
|
||||
if (plugin.backpackData.get(backpack).get(13) != null
|
||||
&& plugin.backpackData.get(backpack).get(13)
|
||||
.equalsIgnoreCase("true")) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
|
||||
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
|
||||
+ ChatColor.GOLD + " | " + ChatColor.GREEN
|
||||
if (plugin.backpackData.get(backpack).get(13) != null && plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true")) {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
|
||||
+ Double.parseDouble(key.get(14)));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
|
||||
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
|
||||
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (command.equalsIgnoreCase("give")) {
|
||||
if (!(args.length == 3)) {
|
||||
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY
|
||||
+ " /rb give <玩家> <背包名称>");
|
||||
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY + " /rb give <玩家> <背包名称>");
|
||||
return false;
|
||||
}
|
||||
String backpack = null;
|
||||
@@ -201,39 +171,30 @@ public class MainCommand implements CommandExecutor {
|
||||
final Inventory inv = other.getInventory();
|
||||
final ItemStack backpackItem = plugin.backpackItems.get(backpack);
|
||||
if (inv.firstEmpty() != -1) {
|
||||
if (plugin.backpackData.get(backpack).get(18) != null
|
||||
&& plugin.backpackData.get(backpack).get(18)
|
||||
.equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow
|
||||
&& plugin.backpackData.get(backpack).get(17) != null
|
||||
&& plugin.backpackData.get(backpack).get(17)
|
||||
.equalsIgnoreCase("true")) {
|
||||
inv.setItem(inv.firstEmpty(),
|
||||
RealBackpacks.NMS.addGlow(backpackItem));
|
||||
if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
|
||||
inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
|
||||
} else {
|
||||
inv.setItem(inv.firstEmpty(), backpackItem);
|
||||
}
|
||||
} else {
|
||||
if (RealBackpacks.globalGlow
|
||||
&& plugin.backpackData.get(backpack).get(17) != null
|
||||
&& plugin.backpackData.get(backpack).get(17)
|
||||
.equalsIgnoreCase("true")) {
|
||||
if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true")) {
|
||||
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
|
||||
} else {
|
||||
inv.addItem(backpackItem);
|
||||
}
|
||||
}
|
||||
other.updateInventory();
|
||||
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack
|
||||
+ ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
|
||||
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack + ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
|
||||
return false;
|
||||
}
|
||||
} else if (command.equalsIgnoreCase("filetomysql")) {
|
||||
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql"))
|
||||
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql")) {
|
||||
return false;
|
||||
}
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -244,67 +205,53 @@ public class MainCommand implements CommandExecutor {
|
||||
exist = true;
|
||||
}
|
||||
try {
|
||||
final Connection conn = DriverManager.getConnection(
|
||||
plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
||||
final File dir = new File(plugin.getDataFolder() + File.separator
|
||||
+ "userdata");
|
||||
final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
|
||||
final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
|
||||
int i = 0, times = 0;
|
||||
final int files = dir.listFiles().length;
|
||||
for (final File child : dir.listFiles()) {
|
||||
final String player = child.getName().replace(".yml", "");
|
||||
final FileConfig config = PlayerConfig.getInstance(plugin,
|
||||
player);
|
||||
final FileConfig config = PlayerConfig.getInstance(plugin, player);
|
||||
|
||||
i++;
|
||||
PreparedStatement statement = null;
|
||||
PreparedStatement state = null;
|
||||
for (final String backpack : config.getConfigurationSection("")
|
||||
.getKeys(false)) {
|
||||
for (final String backpack : config.getConfigurationSection("").getKeys(false)) {
|
||||
if (exist) {
|
||||
statement = conn
|
||||
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
||||
statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
||||
statement.setString(1, player);
|
||||
statement.setString(2, backpack);
|
||||
final ResultSet res = statement.executeQuery();
|
||||
if (res.next()) {
|
||||
if (res.getInt(1) == 1) {
|
||||
state = conn
|
||||
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||
state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||
state.setString(1, player);
|
||||
state.setString(2, backpack);
|
||||
state.setString(3, Serialization
|
||||
.listToString(config
|
||||
.getStringList(backpack
|
||||
+ ".Inventory")));
|
||||
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
|
||||
state.setString(4, player);
|
||||
state.setString(5, backpack);
|
||||
} else {
|
||||
state = conn
|
||||
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state.setString(1, player);
|
||||
state.setString(2, backpack);
|
||||
state.setString(3, Serialization
|
||||
.listToString(config
|
||||
.getStringList(backpack
|
||||
+ ".Inventory")));
|
||||
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
state = conn
|
||||
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state.setString(1, player);
|
||||
state.setString(2, backpack);
|
||||
state.setString(3, Serialization.listToString(config
|
||||
.getStringList(backpack + ".Inventory")));
|
||||
state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
|
||||
}
|
||||
if (state != null) {
|
||||
state.executeUpdate();
|
||||
state.close();
|
||||
}
|
||||
}
|
||||
if (i == 50) {
|
||||
i = 0;
|
||||
times++;
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50
|
||||
+ "/" + files + " files have been transferred.");
|
||||
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 + "/" + files + " files have been transferred.");
|
||||
}
|
||||
}
|
||||
conn.close();
|
||||
@@ -316,8 +263,7 @@ public class MainCommand implements CommandExecutor {
|
||||
});
|
||||
} else if (command.equalsIgnoreCase("view")) {
|
||||
if (!(args.length == 3)) {
|
||||
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY
|
||||
+ " /rb view <player> <backpack>");
|
||||
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb view <player> <backpack>");
|
||||
return false;
|
||||
}
|
||||
String backpack = null;
|
||||
@@ -344,8 +290,7 @@ public class MainCommand implements CommandExecutor {
|
||||
if (!plugin.isUsingMysql()) {
|
||||
boolean fileExists = false;
|
||||
String fullName = null;
|
||||
final File dir = new File(plugin.getDataFolder() + File.separator
|
||||
+ "userdata");
|
||||
final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
|
||||
for (final File f : dir.listFiles()) {
|
||||
final String fileName = f.getName();
|
||||
fullName = fileName.replace(".yml", "");
|
||||
@@ -361,15 +306,9 @@ public class MainCommand implements CommandExecutor {
|
||||
}
|
||||
final FileConfig config = PlayerConfig.getInstance(plugin, fullName);
|
||||
if (config.getStringList(backpack + ".Inventory") == null) {
|
||||
inv = plugin.getServer().createInventory(
|
||||
p,
|
||||
Integer.parseInt(key.get(0)),
|
||||
ChatColor.translateAlternateColorCodes('&', fullName + "'s "
|
||||
+ backpack + " data"));
|
||||
inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', fullName + "'s " + backpack + " data"));
|
||||
} else {
|
||||
inv = Serialization.toInventory(
|
||||
config.getStringList(backpack + ".Inventory"), fullName + "'s "
|
||||
+ backpack + " data", Integer.parseInt(key.get(0)));
|
||||
inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), fullName + "'s " + backpack + " data", Integer.parseInt(key.get(0)));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
||||
@@ -29,38 +29,43 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSimilar(ItemStack origin, ItemStack compare) {
|
||||
if (compare == null)
|
||||
public boolean isSimilar(final ItemStack origin, final ItemStack compare) {
|
||||
if (compare == null) {
|
||||
return false;
|
||||
if (compare == origin)
|
||||
}
|
||||
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);
|
||||
}
|
||||
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())
|
||||
public boolean isSimilarMeta(final ItemMeta origin, final ItemMeta compare) {
|
||||
if (origin.hasDisplayName() != compare.hasDisplayName()) {
|
||||
return false;
|
||||
if (origin.hasEnchants() != compare.hasEnchants())
|
||||
}
|
||||
if (origin.hasEnchants() != compare.hasEnchants()) {
|
||||
return false;
|
||||
if (origin.hasLore() != compare.hasLore())
|
||||
}
|
||||
if (origin.hasLore() != compare.hasLore()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (origin.hasDisplayName() && compare.hasDisplayName()) {
|
||||
if (!origin.getDisplayName().equals(compare.getDisplayName()))
|
||||
if (!origin.getDisplayName().equals(compare.getDisplayName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (origin.hasEnchants() && compare.hasEnchants()) {
|
||||
if (!origin.getEnchants().equals(compare.getEnchants()))
|
||||
if (!origin.getEnchants().equals(compare.getEnchants())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (origin.hasLore() && compare.hasLore()) {
|
||||
if (!(compare.getLore().containsAll(origin.getLore())))
|
||||
if (!(compare.getLore().containsAll(origin.getLore()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -108,18 +113,14 @@ public class InventoryListener implements Listener {
|
||||
if (whitelist == null) {
|
||||
continue;
|
||||
}
|
||||
String potentialBackpack = RBUtil.stringToBackpack(whitelist);
|
||||
if (potentialBackpack != null
|
||||
&& plugin.backpackItems.containsKey(potentialBackpack)) {
|
||||
if (curItem.isSimilar(plugin.backpackItems.get(potentialBackpack))
|
||||
|| cursor.isSimilar(plugin.backpackItems
|
||||
.get(potentialBackpack))) {
|
||||
final String potentialBackpack = RBUtil.stringToBackpack(whitelist);
|
||||
if (potentialBackpack != null && plugin.backpackItems.containsKey(potentialBackpack)) {
|
||||
if (curItem.isSimilar(plugin.backpackItems.get(potentialBackpack)) || cursor.isSimilar(plugin.backpackItems.get(potentialBackpack))) {
|
||||
go = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (RBUtil.itemsAreEqual(curItem, whitelist)
|
||||
|| RBUtil.itemsAreEqual(cursor, whitelist)) {
|
||||
if (RBUtil.itemsAreEqual(curItem, whitelist) || RBUtil.itemsAreEqual(cursor, whitelist)) {
|
||||
go = false;
|
||||
break;
|
||||
}
|
||||
@@ -136,9 +137,8 @@ public class InventoryListener implements Listener {
|
||||
if (blacklist == null) {
|
||||
continue;
|
||||
}
|
||||
String potentialBackpack = RBUtil.stringToBackpack(blacklist);
|
||||
if (potentialBackpack != null
|
||||
&& plugin.backpackItems.containsKey(potentialBackpack)) {
|
||||
final String potentialBackpack = RBUtil.stringToBackpack(blacklist);
|
||||
if (potentialBackpack != null && plugin.backpackItems.containsKey(potentialBackpack)) {
|
||||
if (isSimilar(curItem, plugin.backpackItems.get(potentialBackpack))) {
|
||||
e.setCancelled(true);
|
||||
p.sendMessage(ChatColor.RED + "当前物品不能放入背包...");
|
||||
@@ -155,24 +155,6 @@ public class InventoryListener implements Listener {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Dupes for (String backpack : plugin.backpackItems.keySet()) { if
|
||||
* (p.getInventory().contains(plugin.backpackItems.get(backpack))) {
|
||||
* plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
*
|
||||
* @Override public void run() { Location loc = p.getLocation(); World world =
|
||||
* p.getWorld(); for (ItemStack item : p.getInventory().getContents()) { if (item !=
|
||||
* null && item.hasItemMeta() && item.getAmount() > 1) { for (String backpack :
|
||||
* plugin.backpacks) { String unstackable = plugin.backpackData.get(backpack).get(18);
|
||||
* if (unstackable == null || unstackable.equalsIgnoreCase("false")) { continue; } if
|
||||
* (item.isSimilar(plugin.backpackItems.get(backpack))) { while (item.getAmount() > 1) {
|
||||
* item.setAmount(item.getAmount() - 1); if (p.getInventory().firstEmpty() != -1) {
|
||||
* p.getInventory().setItem(p.getInventory().firstEmpty(), item); p.updateInventory(); }
|
||||
* else { world.dropItemNaturally(loc, plugin.backpackItems.get(backpack)); } } } } } }
|
||||
* } }, 2L); break; } }
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +178,7 @@ public class InventoryListener implements Listener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory",
|
||||
invString);
|
||||
PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory", invString);
|
||||
PlayerConfig.save();
|
||||
}
|
||||
}
|
||||
@@ -214,8 +195,7 @@ public class InventoryListener implements Listener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
PlayerConfig.getInstance(plugin, split[1]).set(split[0] + ".Inventory",
|
||||
invString);
|
||||
PlayerConfig.getInstance(plugin, split[1]).set(split[0] + ".Inventory", invString);
|
||||
PlayerConfig.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,50 +18,37 @@ public class MysqlFunctions {
|
||||
|
||||
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
|
||||
|
||||
public static void addBackpackData(final String playerName,
|
||||
final String backpack, final List<String> invString)
|
||||
throws SQLException {
|
||||
plugin.getServer().getScheduler()
|
||||
.runTaskAsynchronously(plugin, new Runnable() {
|
||||
public static void addBackpackData(final String playerName, final String backpack, final List<String> invString) throws SQLException {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
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);");
|
||||
final String url = plugin.getUrl() + "?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
||||
final Connection conn = DriverManager.getConnection(url);
|
||||
final 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);
|
||||
final ResultSet res = statement.executeQuery();
|
||||
PreparedStatement state = null;
|
||||
if (res.next()) {
|
||||
if (res.getInt(1) == 1) {
|
||||
state = conn
|
||||
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||
state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||
state.setString(1, playerName);
|
||||
state.setString(2, backpack);
|
||||
state.setString(3, Serialization
|
||||
.listToString(invString));
|
||||
state.setString(3, Serialization.listToString(invString));
|
||||
state.setString(4, playerName);
|
||||
state.setString(5, backpack);
|
||||
} else {
|
||||
state = conn
|
||||
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||
state.setString(1, playerName);
|
||||
state.setString(2, backpack);
|
||||
state.setString(3, Serialization
|
||||
.listToString(invString));
|
||||
state.setString(3, Serialization.listToString(invString));
|
||||
}
|
||||
}
|
||||
if (state != null) {
|
||||
state.executeUpdate();
|
||||
state.close();
|
||||
}
|
||||
conn.close();
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
@@ -72,19 +59,18 @@ public class MysqlFunctions {
|
||||
|
||||
public static boolean checkIfTableExists(final String table) {
|
||||
try {
|
||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||
+ "&password=" + plugin.getPass()
|
||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||
final 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);
|
||||
state.close();
|
||||
conn.close();
|
||||
if (tables.next())
|
||||
if (tables.next()) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -93,12 +79,9 @@ public class MysqlFunctions {
|
||||
|
||||
public static void createTables() {
|
||||
try {
|
||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||
+ "&password=" + plugin.getPass()
|
||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||
final 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;");
|
||||
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();
|
||||
@@ -108,22 +91,13 @@ public class MysqlFunctions {
|
||||
}
|
||||
|
||||
public static void delete(final String playerName, final String backpack) {
|
||||
plugin.getServer().getScheduler()
|
||||
.runTaskAsynchronously(plugin, new Runnable() {
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
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 = ?;");
|
||||
final 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);
|
||||
state.executeUpdate();
|
||||
@@ -136,30 +110,20 @@ public class MysqlFunctions {
|
||||
});
|
||||
}
|
||||
|
||||
public static Inventory getBackpackInv(final String playerName,
|
||||
final String backpack) throws SQLException {
|
||||
public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException {
|
||||
Inventory returnInv = null;
|
||||
try {
|
||||
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||
+ "&password=" + plugin.getPass()
|
||||
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||
final 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;");
|
||||
final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
||||
state.setString(1, playerName);
|
||||
state.setString(2, backpack);
|
||||
final ResultSet res = state.executeQuery();
|
||||
if (res.next()) {
|
||||
final String invString = res.getString(1);
|
||||
if (invString != null) {
|
||||
returnInv = Serialization.toInventory(Serialization
|
||||
.stringToList(invString), ChatColor
|
||||
.translateAlternateColorCodes('&',
|
||||
plugin.backpackData.get(backpack).get(3)),
|
||||
Integer.parseInt(plugin.backpackData.get(backpack)
|
||||
.get(0)));
|
||||
} else {
|
||||
returnInv = null;
|
||||
returnInv = Serialization.toInventory(Serialization.stringToList(invString), ChatColor.translateAlternateColorCodes('&', plugin.backpackData.get(backpack).get(3)),
|
||||
Integer.parseInt(plugin.backpackData.get(backpack).get(0)));
|
||||
}
|
||||
}
|
||||
state.close();
|
||||
|
||||
Reference in New Issue
Block a user