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

rebuild priject...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-05-28 20:58:32 +08:00
parent 7b1ea95b81
commit cfce6987c0
5 changed files with 608 additions and 573 deletions

View File

@ -55,28 +55,26 @@ public class RealBackpacks extends JavaPlugin {
public List<String> adminRestrictedView = new ArrayList<String>();
public List<String> slowedPlayers = new ArrayList<String>();
/*
* 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();
@ -134,17 +132,14 @@ public class RealBackpacks extends JavaPlugin {
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);

View File

@ -30,11 +30,6 @@ 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);
}
@ -53,19 +48,14 @@ public class FileConfig extends YamlConfiguration {
return config;
}
@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 DumperOptions yamlOptions = new DumperOptions();
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,
InvalidConfigurationException {
Validate.notNull(file, "File cannot be null");
@ -73,6 +63,7 @@ public class FileConfig extends YamlConfiguration {
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);
@ -85,4 +76,17 @@ public class FileConfig extends YamlConfiguration {
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;
}
}

View File

@ -41,11 +41,20 @@ public class JSONArray {
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 {
this();
if (x.nextClean() != '[') {
if (x.nextClean() != '[')
throw x.syntaxError("A JSONArray text must start with '['");
}
if (x.nextClean() != ']') {
x.back();
for (;;) {
@ -59,9 +68,8 @@ public class JSONArray {
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == ']') {
if (x.nextClean() == ']')
return;
}
x.back();
break;
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 {
this();
if (array.getClass().isArray()) {
@ -94,33 +88,40 @@ public class JSONArray {
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.");
} 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) {
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"))) {
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"))) {
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);
return object instanceof Number ? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
@ -129,7 +130,8 @@ public class JSONArray {
public int getInt(int index) throws JSONException {
Object object = this.get(index);
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) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
@ -137,24 +139,23 @@ public class JSONArray {
public JSONArray getJSONArray(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof JSONArray) {
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) {
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);
return object instanceof Number ? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
throw new JSONException("JSONArray[" + index + "] is not a number.");
}
@ -162,9 +163,8 @@ public class JSONArray {
public String getString(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof String) {
if (object instanceof String)
return (String) object;
}
throw new JSONException("JSONArray[" + index + "] not a string.");
}
@ -190,7 +190,8 @@ public class JSONArray {
}
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) {
@ -257,7 +258,8 @@ public class JSONArray {
public String optString(int index, String defaultValue) {
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) {
@ -282,21 +284,6 @@ public class JSONArray {
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;
@ -329,9 +316,8 @@ public class JSONArray {
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0) {
if (index < 0)
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < this.length()) {
this.myArrayList.set(index, value);
} else {
@ -343,6 +329,21 @@ public class JSONArray {
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);
@ -350,9 +351,8 @@ public class JSONArray {
}
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;
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.length(); i += 1) {
jo.put(names.getString(i), this.opt(i));
@ -360,6 +360,7 @@ public class JSONArray {
return jo;
}
@Override
public String toString() {
try {
return this.toString(0);
@ -379,14 +380,16 @@ public class JSONArray {
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 {
boolean commanate = false;
int length = this.length();
writer.write('[');
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) {
final int newindent = indent + indentFactor;
@ -398,7 +401,8 @@ public class JSONArray {
writer.write('\n');
}
JSONObject.indent(writer, newindent);
JSONObject.writeValue(writer, this.myArrayList.get(i), indentFactor, newindent);
JSONObject.writeValue(writer, this.myArrayList.get(i),
indentFactor, newindent);
commanate = true;
}
if (indentFactor > 0) {

View File

@ -18,71 +18,46 @@ public class MysqlFunctions {
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<String> invString) throws SQLException {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
public static void addBackpackData(final String playerName,
final String backpack, final List<String> invString)
throws SQLException {
plugin.getServer().getScheduler()
.runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
String url = plugin.getUrl()+"?"
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
final Connection conn = DriverManager.getConnection(url);
PreparedStatement statement = conn.prepareStatement("SELECT EXISTS(SELECT 1 FROM rb_data WHERE player = ? AND backpack = ? LIMIT 1);");
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 = 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(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 = 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.setString(3, Serialization
.listToString(invString));
}
}
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;
try {
String url = plugin.getUrl()+"?"
+ "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8";
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;");
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)));
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;
}
@ -121,25 +170,8 @@ public class MysqlFunctions {
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 void setMysqlFunc(final RealBackpacks plugin) {
MysqlFunctions.plugin = plugin;
}
}

View File

@ -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.