mirror of
https://e.coding.net/circlecloud/RealBackpacks.git
synced 2025-11-25 21:46:12 +00:00
@@ -55,28 +55,26 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
public List<String> adminRestrictedView = new ArrayList<String>();
|
public List<String> adminRestrictedView = new ArrayList<String>();
|
||||||
public List<String> slowedPlayers = new ArrayList<String>();
|
public List<String> slowedPlayers = new ArrayList<String>();
|
||||||
|
|
||||||
/*
|
// List key
|
||||||
* List key ---------
|
// 0 = Size
|
||||||
* 0 =Size
|
// 1 = UseRecipe
|
||||||
* 1 = UseRecipe
|
// 2 = id
|
||||||
* 2 = id
|
// 3 = name
|
||||||
* 3 = name
|
// 4 =destroyContents
|
||||||
* 4 =destroyContents
|
// 5 = dropContents
|
||||||
* 5 = dropContents
|
// 6 = dropBackpack
|
||||||
* 6 = dropBackpack
|
// 7 = keepBackpack
|
||||||
* 7 = keepBackpack
|
// 8 = walkSpeedEnabled
|
||||||
* 8 =walkSpeedEnabled
|
// 9 = walkSpeedMultiplier
|
||||||
* 9 = walkSpeedMultiplier
|
// 10 = increasedHungerEnabled
|
||||||
* 10 = increasedHungerEnabled
|
// 11 = hungerBarsToDeplete
|
||||||
* 11 =hungerBarsToDeplete
|
// 12 = hungerBarsToSubtractWhenEating
|
||||||
* 12 = hungerBarsToSubtractWhenEating
|
// 13 = Purchasable
|
||||||
* 13 = Purchasable
|
// 14 = Price
|
||||||
* 14 = Price
|
// 15 = OpenWith
|
||||||
* 15 = OpenWith
|
// 16 = UseWhitelist
|
||||||
* 16 = UseWhitelist
|
// 17 = addGlow
|
||||||
* 17 = addGlow
|
// 18 = Unstackable
|
||||||
* 18 = Unstackable
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -100,10 +98,10 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
MysqlFunctions.setMysqlFunc(this);
|
MysqlFunctions.setMysqlFunc(this);
|
||||||
RBUtil.setRBUtil(this);
|
RBUtil.setRBUtil(this);
|
||||||
if (!setupEconomy()) {
|
if (!setupEconomy()) {
|
||||||
getLogger().info("Vault not found, economy features disabled.");
|
getLogger().warning("Vault 未找到, 部分功能无法使用...");
|
||||||
vault = false;
|
vault = false;
|
||||||
} else {
|
} else {
|
||||||
getLogger().info("Vault found, economy features enabled.");
|
getLogger().info("Vault 已找到, 启用经济系统...");
|
||||||
}
|
}
|
||||||
setupLists();
|
setupLists();
|
||||||
setup();
|
setup();
|
||||||
@@ -128,23 +126,20 @@ public class RealBackpacks extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
if(Config.getInstance()==null){
|
if (Config.getInstance() == null) {
|
||||||
Config.load(this);
|
Config.load(this);
|
||||||
}
|
}
|
||||||
return Config.getInstance();
|
return Config.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (非 Javadoc)
|
|
||||||
* @see org.bukkit.plugin.java.JavaPlugin#saveConfig()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
|
if (Config.getInstance() == null) {
|
||||||
|
Config.load(this);
|
||||||
|
}
|
||||||
Config.save();
|
Config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (非 Javadoc)
|
|
||||||
* @see org.bukkit.plugin.java.JavaPlugin#reloadConfig()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
Config.load(this);
|
Config.load(this);
|
||||||
|
|||||||
@@ -30,11 +30,6 @@ import com.google.common.io.Files;
|
|||||||
*/
|
*/
|
||||||
public class FileConfig extends YamlConfiguration {
|
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) {
|
public static FileConfig init(File file) {
|
||||||
return FileConfig.loadConfiguration(file);
|
return FileConfig.loadConfiguration(file);
|
||||||
}
|
}
|
||||||
@@ -53,19 +48,14 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected final DumperOptions yamlOptions = new DumperOptions();
|
||||||
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();
|
||||||
|
|
||||||
|
protected final Yaml yaml = new Yaml(new YamlConstructor(),
|
||||||
|
yamlRepresenter, yamlOptions);
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load(File file) throws FileNotFoundException, IOException,
|
public void load(File file) throws FileNotFoundException, IOException,
|
||||||
InvalidConfigurationException {
|
InvalidConfigurationException {
|
||||||
Validate.notNull(file, "File cannot be null");
|
Validate.notNull(file, "File cannot be null");
|
||||||
@@ -73,6 +63,7 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
load(new InputStreamReader(stream, Charsets.UTF_8));
|
load(new InputStreamReader(stream, Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void save(File file) throws IOException {
|
public void save(File file) throws IOException {
|
||||||
Validate.notNull(file, "File cannot be null");
|
Validate.notNull(file, "File cannot be null");
|
||||||
Files.createParentDirs(file);
|
Files.createParentDirs(file);
|
||||||
@@ -85,4 +76,17 @@ public class FileConfig extends YamlConfiguration {
|
|||||||
writer.close();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,11 +41,20 @@ public class JSONArray {
|
|||||||
this.myArrayList = new ArrayList<Object>();
|
this.myArrayList = new ArrayList<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONArray(Collection<?> collection) {
|
||||||
|
this.myArrayList = new ArrayList<Object>();
|
||||||
|
if (collection != null) {
|
||||||
|
Iterator<?> iter = collection.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
this.myArrayList.add(JSONObject.wrap(iter.next()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public JSONArray(JSONTokener x) throws JSONException {
|
public JSONArray(JSONTokener x) throws JSONException {
|
||||||
this();
|
this();
|
||||||
if (x.nextClean() != '[') {
|
if (x.nextClean() != '[')
|
||||||
throw x.syntaxError("A JSONArray text must start with '['");
|
throw x.syntaxError("A JSONArray text must start with '['");
|
||||||
}
|
|
||||||
if (x.nextClean() != ']') {
|
if (x.nextClean() != ']') {
|
||||||
x.back();
|
x.back();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -59,9 +68,8 @@ public class JSONArray {
|
|||||||
switch (x.nextClean()) {
|
switch (x.nextClean()) {
|
||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
if (x.nextClean() == ']') {
|
if (x.nextClean() == ']')
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
x.back();
|
x.back();
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
@@ -73,20 +81,6 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONArray(String source) throws JSONException {
|
|
||||||
this(new JSONTokener(source));
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONArray(Collection<?> collection) {
|
|
||||||
this.myArrayList = new ArrayList<Object>();
|
|
||||||
if (collection != null) {
|
|
||||||
Iterator<?> iter = collection.iterator();
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
this.myArrayList.add(JSONObject.wrap(iter.next()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONArray(Object array) throws JSONException {
|
public JSONArray(Object array) throws JSONException {
|
||||||
this();
|
this();
|
||||||
if (array.getClass().isArray()) {
|
if (array.getClass().isArray()) {
|
||||||
@@ -94,33 +88,40 @@ public class JSONArray {
|
|||||||
for (int i = 0; i < length; i += 1) {
|
for (int i = 0; i < length; i += 1) {
|
||||||
this.put(JSONObject.wrap(Array.get(array, i)));
|
this.put(JSONObject.wrap(Array.get(array, i)));
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
throw new JSONException("JSONArray initial value should be a string or collection or array.");
|
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 {
|
public Object get(int index) throws JSONException {
|
||||||
Object object = this.opt(index);
|
Object object = this.opt(index);
|
||||||
if (object == null) {
|
if (object == null)
|
||||||
throw new JSONException("JSONArray[" + index + "] not found.");
|
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||||
}
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(int index) throws JSONException {
|
public boolean getBoolean(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
if (object.equals(Boolean.FALSE) || (object instanceof String && ((String) object).equalsIgnoreCase("false"))) {
|
if (object.equals(Boolean.FALSE)
|
||||||
|
|| (object instanceof String && ((String) object)
|
||||||
|
.equalsIgnoreCase("false")))
|
||||||
return false;
|
return false;
|
||||||
} else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String) object).equalsIgnoreCase("true"))) {
|
else if (object.equals(Boolean.TRUE)
|
||||||
|
|| (object instanceof String && ((String) object)
|
||||||
|
.equalsIgnoreCase("true")))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
throw new JSONException("JSONArray[" + index + "] is not a boolean.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(int index) throws JSONException {
|
public double getDouble(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).doubleValue() : Double.parseDouble((String) object);
|
return object instanceof Number ? ((Number) object).doubleValue()
|
||||||
|
: Double.parseDouble((String) object);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
@@ -129,7 +130,8 @@ public class JSONArray {
|
|||||||
public int getInt(int index) throws JSONException {
|
public int getInt(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).intValue() : Integer.parseInt((String) object);
|
return object instanceof Number ? ((Number) object).intValue()
|
||||||
|
: Integer.parseInt((String) object);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
@@ -137,24 +139,23 @@ public class JSONArray {
|
|||||||
|
|
||||||
public JSONArray getJSONArray(int index) throws JSONException {
|
public JSONArray getJSONArray(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
if (object instanceof JSONArray) {
|
if (object instanceof JSONArray)
|
||||||
return (JSONArray) object;
|
return (JSONArray) object;
|
||||||
}
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getJSONObject(int index) throws JSONException {
|
public JSONObject getJSONObject(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
if (object instanceof JSONObject) {
|
if (object instanceof JSONObject)
|
||||||
return (JSONObject) object;
|
return (JSONObject) object;
|
||||||
}
|
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLong(int index) throws JSONException {
|
public long getLong(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
try {
|
try {
|
||||||
return object instanceof Number ? ((Number) object).longValue() : Long.parseLong((String) object);
|
return object instanceof Number ? ((Number) object).longValue()
|
||||||
|
: Long.parseLong((String) object);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
throw new JSONException("JSONArray[" + index + "] is not a number.");
|
||||||
}
|
}
|
||||||
@@ -162,9 +163,8 @@ public class JSONArray {
|
|||||||
|
|
||||||
public String getString(int index) throws JSONException {
|
public String getString(int index) throws JSONException {
|
||||||
Object object = this.get(index);
|
Object object = this.get(index);
|
||||||
if (object instanceof String) {
|
if (object instanceof String)
|
||||||
return (String) object;
|
return (String) object;
|
||||||
}
|
|
||||||
throw new JSONException("JSONArray[" + index + "] not a string.");
|
throw new JSONException("JSONArray[" + index + "] not a string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,8 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object opt(int index) {
|
public Object opt(int index) {
|
||||||
return (index < 0 || index >= this.length()) ? null : this.myArrayList.get(index);
|
return (index < 0 || index >= this.length()) ? null : this.myArrayList
|
||||||
|
.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean optBoolean(int index) {
|
public boolean optBoolean(int index) {
|
||||||
@@ -257,7 +258,8 @@ public class JSONArray {
|
|||||||
|
|
||||||
public String optString(int index, String defaultValue) {
|
public String optString(int index, String defaultValue) {
|
||||||
Object object = this.opt(index);
|
Object object = this.opt(index);
|
||||||
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
return JSONObject.NULL.equals(object) ? defaultValue : object
|
||||||
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONArray put(boolean value) {
|
public JSONArray put(boolean value) {
|
||||||
@@ -282,21 +284,6 @@ public class JSONArray {
|
|||||||
return this;
|
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 {
|
public JSONArray put(int index, boolean value) throws JSONException {
|
||||||
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
|
||||||
return this;
|
return this;
|
||||||
@@ -329,9 +316,8 @@ public class JSONArray {
|
|||||||
|
|
||||||
public JSONArray put(int index, Object value) throws JSONException {
|
public JSONArray put(int index, Object value) throws JSONException {
|
||||||
JSONObject.testValidity(value);
|
JSONObject.testValidity(value);
|
||||||
if (index < 0) {
|
if (index < 0)
|
||||||
throw new JSONException("JSONArray[" + index + "] not found.");
|
throw new JSONException("JSONArray[" + index + "] not found.");
|
||||||
}
|
|
||||||
if (index < this.length()) {
|
if (index < this.length()) {
|
||||||
this.myArrayList.set(index, value);
|
this.myArrayList.set(index, value);
|
||||||
} else {
|
} else {
|
||||||
@@ -343,6 +329,21 @@ public class JSONArray {
|
|||||||
return this;
|
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) {
|
public Object remove(int index) {
|
||||||
Object o = this.opt(index);
|
Object o = this.opt(index);
|
||||||
this.myArrayList.remove(index);
|
this.myArrayList.remove(index);
|
||||||
@@ -350,9 +351,8 @@ public class JSONArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject toJSONObject(JSONArray names) throws JSONException {
|
public JSONObject toJSONObject(JSONArray names) throws JSONException {
|
||||||
if (names == null || names.length() == 0 || this.length() == 0) {
|
if (names == null || names.length() == 0 || this.length() == 0)
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
JSONObject jo = new JSONObject();
|
JSONObject jo = new JSONObject();
|
||||||
for (int i = 0; i < names.length(); i += 1) {
|
for (int i = 0; i < names.length(); i += 1) {
|
||||||
jo.put(names.getString(i), this.opt(i));
|
jo.put(names.getString(i), this.opt(i));
|
||||||
@@ -360,6 +360,7 @@ public class JSONArray {
|
|||||||
return jo;
|
return jo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
try {
|
||||||
return this.toString(0);
|
return this.toString(0);
|
||||||
@@ -379,14 +380,16 @@ public class JSONArray {
|
|||||||
return this.write(writer, 0, 0);
|
return this.write(writer, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Writer write(Writer writer, int indentFactor, int indent) throws JSONException {
|
Writer write(Writer writer, int indentFactor, int indent)
|
||||||
|
throws JSONException {
|
||||||
try {
|
try {
|
||||||
boolean commanate = false;
|
boolean commanate = false;
|
||||||
int length = this.length();
|
int length = this.length();
|
||||||
writer.write('[');
|
writer.write('[');
|
||||||
|
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent);
|
JSONObject.writeValue(writer, this.myArrayList.get(0),
|
||||||
|
indentFactor, indent);
|
||||||
} else if (length != 0) {
|
} else if (length != 0) {
|
||||||
final int newindent = indent + indentFactor;
|
final int newindent = indent + indentFactor;
|
||||||
|
|
||||||
@@ -398,7 +401,8 @@ public class JSONArray {
|
|||||||
writer.write('\n');
|
writer.write('\n');
|
||||||
}
|
}
|
||||||
JSONObject.indent(writer, newindent);
|
JSONObject.indent(writer, newindent);
|
||||||
JSONObject.writeValue(writer, this.myArrayList.get(i), indentFactor, newindent);
|
JSONObject.writeValue(writer, this.myArrayList.get(i),
|
||||||
|
indentFactor, newindent);
|
||||||
commanate = true;
|
commanate = true;
|
||||||
}
|
}
|
||||||
if (indentFactor > 0) {
|
if (indentFactor > 0) {
|
||||||
|
|||||||
@@ -18,71 +18,46 @@ public class MysqlFunctions {
|
|||||||
|
|
||||||
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
|
private static cn.citycraft.RealBackpacks.RealBackpacks plugin;
|
||||||
|
|
||||||
public static void setMysqlFunc(final RealBackpacks plugin) {
|
public static void addBackpackData(final String playerName,
|
||||||
MysqlFunctions.plugin = plugin;
|
final String backpack, final List<String> invString)
|
||||||
}
|
throws SQLException {
|
||||||
|
plugin.getServer().getScheduler()
|
||||||
public static boolean checkIfTableExists(final String table) {
|
.runTaskAsynchronously(plugin, new Runnable() {
|
||||||
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<String> invString) throws SQLException {
|
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl()+"?"
|
String url = plugin.getUrl()
|
||||||
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
+ "?"
|
||||||
final Connection conn = DriverManager.getConnection(url);
|
+ "user="
|
||||||
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
|
+ 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(1, playerName);
|
||||||
statement.setString(2, backpack);
|
statement.setString(2, backpack);
|
||||||
final ResultSet res = statement.executeQuery();
|
final ResultSet res = statement.executeQuery();
|
||||||
PreparedStatement state = null;
|
PreparedStatement state = null;
|
||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
if (res.getInt(1) == 1) {
|
if (res.getInt(1) == 1) {
|
||||||
state = conn.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
state = conn
|
||||||
|
.prepareStatement("UPDATE rb_data SET player=?, backpack=?, inventory=? WHERE player=? AND backpack=?;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
state.setString(3, Serialization.listToString(invString));
|
state.setString(3, Serialization
|
||||||
|
.listToString(invString));
|
||||||
state.setString(4, playerName);
|
state.setString(4, playerName);
|
||||||
state.setString(5, backpack);
|
state.setString(5, backpack);
|
||||||
} else {
|
} else {
|
||||||
state = conn.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
state = conn
|
||||||
|
.prepareStatement("INSERT INTO rb_data (player, backpack, inventory) VALUES(?, ?, ?);");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
state.setString(3, Serialization.listToString(invString));
|
state.setString(3, Serialization
|
||||||
|
.listToString(invString));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.executeUpdate();
|
state.executeUpdate();
|
||||||
@@ -95,20 +70,94 @@ public class MysqlFunctions {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Inventory getBackpackInv(final String playerName, final String backpack) throws SQLException {
|
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;
|
Inventory returnInv = null;
|
||||||
try {
|
try {
|
||||||
String url = plugin.getUrl()+"?"
|
String url = plugin.getUrl() + "?" + "user=" + plugin.getUser()
|
||||||
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
|
+ "&password=" + plugin.getPass()
|
||||||
|
+ "&useUnicode=true&characterEncoding=utf-8";
|
||||||
final Connection conn = DriverManager.getConnection(url);
|
final Connection conn = DriverManager.getConnection(url);
|
||||||
final PreparedStatement state = conn.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
final PreparedStatement state = conn
|
||||||
|
.prepareStatement("SELECT inventory FROM rb_data WHERE player=? AND backpack=? LIMIT 1;");
|
||||||
state.setString(1, playerName);
|
state.setString(1, playerName);
|
||||||
state.setString(2, backpack);
|
state.setString(2, backpack);
|
||||||
final ResultSet res = state.executeQuery();
|
final ResultSet res = state.executeQuery();
|
||||||
if (res.next()) {
|
if (res.next()) {
|
||||||
final String invString = res.getString(1);
|
final String invString = res.getString(1);
|
||||||
if (invString != null) {
|
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)));
|
returnInv = Serialization.toInventory(Serialization
|
||||||
|
.stringToList(invString), ChatColor
|
||||||
|
.translateAlternateColorCodes('&',
|
||||||
|
plugin.backpackData.get(backpack).get(3)),
|
||||||
|
Integer.parseInt(plugin.backpackData.get(backpack)
|
||||||
|
.get(0)));
|
||||||
} else {
|
} else {
|
||||||
returnInv = null;
|
returnInv = null;
|
||||||
}
|
}
|
||||||
@@ -121,25 +170,8 @@ public class MysqlFunctions {
|
|||||||
return returnInv;
|
return returnInv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void delete(final String playerName, final String backpack) {
|
public static void setMysqlFunc(final RealBackpacks plugin) {
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
MysqlFunctions.plugin = plugin;
|
||||||
@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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
name: RealBackpacks
|
name: RealBackpacks
|
||||||
main: cn.citycraft.RealBackpacks.RealBackpacks
|
main: cn.citycraft.RealBackpacks.RealBackpacks
|
||||||
version: 1.6.5
|
version: 0.1.3
|
||||||
author: Slayr288,喵♂呜
|
author: Slayr288,喵♂呜
|
||||||
softdepend: [Vault,BVLib]
|
softdepend: [Vault]
|
||||||
commands:
|
commands:
|
||||||
rb:
|
rb:
|
||||||
description: Main commands.
|
description: Main commands.
|
||||||
|
|||||||
Reference in New Issue
Block a user