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

清理代码...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-12-12 11:18:34 +08:00
parent 437880e5b9
commit 9ba6275108
3 changed files with 378 additions and 380 deletions

View File

@ -28,12 +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 <背包名称> ",
"§4* §a给玩家指定背包 §7/rb give <玩家名称> <背包名称>",
"§4* §a查看玩家指定背包 §7/rb view <玩家名称> <背包名称>",
"§4* §a数据转移至MySQL §7/rb filetomysql" };
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" };
public MainCommand(final RealBackpacks plugin) {
this.plugin = plugin;
@ -108,10 +108,9 @@ public class MainCommand implements CommandExecutor {
p.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你花费了 " + ChatColor.GOLD + price + ChatColor.GREEN + " 购买了背包: " + ChatColor.GOLD + backpack);
return true;
} else {
sender.sendMessage(ChatColor.RED + "你的背包是空的.");
return false;
}
sender.sendMessage(ChatColor.RED + "你的背包是空的.");
return false;
} else if (command.equalsIgnoreCase("list")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.list")) {
sender.sendMessage(ChatColor.RED + "你没有此命令的权限!");
@ -175,10 +174,9 @@ public class MainCommand implements CommandExecutor {
other.updateInventory();
sender.sendMessage(ChatColor.GREEN + "你把背包 " + ChatColor.GOLD + backpack + ChatColor.GREEN + " 发送给了 " + ChatColor.GOLD + other.getName());
return true;
} else {
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
return false;
}
sender.sendMessage(ChatColor.RED + other.getName() + "的背包已经满了");
return false;
} else if (command.equalsIgnoreCase("filetomysql")) {
if (plugin.isUsingPerms() && !sender.hasPermission("rb.filetomysql"))
return false;

View File

@ -2,19 +2,19 @@ package cn.citycraft.RealBackpacks.json;
/*
* Copyright (c) 2002 JSON.org
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* The Software shall be used for Good, not Evil.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -41,18 +41,8 @@ import java.util.Set;
public class JSONObject {
private static final int keyPoolSize = 100;
@SuppressWarnings("rawtypes")
private static HashMap keyPool = new HashMap(keyPoolSize);
private static final class Null {
@Override
protected final Object clone() {
return this;
}
@Override
public boolean equals(final Object object) {
return object == null || object == this;
@ -62,13 +52,23 @@ public class JSONObject {
public String toString() {
return "null";
}
@Override
protected final Object clone() {
return this;
}
}
private static final int keyPoolSize = 100;
@SuppressWarnings("rawtypes")
private static HashMap keyPool = new HashMap(keyPoolSize);
public static final Object NULL = new Null();
@SuppressWarnings("rawtypes")
private final Map map;
public static final Object NULL = new Null();
@SuppressWarnings("rawtypes")
public JSONObject() {
this.map = new HashMap();
@ -204,6 +204,312 @@ public class JSONObject {
}
}
public static String doubleToString(final double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return "null";
}
// Shave off trailing zeros and decimal point, if possible.
String string = Double.toString(d);
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
}
public static String[] getNames(final JSONObject jo) {
final int length = jo.length();
if (length == 0) {
return null;
}
@SuppressWarnings("rawtypes")
final Iterator iterator = jo.keys();
final String[] names = new String[length];
int i = 0;
while (iterator.hasNext()) {
names[i] = (String) iterator.next();
i += 1;
}
return names;
}
@SuppressWarnings("rawtypes")
public static String[] getNames(final Object object) {
if (object == null) {
return null;
}
final Class klass = object.getClass();
final Field[] fields = klass.getFields();
final int length = fields.length;
if (length == 0) {
return null;
}
final String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
}
public static String numberToString(final Number number) throws JSONException {
if (number == null) {
throw new JSONException("Null pointer");
}
testValidity(number);
// Shave off trailing zeros and decimal point, if possible.
String string = number.toString();
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
}
public static String quote(final String string) {
final StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
} catch (final IOException ignored) {
// will never happen - we are writing to a string writer
return "";
}
}
}
public static Writer quote(final String string, final Writer w) throws IOException {
if (string == null || string.length() == 0) {
w.write("\"\"");
return w;
}
char b;
char c = 0;
String hhhh;
int i;
final int len = string.length();
w.write('"');
for (i = 0; i < len; i += 1) {
b = c;
c = string.charAt(i);
switch (c) {
case '\\':
case '"':
w.write('\\');
w.write(c);
break;
case '/':
if (b == '<') {
w.write('\\');
}
w.write(c);
break;
case '\b':
w.write("\\b");
break;
case '\t':
w.write("\\t");
break;
case '\n':
w.write("\\n");
break;
case '\f':
w.write("\\f");
break;
case '\r':
w.write("\\r");
break;
default:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
w.write("\\u");
hhhh = Integer.toHexString(c);
w.write("0000", 0, 4 - hhhh.length());
w.write(hhhh);
} else {
w.write(c);
}
}
}
w.write('"');
return w;
}
public static Object stringToValue(final String string) {
Double d;
if (string.equals("")) {
return string;
}
if (string.equalsIgnoreCase("true")) {
return Boolean.TRUE;
}
if (string.equalsIgnoreCase("false")) {
return Boolean.FALSE;
}
if (string.equalsIgnoreCase("null")) {
return JSONObject.NULL;
}
/*
* If it might be a number, try converting it.
* If a number cannot be produced, then the value will just
* be a string. Note that the plus and implied string
* conventions are non-standard. A JSON parser may accept
* non-JSON forms as long as it accepts all correct JSON forms.
*/
final char b = string.charAt(0);
if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
try {
if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
d = Double.valueOf(string);
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
} else {
final Long myLong = new Long(string);
if (myLong.longValue() == myLong.intValue()) {
return new Integer(myLong.intValue());
}
return myLong;
}
} catch (final Exception ignore) {
}
}
return string;
}
public static void testValidity(final Object o) throws JSONException {
if (o != null) {
if (o instanceof Double) {
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
throw new JSONException("JSON does not allow non-finite numbers.");
}
} else if (o instanceof Float) {
if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
throw new JSONException("JSON does not allow non-finite numbers.");
}
}
}
}
@SuppressWarnings("rawtypes")
public static String valueToString(final Object value) throws JSONException {
if (value == null || value.equals(null)) {
return "null";
}
if (value instanceof JSONString) {
Object object;
try {
object = ((JSONString) value).toJSONString();
} catch (final Exception e) {
throw new JSONException(e);
}
if (object instanceof String) {
return (String) object;
}
throw new JSONException("Bad value from toJSONString: " + object);
}
if (value instanceof Number) {
return numberToString((Number) value);
}
if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
return value.toString();
}
if (value instanceof Map) {
return new JSONObject((Map) value).toString();
}
if (value instanceof Collection) {
return new JSONArray((Collection) value).toString();
}
if (value.getClass().isArray()) {
return new JSONArray(value).toString();
}
return quote(value.toString());
}
@SuppressWarnings("rawtypes")
public static Object wrap(final Object object) {
try {
if (object == null) {
return NULL;
}
if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character
|| object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double
|| object instanceof String) {
return object;
}
if (object instanceof Collection) {
return new JSONArray((Collection) object);
}
if (object.getClass().isArray()) {
return new JSONArray(object);
}
if (object instanceof Map) {
return new JSONObject((Map) object);
}
final Package objectPackage = object.getClass().getPackage();
final String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) {
return object.toString();
}
return new JSONObject(object);
} catch (final Exception exception) {
return null;
}
}
static final void indent(final Writer writer, final int indent) throws IOException {
for (int i = 0; i < indent; i += 1) {
writer.write(' ');
}
}
@SuppressWarnings("rawtypes")
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
if (value == null || value.equals(null)) {
writer.write("null");
} else if (value instanceof JSONObject) {
((JSONObject) value).write(writer, indentFactor, indent);
} else if (value instanceof JSONArray) {
((JSONArray) value).write(writer, indentFactor, indent);
} else if (value instanceof Map) {
new JSONObject((Map) value).write(writer, indentFactor, indent);
} else if (value instanceof Collection) {
new JSONArray((Collection) value).write(writer, indentFactor, indent);
} else if (value.getClass().isArray()) {
new JSONArray(value).write(writer, indentFactor, indent);
} else if (value instanceof Number) {
writer.write(numberToString((Number) value));
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
Object o;
try {
o = ((JSONString) value).toJSONString();
} catch (final Exception e) {
throw new JSONException(e);
}
writer.write(o != null ? o.toString() : quote(value.toString()));
} else {
quote(value.toString(), writer);
}
return writer;
}
public JSONObject accumulate(final String key, final Object value) throws JSONException {
testValidity(value);
final Object object = this.opt(key);
@ -230,25 +536,6 @@ public class JSONObject {
return this;
}
public static String doubleToString(final double d) {
if (Double.isInfinite(d) || Double.isNaN(d)) {
return "null";
}
// Shave off trailing zeros and decimal point, if possible.
String string = Double.toString(d);
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
}
public Object get(final String key) throws JSONException {
if (key == null) {
throw new JSONException("Null key.");
@ -313,40 +600,6 @@ public class JSONObject {
}
}
public static String[] getNames(final JSONObject jo) {
final int length = jo.length();
if (length == 0) {
return null;
}
@SuppressWarnings("rawtypes")
final Iterator iterator = jo.keys();
final String[] names = new String[length];
int i = 0;
while (iterator.hasNext()) {
names[i] = (String) iterator.next();
i += 1;
}
return names;
}
@SuppressWarnings("rawtypes")
public static String[] getNames(final Object object) {
if (object == null) {
return null;
}
final Class klass = object.getClass();
final Field[] fields = klass.getFields();
final int length = fields.length;
if (length == 0) {
return null;
}
final String[] names = new String[length];
for (int i = 0; i < length; i += 1) {
names[i] = fields[i].getName();
}
return names;
}
public String getString(final String key) throws JSONException {
final Object object = this.get(key);
if (object instanceof String) {
@ -405,26 +658,6 @@ public class JSONObject {
return ja.length() == 0 ? null : ja;
}
public static String numberToString(final Number number) throws JSONException {
if (number == null) {
throw new JSONException("Null pointer");
}
testValidity(number);
// Shave off trailing zeros and decimal point, if possible.
String string = number.toString();
if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
while (string.endsWith("0")) {
string = string.substring(0, string.length() - 1);
}
if (string.endsWith(".")) {
string = string.substring(0, string.length() - 1);
}
}
return string;
}
public Object opt(final String key) {
return key == null ? null : this.map.get(key);
}
@ -496,48 +729,6 @@ public class JSONObject {
return NULL.equals(object) ? defaultValue : object.toString();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void populateMap(final Object bean) {
final Class klass = bean.getClass();
// If klass is a System class then set includeSuperClass to false.
final boolean includeSuperClass = klass.getClassLoader() != null;
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (int i = 0; i < methods.length; i += 1) {
try {
final Method method = methods[i];
if (Modifier.isPublic(method.getModifiers())) {
final String name = method.getName();
String key = "";
if (name.startsWith("get")) {
if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
key = "";
} else {
key = name.substring(3);
}
} else if (name.startsWith("is")) {
key = name.substring(2);
}
if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) {
if (key.length() == 1) {
key = key.toLowerCase();
} else if (!Character.isUpperCase(key.charAt(1))) {
key = key.substring(0, 1).toLowerCase() + key.substring(1);
}
final Object result = method.invoke(bean, (Object[]) null);
if (result != null) {
this.map.put(key, wrap(result));
}
}
}
} catch (final Exception ignore) {
}
}
}
public JSONObject put(final String key, final boolean value) throws JSONException {
this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
return this;
@ -610,139 +801,10 @@ public class JSONObject {
return this;
}
public static String quote(final String string) {
final StringWriter sw = new StringWriter();
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
} catch (final IOException ignored) {
// will never happen - we are writing to a string writer
return "";
}
}
}
public static Writer quote(final String string, final Writer w) throws IOException {
if (string == null || string.length() == 0) {
w.write("\"\"");
return w;
}
char b;
char c = 0;
String hhhh;
int i;
final int len = string.length();
w.write('"');
for (i = 0; i < len; i += 1) {
b = c;
c = string.charAt(i);
switch (c) {
case '\\':
case '"':
w.write('\\');
w.write(c);
break;
case '/':
if (b == '<') {
w.write('\\');
}
w.write(c);
break;
case '\b':
w.write("\\b");
break;
case '\t':
w.write("\\t");
break;
case '\n':
w.write("\\n");
break;
case '\f':
w.write("\\f");
break;
case '\r':
w.write("\\r");
break;
default:
if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
w.write("\\u");
hhhh = Integer.toHexString(c);
w.write("0000", 0, 4 - hhhh.length());
w.write(hhhh);
} else {
w.write(c);
}
}
}
w.write('"');
return w;
}
public Object remove(final String key) {
return this.map.remove(key);
}
public static Object stringToValue(final String string) {
Double d;
if (string.equals("")) {
return string;
}
if (string.equalsIgnoreCase("true")) {
return Boolean.TRUE;
}
if (string.equalsIgnoreCase("false")) {
return Boolean.FALSE;
}
if (string.equalsIgnoreCase("null")) {
return JSONObject.NULL;
}
/*
* If it might be a number, try converting it.
* If a number cannot be produced, then the value will just
* be a string. Note that the plus and implied string
* conventions are non-standard. A JSON parser may accept
* non-JSON forms as long as it accepts all correct JSON forms.
*/
final char b = string.charAt(0);
if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
try {
if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
d = Double.valueOf(string);
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
} else {
final Long myLong = new Long(string);
if (myLong.longValue() == myLong.intValue()) {
return new Integer(myLong.intValue());
} else {
return myLong;
}
}
} catch (final Exception ignore) {
}
}
return string;
}
public static void testValidity(final Object o) throws JSONException {
if (o != null) {
if (o instanceof Double) {
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
throw new JSONException("JSON does not allow non-finite numbers.");
}
} else if (o instanceof Float) {
if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
throw new JSONException("JSON does not allow non-finite numbers.");
}
}
}
}
public JSONArray toJSONArray(final JSONArray names) throws JSONException {
if (names == null || names.length() == 0) {
return null;
@ -770,110 +832,49 @@ public class JSONObject {
}
}
@SuppressWarnings("rawtypes")
public static String valueToString(final Object value) throws JSONException {
if (value == null || value.equals(null)) {
return "null";
}
if (value instanceof JSONString) {
Object object;
try {
object = ((JSONString) value).toJSONString();
} catch (final Exception e) {
throw new JSONException(e);
}
if (object instanceof String) {
return (String) object;
}
throw new JSONException("Bad value from toJSONString: " + object);
}
if (value instanceof Number) {
return numberToString((Number) value);
}
if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
return value.toString();
}
if (value instanceof Map) {
return new JSONObject((Map) value).toString();
}
if (value instanceof Collection) {
return new JSONArray((Collection) value).toString();
}
if (value.getClass().isArray()) {
return new JSONArray(value).toString();
}
return quote(value.toString());
}
@SuppressWarnings("rawtypes")
public static Object wrap(final Object object) {
try {
if (object == null) {
return NULL;
}
if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double || object instanceof String) {
return object;
}
if (object instanceof Collection) {
return new JSONArray((Collection) object);
}
if (object.getClass().isArray()) {
return new JSONArray(object);
}
if (object instanceof Map) {
return new JSONObject((Map) object);
}
final Package objectPackage = object.getClass().getPackage();
final String objectPackageName = objectPackage != null ? objectPackage.getName() : "";
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || object.getClass().getClassLoader() == null) {
return object.toString();
}
return new JSONObject(object);
} catch (final Exception exception) {
return null;
}
}
public Writer write(final Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
@SuppressWarnings("rawtypes")
static final Writer writeValue(final Writer writer, final Object value, final int indentFactor, final int indent) throws JSONException, IOException {
if (value == null || value.equals(null)) {
writer.write("null");
} else if (value instanceof JSONObject) {
((JSONObject) value).write(writer, indentFactor, indent);
} else if (value instanceof JSONArray) {
((JSONArray) value).write(writer, indentFactor, indent);
} else if (value instanceof Map) {
new JSONObject((Map) value).write(writer, indentFactor, indent);
} else if (value instanceof Collection) {
new JSONArray((Collection) value).write(writer, indentFactor, indent);
} else if (value.getClass().isArray()) {
new JSONArray(value).write(writer, indentFactor, indent);
} else if (value instanceof Number) {
writer.write(numberToString((Number) value));
} else if (value instanceof Boolean) {
writer.write(value.toString());
} else if (value instanceof JSONString) {
Object o;
try {
o = ((JSONString) value).toJSONString();
} catch (final Exception e) {
throw new JSONException(e);
}
writer.write(o != null ? o.toString() : quote(value.toString()));
} else {
quote(value.toString(), writer);
}
return writer;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void populateMap(final Object bean) {
final Class klass = bean.getClass();
static final void indent(final Writer writer, final int indent) throws IOException {
for (int i = 0; i < indent; i += 1) {
writer.write(' ');
// If klass is a System class then set includeSuperClass to false.
final boolean includeSuperClass = klass.getClassLoader() != null;
final Method[] methods = includeSuperClass ? klass.getMethods() : klass.getDeclaredMethods();
for (int i = 0; i < methods.length; i += 1) {
try {
final Method method = methods[i];
if (Modifier.isPublic(method.getModifiers())) {
final String name = method.getName();
String key = "";
if (name.startsWith("get")) {
if ("getClass".equals(name) || "getDeclaringClass".equals(name)) {
key = "";
} else {
key = name.substring(3);
}
} else if (name.startsWith("is")) {
key = name.substring(2);
}
if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) {
if (key.length() == 1) {
key = key.toLowerCase();
} else if (!Character.isUpperCase(key.charAt(1))) {
key = key.substring(0, 1).toLowerCase() + key.substring(1);
}
final Object result = method.invoke(bean, (Object[]) null);
if (result != null) {
this.map.put(key, wrap(result));
}
}
}
} catch (final Exception ignore) {
}
}
}

View File

@ -23,9 +23,9 @@ public class MysqlFunctions {
@Override
public void run() {
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);
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
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();
@ -58,7 +58,7 @@ 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();
@ -67,8 +67,6 @@ public class MysqlFunctions {
conn.close();
if (tables.next())
return true;
else
return false;
} catch (final SQLException e) {
e.printStackTrace();
}
@ -77,7 +75,7 @@ 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;");
state.executeUpdate();
@ -93,7 +91,7 @@ public class MysqlFunctions {
@Override
public void run() {
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("DELETE FROM rb_data WHERE player = ? AND backpack = ?;");
state.setString(1, playerName);
@ -111,7 +109,7 @@ public class MysqlFunctions {
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;");
state.setString(1, playerName);
@ -120,7 +118,8 @@ public class MysqlFunctions {
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)),
returnInv = Serialization.toInventory(Serialization.stringToList(invString),
ChatColor.translateAlternateColorCodes('&', plugin.backpackData.get(backpack).get(3)),
Integer.parseInt(plugin.backpackData.get(backpack).get(0)));
}
state.close();