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"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<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"
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>
<groupId>cn.CityCraft</groupId>
<groupId>cn.citycraft</groupId>
<artifactId>RealBackpacks</artifactId>
<version>0.1.5-SNAPSHOT</version>
<version>0.1.5</version>
<name>RealBackpacks</name>
<build>
<finalName>${project.name}</finalName>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
@ -51,4 +49,5 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>支持数据库的MySQL插件...</description>
</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 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 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;
@ -41,9 +43,8 @@ public class MainCommand implements CommandExecutor {
@SuppressWarnings("deprecation")
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (cmd.getName().equalsIgnoreCase("rb")) {
if (args.length == 0) {
if (args.length == 0)
sender.sendMessage(helps);
}
if (args.length >= 1) {
final String command = args[0];
if (command.equalsIgnoreCase("reload")) {
@ -56,8 +57,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 +69,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 +82,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 +96,17 @@ 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));
} else {
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")) {
} 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));
} else {
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 +117,32 @@ 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()) {
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 {
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 + "没有足够的权限购买");
}
}
} else {
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 + "不能购买");
}
}
else
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,31 +163,17 @@ 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));
} else {
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")) {
} 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));
} else {
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() + "的背包已经满了");
@ -240,71 +188,55 @@ public class MainCommand implements CommandExecutor {
if (!MysqlFunctions.checkIfTableExists("rb_data")) {
MysqlFunctions.createTables();
exist = false;
} else {
} else
exist = true;
}
try {
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 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.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,19 +248,17 @@ 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;
backpack = RBUtil.stringToBackpack(args[2]);
boolean fullview = false;
boolean restrictedview = false;
if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview")) {
if (plugin.isUsingPerms() && sender.hasPermission("rb.fullview"))
fullview = true;
} else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview")) {
else if (plugin.isUsingPerms() && sender.hasPermission("rb.restrictedview"))
restrictedview = true;
}
if (plugin.isUsingPerms() && !fullview && !restrictedview) {
sender.sendMessage(ChatColor.RED + "没有足够的权限购买");
return false;
@ -344,8 +274,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", "");
@ -360,17 +289,10 @@ public class MainCommand implements CommandExecutor {
return false;
}
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"));
} else {
inv = Serialization.toInventory(
config.getStringList(backpack + ".Inventory"), fullName + "'s "
+ backpack + " data", Integer.parseInt(key.get(0)));
}
if (config.getStringList(backpack + ".Inventory") == null)
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)));
} else {
try {
inv = MysqlFunctions.getBackpackInv(name, backpack);
@ -386,11 +308,10 @@ public class MainCommand implements CommandExecutor {
sender.sendMessage(ChatColor.RED + "玩家打开了背包,请等待玩家关闭.");
return false;
}
if (fullview || !plugin.isUsingPerms()) {
if (fullview || !plugin.isUsingPerms())
plugin.adminFullView.put(sender.getName(), backpack + ":" + name);
} else {
else
plugin.adminRestrictedView.add(sender.getName());
}
p.openInventory(inv);
} else {
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
main: cn.citycraft.RealBackpacks.RealBackpacks
version: 0.1.5
website: http://ci.citycraft.cn:8800/jenkins/job/RealBackpacks/
author: Slayr288,喵♂呜
name: ${project.artifactId}
description: ${project.description}
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/
version: ${project.version}
authors: [喵♂呜]
softdepend: [Vault]
commands:
rb: