From cfce6987c0b2d064611d03ae3924eeea51d7578a Mon Sep 17 00:00:00 2001 From: j502647092 Date: Thu, 28 May 2015 20:58:32 +0800 Subject: [PATCH] rebuild priject... Signed-off-by: j502647092 --- .../RealBackpacks/RealBackpacks.java | 63 +- .../RealBackpacks/config/FileConfig.java | 100 +-- .../RealBackpacks/json/JSONArray.java | 744 +++++++++--------- .../RealBackpacks/util/MysqlFunctions.java | 270 ++++--- src/plugin.yml | 4 +- 5 files changed, 608 insertions(+), 573 deletions(-) diff --git a/src/cn/citycraft/RealBackpacks/RealBackpacks.java b/src/cn/citycraft/RealBackpacks/RealBackpacks.java index bce5fe0..9b7a11a 100644 --- a/src/cn/citycraft/RealBackpacks/RealBackpacks.java +++ b/src/cn/citycraft/RealBackpacks/RealBackpacks.java @@ -55,28 +55,26 @@ public class RealBackpacks extends JavaPlugin { public List adminRestrictedView = new ArrayList(); public List slowedPlayers = new ArrayList(); - /* - * List key --------- - * 0 =Size - * 1 = UseRecipe - * 2 = id - * 3 = name - * 4 =destroyContents - * 5 = dropContents - * 6 = dropBackpack - * 7 = keepBackpack - * 8 =walkSpeedEnabled - * 9 = walkSpeedMultiplier - * 10 = increasedHungerEnabled - * 11 =hungerBarsToDeplete - * 12 = hungerBarsToSubtractWhenEating - * 13 = Purchasable - * 14 = Price - * 15 = OpenWith - * 16 = UseWhitelist - * 17 = addGlow - * 18 = Unstackable - */ + // List key + // 0 = Size + // 1 = UseRecipe + // 2 = id + // 3 = name + // 4 =destroyContents + // 5 = dropContents + // 6 = dropBackpack + // 7 = keepBackpack + // 8 = walkSpeedEnabled + // 9 = walkSpeedMultiplier + // 10 = increasedHungerEnabled + // 11 = hungerBarsToDeplete + // 12 = hungerBarsToSubtractWhenEating + // 13 = Purchasable + // 14 = Price + // 15 = OpenWith + // 16 = UseWhitelist + // 17 = addGlow + // 18 = Unstackable @Override public void onEnable() { @@ -100,10 +98,10 @@ public class RealBackpacks extends JavaPlugin { MysqlFunctions.setMysqlFunc(this); RBUtil.setRBUtil(this); if (!setupEconomy()) { - getLogger().info("Vault not found, economy features disabled."); + getLogger().warning("Vault 未找到, 部分功能无法使用..."); vault = false; } else { - getLogger().info("Vault found, economy features enabled."); + getLogger().info("Vault 已找到, 启用经济系统..."); } setupLists(); setup(); @@ -118,9 +116,9 @@ public class RealBackpacks extends JavaPlugin { new EntityListener(this), this); getServer().getScheduler().runTaskTimer(this, new WalkSpeedRunnable(this), 20, 20); - + getCommand("rb").setExecutor(new MainCommand(this)); - + getLogger().info("真实背包已加载 By: 喵♂呜."); } } @@ -128,23 +126,20 @@ public class RealBackpacks extends JavaPlugin { @Override public FileConfiguration getConfig() { - if(Config.getInstance()==null){ + if (Config.getInstance() == null) { Config.load(this); } return Config.getInstance(); } - - /* (非 Javadoc) - * @see org.bukkit.plugin.java.JavaPlugin#saveConfig() - */ + @Override public void saveConfig() { + if (Config.getInstance() == null) { + Config.load(this); + } Config.save(); } - /* (非 Javadoc) - * @see org.bukkit.plugin.java.JavaPlugin#reloadConfig() - */ @Override public void reloadConfig() { Config.load(this); diff --git a/src/cn/citycraft/RealBackpacks/config/FileConfig.java b/src/cn/citycraft/RealBackpacks/config/FileConfig.java index 9ba47bf..b2a1c14 100644 --- a/src/cn/citycraft/RealBackpacks/config/FileConfig.java +++ b/src/cn/citycraft/RealBackpacks/config/FileConfig.java @@ -30,59 +30,63 @@ import com.google.common.io.Files; */ public class FileConfig extends YamlConfiguration { - protected final DumperOptions yamlOptions = new DumperOptions(); - protected final Representer yamlRepresenter = new YamlRepresenter(); - protected final Yaml yaml = new Yaml(new YamlConstructor(), - yamlRepresenter, yamlOptions); + public static FileConfig init(File file) { + return FileConfig.loadConfiguration(file); + } - public static FileConfig init(File file) { - return FileConfig.loadConfiguration(file); + public static FileConfig loadConfiguration(File file) { + Validate.notNull(file, "File cannot be null"); + FileConfig config = new FileConfig(); + try { + config.load(file); + } catch (FileNotFoundException ex) { + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); + } catch (InvalidConfigurationException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); } + return config; + } - public static FileConfig loadConfiguration(File file) { - Validate.notNull(file, "File cannot be null"); - FileConfig config = new FileConfig(); - try { - config.load(file); - } catch (FileNotFoundException ex) { - } catch (IOException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } catch (InvalidConfigurationException ex) { - Bukkit.getLogger().log(Level.SEVERE, "Cannot load " + file, ex); - } - return config; - } + protected final DumperOptions yamlOptions = new DumperOptions(); - @Override - public String saveToString() { - yamlOptions.setIndent(options().indent()); - yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); - String header = buildHeader(); - String dump = yaml.dump(getValues(false)); - if (dump.equals(BLANK_CONFIG)) { - dump = ""; - } - return header + dump; - } + protected final Representer yamlRepresenter = new YamlRepresenter(); - public void load(File file) throws FileNotFoundException, IOException, - InvalidConfigurationException { - Validate.notNull(file, "File cannot be null"); - final FileInputStream stream = new FileInputStream(file); - load(new InputStreamReader(stream, Charsets.UTF_8)); - } + protected final Yaml yaml = new Yaml(new YamlConstructor(), + yamlRepresenter, yamlOptions); - public void save(File file) throws IOException { - Validate.notNull(file, "File cannot be null"); - Files.createParentDirs(file); - String data = saveToString(); - Writer writer = new OutputStreamWriter(new FileOutputStream(file), - Charsets.UTF_8); - try { - writer.write(data); - } finally { - writer.close(); - } + @Override + public void load(File file) throws FileNotFoundException, IOException, + InvalidConfigurationException { + Validate.notNull(file, "File cannot be null"); + final FileInputStream stream = new FileInputStream(file); + load(new InputStreamReader(stream, Charsets.UTF_8)); + } + + @Override + public void save(File file) throws IOException { + Validate.notNull(file, "File cannot be null"); + Files.createParentDirs(file); + String data = saveToString(); + Writer writer = new OutputStreamWriter(new FileOutputStream(file), + Charsets.UTF_8); + try { + writer.write(data); + } finally { + writer.close(); } + } + + @Override + public String saveToString() { + yamlOptions.setIndent(options().indent()); + yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); + String header = buildHeader(); + String dump = yaml.dump(getValues(false)); + if (dump.equals(BLANK_CONFIG)) { + dump = ""; + } + return header + dump; + } } diff --git a/src/cn/citycraft/RealBackpacks/json/JSONArray.java b/src/cn/citycraft/RealBackpacks/json/JSONArray.java index 93eea4f..520f48d 100644 --- a/src/cn/citycraft/RealBackpacks/json/JSONArray.java +++ b/src/cn/citycraft/RealBackpacks/json/JSONArray.java @@ -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 @@ -35,381 +35,385 @@ import java.util.Map; public class JSONArray { - private final ArrayList myArrayList; + private final ArrayList myArrayList; - public JSONArray() { - this.myArrayList = new ArrayList(); + public JSONArray() { + this.myArrayList = new ArrayList(); + } + + public JSONArray(Collection collection) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { + this.myArrayList.add(JSONObject.wrap(iter.next())); + } } + } - public JSONArray(JSONTokener x) throws JSONException { - this(); - if (x.nextClean() != '[') { - throw x.syntaxError("A JSONArray text must start with '['"); - } - if (x.nextClean() != ']') { - x.back(); - for (;;) { - if (x.nextClean() == ',') { - x.back(); - this.myArrayList.add(JSONObject.NULL); - } else { - x.back(); - this.myArrayList.add(x.nextValue()); - } - switch (x.nextClean()) { - case ';': - case ',': - if (x.nextClean() == ']') { - return; - } - x.back(); - break; - case ']': - return; - default: - throw x.syntaxError("Expected a ',' or ']'"); - } - } - } - } - - public JSONArray(String source) throws JSONException { - this(new JSONTokener(source)); - } - - public JSONArray(Collection collection) { - this.myArrayList = new ArrayList(); - if (collection != null) { - Iterator iter = collection.iterator(); - while (iter.hasNext()) { - this.myArrayList.add(JSONObject.wrap(iter.next())); - } - } - } - - public JSONArray(Object array) throws JSONException { - this(); - if (array.getClass().isArray()) { - int length = Array.getLength(array); - for (int i = 0; i < length; i += 1) { - this.put(JSONObject.wrap(Array.get(array, i))); - } + public JSONArray(JSONTokener x) throws JSONException { + this(); + if (x.nextClean() != '[') + throw x.syntaxError("A JSONArray text must start with '['"); + if (x.nextClean() != ']') { + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); } else { - throw new JSONException("JSONArray initial value should be a string or collection or array."); + x.back(); + this.myArrayList.add(x.nextValue()); } - } - - public Object get(int index) throws JSONException { - Object object = this.opt(index); - if (object == null) { - throw new JSONException("JSONArray[" + index + "] not found."); + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == ']') + return; + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); } - return object; + } } + } - public boolean getBoolean(int index) throws JSONException { - Object object = this.get(index); - if (object.equals(Boolean.FALSE) || (object instanceof String && ((String) object).equalsIgnoreCase("false"))) { - return false; - } else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String) object).equalsIgnoreCase("true"))) { - return true; + public JSONArray(Object array) throws JSONException { + this(); + if (array.getClass().isArray()) { + int length = Array.getLength(array); + for (int i = 0; i < length; i += 1) { + this.put(JSONObject.wrap(Array.get(array, i))); + } + } else + throw new JSONException( + "JSONArray initial value should be a string or collection or array."); + } + + public JSONArray(String source) throws JSONException { + this(new JSONTokener(source)); + } + + public Object get(int index) throws JSONException { + Object object = this.opt(index); + if (object == null) + throw new JSONException("JSONArray[" + index + "] not found."); + return object; + } + + public boolean getBoolean(int index) throws JSONException { + Object object = this.get(index); + if (object.equals(Boolean.FALSE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("false"))) + return false; + else if (object.equals(Boolean.TRUE) + || (object instanceof String && ((String) object) + .equalsIgnoreCase("true"))) + return true; + throw new JSONException("JSONArray[" + index + "] is not a boolean."); + } + + public double getDouble(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + public int getInt(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + public JSONArray getJSONArray(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONArray) + return (JSONArray) object; + throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); + } + + public JSONObject getJSONObject(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof JSONObject) + return (JSONObject) object; + throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); + } + + public long getLong(int index) throws JSONException { + Object object = this.get(index); + try { + return object instanceof Number ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + "] is not a number."); + } + } + + public String getString(int index) throws JSONException { + Object object = this.get(index); + if (object instanceof String) + return (String) object; + throw new JSONException("JSONArray[" + index + "] not a string."); + } + + public boolean isNull(int index) { + return JSONObject.NULL.equals(this.opt(index)); + } + + public String join(String separator) throws JSONException { + int len = this.length(); + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < len; i += 1) { + if (i > 0) { + sb.append(separator); + } + sb.append(JSONObject.valueToString(this.myArrayList.get(i))); + } + return sb.toString(); + } + + public int length() { + return this.myArrayList.size(); + } + + public Object opt(int index) { + return (index < 0 || index >= this.length()) ? null : this.myArrayList + .get(index); + } + + public boolean optBoolean(int index) { + return this.optBoolean(index, false); + } + + public boolean optBoolean(int index, boolean defaultValue) { + try { + return this.getBoolean(index); + } catch (Exception e) { + return defaultValue; + } + } + + public double optDouble(int index) { + return this.optDouble(index, Double.NaN); + } + + public double optDouble(int index, double defaultValue) { + try { + return this.getDouble(index); + } catch (Exception e) { + return defaultValue; + } + } + + public int optInt(int index) { + return this.optInt(index, 0); + } + + public int optInt(int index, int defaultValue) { + try { + return this.getInt(index); + } catch (Exception e) { + return defaultValue; + } + } + + public JSONArray optJSONArray(int index) { + Object o = this.opt(index); + return o instanceof JSONArray ? (JSONArray) o : null; + } + + public JSONObject optJSONObject(int index) { + Object o = this.opt(index); + return o instanceof JSONObject ? (JSONObject) o : null; + } + + public long optLong(int index) { + return this.optLong(index, 0); + } + + public long optLong(int index, long defaultValue) { + try { + return this.getLong(index); + } catch (Exception e) { + return defaultValue; + } + } + + public String optString(int index) { + return this.optString(index, ""); + } + + public String optString(int index, String defaultValue) { + Object object = this.opt(index); + return JSONObject.NULL.equals(object) ? defaultValue : object + .toString(); + } + + public JSONArray put(boolean value) { + this.put(value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + public JSONArray put(Collection value) { + this.put(new JSONArray(value)); + return this; + } + + public JSONArray put(double value) throws JSONException { + Double d = new Double(value); + JSONObject.testValidity(d); + this.put(d); + return this; + } + + public JSONArray put(int value) { + this.put(new Integer(value)); + return this; + } + + public JSONArray put(int index, boolean value) throws JSONException { + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + public JSONArray put(int index, Collection value) throws JSONException { + this.put(index, new JSONArray(value)); + return this; + } + + public JSONArray put(int index, double value) throws JSONException { + this.put(index, new Double(value)); + return this; + } + + public JSONArray put(int index, int value) throws JSONException { + this.put(index, new Integer(value)); + return this; + } + + public JSONArray put(int index, long value) throws JSONException { + this.put(index, new Long(value)); + return this; + } + + public JSONArray put(int index, Map value) throws JSONException { + this.put(index, new JSONObject(value)); + return this; + } + + public JSONArray put(int index, Object value) throws JSONException { + JSONObject.testValidity(value); + if (index < 0) + throw new JSONException("JSONArray[" + index + "] not found."); + if (index < this.length()) { + this.myArrayList.set(index, value); + } else { + while (index != this.length()) { + this.put(JSONObject.NULL); + } + this.put(value); + } + return this; + } + + public JSONArray put(long value) { + this.put(new Long(value)); + return this; + } + + public JSONArray put(Map value) { + this.put(new JSONObject()); + return this; + } + + public JSONArray put(Object value) { + this.myArrayList.add(value); + return this; + } + + public Object remove(int index) { + Object o = this.opt(index); + this.myArrayList.remove(index); + return o; + } + + public JSONObject toJSONObject(JSONArray names) throws JSONException { + if (names == null || names.length() == 0 || this.length() == 0) + return null; + JSONObject jo = new JSONObject(); + for (int i = 0; i < names.length(); i += 1) { + jo.put(names.getString(i), this.opt(i)); + } + return jo; + } + + @Override + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + public String toString(int indentFactor) throws JSONException { + StringWriter sw = new StringWriter(); + synchronized (sw.getBuffer()) { + return this.write(sw, indentFactor, 0).toString(); + } + } + + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + int length = this.length(); + writer.write('['); + + if (length == 1) { + JSONObject.writeValue(writer, this.myArrayList.get(0), + indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + + for (int i = 0; i < length; i += 1) { + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + JSONObject.indent(writer, newindent); + JSONObject.writeValue(writer, this.myArrayList.get(i), + indentFactor, newindent); + commanate = true; } - throw new JSONException("JSONArray[" + index + "] is not a boolean."); - } - - public double getDouble(int index) throws JSONException { - Object object = this.get(index); - try { - return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - public int getInt(int index) throws JSONException { - Object object = this.get(index); - try { - return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - public JSONArray getJSONArray(int index) throws JSONException { - Object object = this.get(index); - if (object instanceof JSONArray) { - return (JSONArray) object; - } - throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); - } - - public JSONObject getJSONObject(int index) throws JSONException { - Object object = this.get(index); - if (object instanceof JSONObject) { - return (JSONObject) object; - } - throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); - } - - public long getLong(int index) throws JSONException { - Object object = this.get(index); - try { - return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object); - } catch (Exception e) { - throw new JSONException("JSONArray[" + index + "] is not a number."); - } - } - - public String getString(int index) throws JSONException { - Object object = this.get(index); - if (object instanceof String) { - return (String) object; - } - throw new JSONException("JSONArray[" + index + "] not a string."); - } - - public boolean isNull(int index) { - return JSONObject.NULL.equals(this.opt(index)); - } - - public String join(String separator) throws JSONException { - int len = this.length(); - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < len; i += 1) { - if (i > 0) { - sb.append(separator); - } - sb.append(JSONObject.valueToString(this.myArrayList.get(i))); - } - return sb.toString(); - } - - public int length() { - return this.myArrayList.size(); - } - - public Object opt(int index) { - return (index < 0 || index >= this.length()) ? null : this.myArrayList.get(index); - } - - public boolean optBoolean(int index) { - return this.optBoolean(index, false); - } - - public boolean optBoolean(int index, boolean defaultValue) { - try { - return this.getBoolean(index); - } catch (Exception e) { - return defaultValue; - } - } - - public double optDouble(int index) { - return this.optDouble(index, Double.NaN); - } - - public double optDouble(int index, double defaultValue) { - try { - return this.getDouble(index); - } catch (Exception e) { - return defaultValue; - } - } - - public int optInt(int index) { - return this.optInt(index, 0); - } - - public int optInt(int index, int defaultValue) { - try { - return this.getInt(index); - } catch (Exception e) { - return defaultValue; - } - } - - public JSONArray optJSONArray(int index) { - Object o = this.opt(index); - return o instanceof JSONArray ? (JSONArray) o : null; - } - - public JSONObject optJSONObject(int index) { - Object o = this.opt(index); - return o instanceof JSONObject ? (JSONObject) o : null; - } - - public long optLong(int index) { - return this.optLong(index, 0); - } - - public long optLong(int index, long defaultValue) { - try { - return this.getLong(index); - } catch (Exception e) { - return defaultValue; - } - } - - public String optString(int index) { - return this.optString(index, ""); - } - - public String optString(int index, String defaultValue) { - Object object = this.opt(index); - return JSONObject.NULL.equals(object) ? defaultValue : object.toString(); - } - - public JSONArray put(boolean value) { - this.put(value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - public JSONArray put(Collection value) { - this.put(new JSONArray(value)); - return this; - } - - public JSONArray put(double value) throws JSONException { - Double d = new Double(value); - JSONObject.testValidity(d); - this.put(d); - return this; - } - - public JSONArray put(int value) { - this.put(new Integer(value)); - return this; - } - - public JSONArray put(long value) { - this.put(new Long(value)); - return this; - } - - public JSONArray put(Map value) { - this.put(new JSONObject()); - return this; - } - - public JSONArray put(Object value) { - this.myArrayList.add(value); - return this; - } - - public JSONArray put(int index, boolean value) throws JSONException { - this.put(index, value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - public JSONArray put(int index, Collection value) throws JSONException { - this.put(index, new JSONArray(value)); - return this; - } - - public JSONArray put(int index, double value) throws JSONException { - this.put(index, new Double(value)); - return this; - } - - public JSONArray put(int index, int value) throws JSONException { - this.put(index, new Integer(value)); - return this; - } - - public JSONArray put(int index, long value) throws JSONException { - this.put(index, new Long(value)); - return this; - } - - public JSONArray put(int index, Map value) throws JSONException { - this.put(index, new JSONObject(value)); - return this; - } - - public JSONArray put(int index, Object value) throws JSONException { - JSONObject.testValidity(value); - if (index < 0) { - throw new JSONException("JSONArray[" + index + "] not found."); - } - if (index < this.length()) { - this.myArrayList.set(index, value); - } else { - while (index != this.length()) { - this.put(JSONObject.NULL); - } - this.put(value); - } - return this; - } - - public Object remove(int index) { - Object o = this.opt(index); - this.myArrayList.remove(index); - return o; - } - - public JSONObject toJSONObject(JSONArray names) throws JSONException { - if (names == null || names.length() == 0 || this.length() == 0) { - return null; - } - JSONObject jo = new JSONObject(); - for (int i = 0; i < names.length(); i += 1) { - jo.put(names.getString(i), this.opt(i)); - } - return jo; - } - - public String toString() { - try { - return this.toString(0); - } catch (Exception e) { - return null; - } - } - - public String toString(int indentFactor) throws JSONException { - StringWriter sw = new StringWriter(); - synchronized (sw.getBuffer()) { - return this.write(sw, indentFactor, 0).toString(); - } - } - - public Writer write(Writer writer) throws JSONException { - return this.write(writer, 0, 0); - } - - Writer write(Writer writer, int indentFactor, int indent) throws JSONException { - try { - boolean commanate = false; - int length = this.length(); - writer.write('['); - - if (length == 1) { - JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent); - } else if (length != 0) { - final int newindent = indent + indentFactor; - - for (int i = 0; i < length; i += 1) { - if (commanate) { - writer.write(','); - } - if (indentFactor > 0) { - writer.write('\n'); - } - JSONObject.indent(writer, newindent); - JSONObject.writeValue(writer, this.myArrayList.get(i), indentFactor, newindent); - commanate = true; - } - if (indentFactor > 0) { - writer.write('\n'); - } - JSONObject.indent(writer, indent); - } - writer.write(']'); - return writer; - } catch (IOException e) { - throw new JSONException(e); + if (indentFactor > 0) { + writer.write('\n'); } + JSONObject.indent(writer, indent); + } + writer.write(']'); + return writer; + } catch (IOException e) { + throw new JSONException(e); } + } } \ No newline at end of file diff --git a/src/cn/citycraft/RealBackpacks/util/MysqlFunctions.java b/src/cn/citycraft/RealBackpacks/util/MysqlFunctions.java index 750a2bd..a3b33e0 100644 --- a/src/cn/citycraft/RealBackpacks/util/MysqlFunctions.java +++ b/src/cn/citycraft/RealBackpacks/util/MysqlFunctions.java @@ -16,130 +16,162 @@ import cn.citycraft.RealBackpacks.RealBackpacks; public class MysqlFunctions { - private static cn.citycraft.RealBackpacks.RealBackpacks plugin; + private static cn.citycraft.RealBackpacks.RealBackpacks plugin; - public static void setMysqlFunc(final RealBackpacks plugin) { - MysqlFunctions.plugin = plugin; - } - - 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 addBackpackData(final String playerName, final String backpack, final List 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 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))); + public static void addBackpackData(final String playerName, + final String backpack, final List 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 { - returnInv = null; + 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(); } - state.close(); - conn.close(); - } catch (final SQLException e) { - e.printStackTrace(); - } - return returnInv; - } + } + }); + } - 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 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; + } } diff --git a/src/plugin.yml b/src/plugin.yml index 818ca54..1d868f9 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,8 +1,8 @@ name: RealBackpacks main: cn.citycraft.RealBackpacks.RealBackpacks -version: 1.6.5 +version: 0.1.3 author: Slayr288,喵♂呜 -softdepend: [Vault,BVLib] +softdepend: [Vault] commands: rb: description: Main commands.