1
0
mirror of https://e.coding.net/circlecloud/RealBackpacks.git synced 2024-12-04 03:49:07 +00:00

move src path...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-09-02 09:39:12 +08:00
parent 360553e25f
commit 81689c97eb
26 changed files with 3467 additions and 3589 deletions

View File

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src"> <classpathentry kind="src" path="src/main/java"/>
<attributes> <classpathentry kind="src" path="src/main/resources"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>

11
pom.xml
View File

@ -1,19 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>cn.CityCraft</groupId> <groupId>cn.citycraft</groupId>
<artifactId>RealBackpacks</artifactId> <artifactId>RealBackpacks</artifactId>
<version>0.1.5-SNAPSHOT</version> <version>0.1.5</version>
<name>RealBackpacks</name> <name>RealBackpacks</name>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>
<resource> <resource>
<directory>src</directory> <directory>src/main/resources</directory>
<excludes> <filtering>true</filtering>
<exclude>**/*.java</exclude>
</excludes>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
@ -51,4 +49,5 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<description>支持数据库的MySQL插件...</description>
</project> </project>

View File

@ -1,177 +0,0 @@
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
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() {
@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);");
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.setString(1, playerName);
state.setString(2, backpack);
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.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization
.listToString(invString));
}
}
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
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())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
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("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
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 = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
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 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);
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;
}
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}

View File

@ -29,9 +29,11 @@ public class MainCommand implements CommandExecutor {
private boolean exist = false; private boolean exist = false;
private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======", private String[] helps = new String[] { "§6====== 真实背包插件 By:喵♂呜 ======",
"§4* §a查看可购买列表 §7/rb list ", "§4* §a购买背包 §7/rb buy <背包名称> ", "§4* §a查看可购买列表 §7/rb list ",
"§4* §a购买背包 §7/rb buy <背包名称> ",
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>", "§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) { public MainCommand(final RealBackpacks plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -41,9 +43,8 @@ public class MainCommand implements CommandExecutor {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (cmd.getName().equalsIgnoreCase("rb")) { if (cmd.getName().equalsIgnoreCase("rb")) {
if (args.length == 0) { if (args.length == 0)
sender.sendMessage(helps); sender.sendMessage(helps);
}
if (args.length >= 1) { if (args.length >= 1) {
final String command = args[0]; final String command = args[0];
if (command.equalsIgnoreCase("reload")) { if (command.equalsIgnoreCase("reload")) {
@ -56,8 +57,7 @@ public class MainCommand implements CommandExecutor {
plugin.setupLists(); plugin.setupLists();
plugin.getServer().resetRecipes(); plugin.getServer().resetRecipes();
plugin.setup(); plugin.setup();
sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW sender.sendMessage(ChatColor.GRAY + "配置文件重载完毕 用时 " + ChatColor.YELLOW + (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
+ (System.currentTimeMillis() - first) + "毫秒" + ChatColor.GRAY + ".");
return true; return true;
} else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) { } else if (command.equalsIgnoreCase("buy") || command.equalsIgnoreCase("purchase")) {
if (!plugin.isUsingVault()) { if (!plugin.isUsingVault()) {
@ -69,8 +69,7 @@ public class MainCommand implements CommandExecutor {
return false; return false;
} }
if (!(args.length == 2)) { if (!(args.length == 2)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb buy <backpack>");
+ " /rb buy <backpack>");
return false; return false;
} }
String backpack = null; String backpack = null;
@ -83,13 +82,11 @@ public class MainCommand implements CommandExecutor {
sender.sendMessage("没有购买的权限."); sender.sendMessage("没有购买的权限.");
return false; return false;
} }
if (plugin.backpackData.get(backpack).get(13) != null if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equals("true")) {
&& !plugin.backpackData.get(backpack).get(13).equals("true")) {
sender.sendMessage("不能被购买."); sender.sendMessage("不能被购买.");
return false; return false;
} }
final double price = Double.parseDouble(plugin.backpackData.get(backpack).get( final double price = Double.parseDouble(plugin.backpackData.get(backpack).get(14));
14));
if (RealBackpacks.econ.getBalance(sender.getName()) < price) { if (RealBackpacks.econ.getBalance(sender.getName()) < price) {
sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包."); sender.sendMessage(ChatColor.RED + "你没有足够的钱购买这个背包.");
return false; return false;
@ -99,31 +96,17 @@ public class MainCommand implements CommandExecutor {
final ItemStack backpackItem = plugin.backpackItems.get(backpack); final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) { if (inv.firstEmpty() != -1) {
RealBackpacks.econ.withdrawPlayer(p.getName(), price); RealBackpacks.econ.withdrawPlayer(p.getName(), price);
if (plugin.backpackData.get(backpack).get(18) != null if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
&& plugin.backpackData.get(backpack).get(18) if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
.equalsIgnoreCase("true")) { inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
if (RealBackpacks.globalGlow else
&& 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); inv.setItem(inv.firstEmpty(), backpackItem);
} } else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
} else {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem)); inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
} else { else
inv.addItem(backpackItem); inv.addItem(backpackItem);
}
}
p.updateInventory(); p.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price + ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
+ ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
return true; return true;
} else { } else {
sender.sendMessage(ChatColor.RED + "你的背包是空的."); sender.sendMessage(ChatColor.RED + "你的背包是空的.");
@ -134,53 +117,32 @@ public class MainCommand implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!"); sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
return false; return false;
} }
sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" sender.sendMessage(ChatColor.LIGHT_PURPLE + " 名称 " + ChatColor.GOLD + "|" + ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN + " 价格 ");
+ ChatColor.AQUA + " 大小 " + ChatColor.GOLD + "|" + ChatColor.GREEN
+ " 价格 ");
sender.sendMessage(ChatColor.GOLD + "-----------------------------------"); sender.sendMessage(ChatColor.GOLD + "-----------------------------------");
if (plugin.isUsingPerms()) { if (plugin.isUsingPerms())
for (final String backpack : plugin.backpacks) { for (final String backpack : plugin.backpacks) {
final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy"); final boolean hasPerm = sender.hasPermission("rb." + backpack + ".buy");
final List<String> key = plugin.backpackData.get(backpack); final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") if (plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
&& hasPerm) { sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14))); + Double.parseDouble(key.get(14)));
} else if (plugin.backpackData.get(backpack).get(13) != null else if (plugin.backpackData.get(backpack).get(13) != null && !plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true") && hasPerm)
&& !plugin.backpackData.get(backpack).get(13) sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
.equalsIgnoreCase("true") && hasPerm) { else
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "没有足够的权限购买");
+ 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 + "没有足够的权限购买");
} }
} else
} else {
for (final String backpack : plugin.backpacks) { for (final String backpack : plugin.backpacks) {
final List<String> key = plugin.backpackData.get(backpack); final List<String> key = plugin.backpackData.get(backpack);
if (plugin.backpackData.get(backpack).get(13) != null if (plugin.backpackData.get(backpack).get(13) != null && plugin.backpackData.get(backpack).get(13).equalsIgnoreCase("true"))
&& plugin.backpackData.get(backpack).get(13) sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.GREEN
.equalsIgnoreCase("true")) {
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.GREEN
+ Double.parseDouble(key.get(14))); + Double.parseDouble(key.get(14)));
} else { else
sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack sender.sendMessage(ChatColor.LIGHT_PURPLE + backpack + ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0) + ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
+ ChatColor.GOLD + " | " + ChatColor.AQUA + key.get(0)
+ ChatColor.GOLD + " | " + ChatColor.RED + "不能购买");
}
}
} }
} else if (command.equalsIgnoreCase("give")) { } else if (command.equalsIgnoreCase("give")) {
if (!(args.length == 3)) { if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY sender.sendMessage(ChatColor.RED + "错误的命令. 正确方式:" + ChatColor.GRAY + " /rb give <玩家> <背包名称>");
+ " /rb give <玩家> <背包名称>");
return false; return false;
} }
String backpack = null; String backpack = null;
@ -201,31 +163,17 @@ public class MainCommand implements CommandExecutor {
final Inventory inv = other.getInventory(); final Inventory inv = other.getInventory();
final ItemStack backpackItem = plugin.backpackItems.get(backpack); final ItemStack backpackItem = plugin.backpackItems.get(backpack);
if (inv.firstEmpty() != -1) { if (inv.firstEmpty() != -1) {
if (plugin.backpackData.get(backpack).get(18) != null if (plugin.backpackData.get(backpack).get(18) != null && plugin.backpackData.get(backpack).get(18).equalsIgnoreCase("true")) {
&& plugin.backpackData.get(backpack).get(18) if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
.equalsIgnoreCase("true")) { inv.setItem(inv.firstEmpty(), RealBackpacks.NMS.addGlow(backpackItem));
if (RealBackpacks.globalGlow else
&& 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); inv.setItem(inv.firstEmpty(), backpackItem);
} } else if (RealBackpacks.globalGlow && plugin.backpackData.get(backpack).get(17) != null && plugin.backpackData.get(backpack).get(17).equalsIgnoreCase("true"))
} else {
if (RealBackpacks.globalGlow
&& plugin.backpackData.get(backpack).get(17) != null
&& plugin.backpackData.get(backpack).get(17)
.equalsIgnoreCase("true")) {
inv.addItem(RealBackpacks.NMS.addGlow(backpackItem)); inv.addItem(RealBackpacks.NMS.addGlow(backpackItem));
} else { else
inv.addItem(backpackItem); inv.addItem(backpackItem);
}
}
other.updateInventory(); other.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack + ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
+ ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
return true; return true;
} else { } else {
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了"); sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
@ -240,71 +188,55 @@ public class MainCommand implements CommandExecutor {
if (!MysqlFunctions.checkIfTableExists("rb_data")) { if (!MysqlFunctions.checkIfTableExists("rb_data")) {
MysqlFunctions.createTables(); MysqlFunctions.createTables();
exist = false; exist = false;
} else { } else
exist = true; exist = true;
}
try { try {
final Connection conn = DriverManager.getConnection( final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass());
plugin.getUrl(), plugin.getUser(), plugin.getPass()); final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
final File dir = new File(plugin.getDataFolder() + File.separator int i = 0, times = 0;
+ "userdata");
int i = 0,times = 0;
final int files = dir.listFiles().length; final int files = dir.listFiles().length;
for (final File child : dir.listFiles()) { for (final File child : dir.listFiles()) {
final String player = child.getName().replace(".yml", ""); final String player = child.getName().replace(".yml", "");
final FileConfig config = PlayerConfig.getInstance(plugin, final FileConfig config = PlayerConfig.getInstance(plugin, player);
player);
i++; i++;
PreparedStatement statement = null; PreparedStatement statement = null;
PreparedStatement state = null; PreparedStatement state = null;
for (final String backpack : config.getConfigurationSection("") for (final String backpack : config.getConfigurationSection("").getKeys(false)) {
.getKeys(false)) {
if (exist) { if (exist) {
statement = conn statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
statement.setString(1, player); statement.setString(1, player);
statement.setString(2, backpack); statement.setString(2, backpack);
final ResultSet res = statement.executeQuery(); final ResultSet res = statement.executeQuery();
if (res.next()) { if (res.next())
if (res.getInt(1) == 1) { if (res.getInt(1) == 1) {
state = conn state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
state.setString(1, player); state.setString(1, player);
state.setString(2, backpack); state.setString(2, backpack);
state.setString(3, Serialization state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
.listToString(config
.getStringList(backpack
+ ".Inventory")));
state.setString(4, player); state.setString(4, player);
state.setString(5, backpack); state.setString(5, backpack);
} else { } else {
state = conn state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player); state.setString(1, player);
state.setString(2, backpack); state.setString(2, backpack);
state.setString(3, Serialization state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
.listToString(config
.getStringList(backpack
+ ".Inventory")));
}
} }
} else { } else {
state = conn state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
state.setString(1, player); state.setString(1, player);
state.setString(2, backpack); state.setString(2, backpack);
state.setString(3, Serialization.listToString(config state.setString(3, Serialization.listToString(config.getStringList(backpack + ".Inventory")));
.getStringList(backpack + ".Inventory")));
} }
if (state != null) {
state.executeUpdate(); state.executeUpdate();
state.close(); state.close();
} }
}
if (i == 50) { if (i == 50) {
i = 0; i = 0;
times++; times++;
sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 sender.sendMessage(ChatColor.LIGHT_PURPLE + "" + times * 50 + "/" + files + " files have been transferred.");
+ "/" + files + " files have been transferred.");
} }
} }
conn.close(); conn.close();
@ -316,19 +248,17 @@ public class MainCommand implements CommandExecutor {
}); });
} else if (command.equalsIgnoreCase("view")) { } else if (command.equalsIgnoreCase("view")) {
if (!(args.length == 3)) { if (!(args.length == 3)) {
sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY sender.sendMessage(ChatColor.RED + "命令错误. 正确命令:" + ChatColor.GRAY + " /rb view <player> <backpack>");
+ " /rb view <player> <backpack>");
return false; return false;
} }
String backpack = null; String backpack = null;
backpack = RBUtil.stringToBackpack(args[2]); backpack = RBUtil.stringToBackpack(args[2]);
boolean fullview = false; boolean fullview = false;
boolean restrictedview = false; boolean restrictedview = false;
if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview")) { if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview"))
fullview = true; fullview = true;
} else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview")) { else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview"))
restrictedview = true; restrictedview = true;
}
if (plugin.isUsingPerms() && !fullview && !restrictedview) { if (plugin.isUsingPerms() && !fullview && !restrictedview) {
sender.sendMessage(ChatColor.RED + "没有足够的权限购买"); sender.sendMessage(ChatColor.RED + "没有足够的权限购买");
return false; return false;
@ -344,8 +274,7 @@ public class MainCommand implements CommandExecutor {
if (!plugin.isUsingMysql()) { if (!plugin.isUsingMysql()) {
boolean fileExists = false; boolean fileExists = false;
String fullName = null; String fullName = null;
final File dir = new File(plugin.getDataFolder() + File.separator final File dir = new File(plugin.getDataFolder() + File.separator + "userdata");
+ "userdata");
for (final File f : dir.listFiles()) { for (final File f : dir.listFiles()) {
final String fileName = f.getName(); final String fileName = f.getName();
fullName = fileName.replace(".yml", ""); fullName = fileName.replace(".yml", "");
@ -360,17 +289,10 @@ public class MainCommand implements CommandExecutor {
return false; return false;
} }
final FileConfig config = PlayerConfig.getInstance(plugin, fullName); final FileConfig config = PlayerConfig.getInstance(plugin, fullName);
if (config.getStringList(backpack + ".Inventory") == null) { if (config.getStringList(backpack + ".Inventory") == null)
inv = plugin.getServer().createInventory( inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', fullName + "'s " + backpack + " data"));
p, else
Integer.parseInt(key.get(0)), inv = Serialization.toInventory(config.getStringList(backpack + ".Inventory"), fullName + "'s " + backpack + " data", 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)));
}
} else { } else {
try { try {
inv = MysqlFunctions.getBackpackInv(name, backpack); inv = MysqlFunctions.getBackpackInv(name, backpack);
@ -386,11 +308,10 @@ public class MainCommand implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭."); sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭.");
return false; return false;
} }
if (fullview || !plugin.isUsingPerms()) { if (fullview || !plugin.isUsingPerms())
plugin.adminFullView.put(sender.getName(), backpack + ":" + name); plugin.adminFullView.put(sender.getName(), backpack + ":" + name);
} else { else
plugin.adminRestrictedView.add(sender.getName()); plugin.adminRestrictedView.add(sender.getName());
}
p.openInventory(inv); p.openInventory(inv);
} else { } else {
sender.sendMessage(ChatColor.RED + "命令未找到."); sender.sendMessage(ChatColor.RED + "命令未找到.");

View File

@ -0,0 +1,138 @@
package cn.citycraft.RealBackpacks.util;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.inventory.Inventory;
import cn.citycraft.RealBackpacks.RealBackpacks;
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() {
@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);");
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.setString(1, playerName);
state.setString(2, backpack);
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.setString(1, playerName);
state.setString(2, backpack);
state.setString(3, Serialization.listToString(invString));
}
if (state != null) {
state.executeUpdate();
state.close();
}
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
public static boolean checkIfTableExists(final String table) {
try {
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())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
return false;
}
public static void createTables() {
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("CREATE TABLE rb_data (player VARCHAR(16), backpack VARCHAR(20), inventory TEXT)ENGINE=InnoDB DEFAULT CHARSET=UTF8;");
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
public static void delete(final String playerName, final String backpack) {
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 = ?;");
state.setString(1, playerName);
state.setString(2, backpack);
state.executeUpdate();
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
}
});
}
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 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);
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)));
}
state.close();
conn.close();
} catch (final SQLException e) {
e.printStackTrace();
}
return returnInv;
}
public static void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}

View File

@ -1,8 +1,9 @@
name: RealBackpacks name: ${project.artifactId}
main: cn.citycraft.RealBackpacks.RealBackpacks description: ${project.description}
version: 0.1.5 main: ${project.groupId}.${project.artifactId}.${project.artifactId}
website: http://ci.citycraft.cn:8800/jenkins/job/RealBackpacks/ website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
author: Slayr288,喵♂呜 version: ${project.version}
authors: [喵♂呜]
softdepend: [Vault] softdepend: [Vault]
commands: commands:
rb: rb: