From 2d951d12a20e541f594615208203824bb617ad71 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 27 Mar 2017 19:58:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DSQL=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 2 +- .../java/pw/yumc/DataStorage/DataStorage.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index eba8e6d..d7d793b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc DataStorage - 1.1 + 1.1.1 ${project.artifactId} diff --git a/src/main/java/pw/yumc/DataStorage/DataStorage.java b/src/main/java/pw/yumc/DataStorage/DataStorage.java index d2bf801..060d809 100644 --- a/src/main/java/pw/yumc/DataStorage/DataStorage.java +++ b/src/main/java/pw/yumc/DataStorage/DataStorage.java @@ -13,6 +13,7 @@ import me.clip.placeholderapi.PlaceholderHook; import pw.yumc.YumCore.commands.CommandSub; import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Help; +import pw.yumc.YumCore.commands.annotation.Sort; import pw.yumc.YumCore.commands.interfaces.Executor; import pw.yumc.YumCore.config.FileConfig; import pw.yumc.YumCore.sql.DataBase; @@ -68,9 +69,10 @@ public class DataStorage extends JavaPlugin implements Executor { } } + @Sort(0) @Cmd @Help(value = "创建一个键值对", possibleArguments = "<键> <值>") - public void create(CommandSender sender, String key, Integer value) { + public void create(CommandSender sender, String key, int value) { try { if (createValue(key, value)) { sender.sendMessage("§a成功创建了 §3" + key + " §a初始值为 §d" + value); @@ -82,9 +84,10 @@ public class DataStorage extends JavaPlugin implements Executor { sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!"); } + @Sort(3) @Cmd @Help(value = "移除一个键值对", possibleArguments = "<键>") - public void remove(CommandSender sender, String key, Integer value) { + public void remove(CommandSender sender, String key, int value) { try { if (removeValue(key)) { sender.sendMessage("§a成功移除了 §3" + key); @@ -96,9 +99,10 @@ public class DataStorage extends JavaPlugin implements Executor { sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!"); } + @Sort(1) @Cmd @Help(value = "键key的值添加value", possibleArguments = "<键> <值>") - public void add(CommandSender sender, String key, Integer value) { + public void add(CommandSender sender, String key, int value) { try { if (incValue(key, value)) { sender.sendMessage("§a成功给了 §3" + key + " §a增加了 §e" + value + " §a目前的值为 §d" + getValue(key)); @@ -110,9 +114,10 @@ public class DataStorage extends JavaPlugin implements Executor { sender.sendMessage("§c操作失败 请查看后台错误 (添加删除需要初始化)!"); } + @Sort(2) @Cmd @Help(value = "键key的值添加value", possibleArguments = "<键> <值>") - public void del(CommandSender sender, String key, Integer value) { + public void del(CommandSender sender, String key, int value) { try { if (decValue(key, value)) { sender.sendMessage("§a成功给了 §3" + key + " §c减少了 §e" + value + " §a目前的值为 §d" + getValue(key)); @@ -125,23 +130,23 @@ public class DataStorage extends JavaPlugin implements Executor { } private boolean createValue(String key, int value) throws SQLException { - return db.getDataBaseCore().update("INSERT INTO " + tableName + " (" + kfields + ", " + vfields + ") VALUES ('" + key + "', '" + value + "')") != 0; + return db.getDataBaseCore().update("INSERT INTO " + tableName + " (`" + kfields + "`, `" + vfields + "`) VALUES ('" + key + "', '" + value + "')") != 0; } private boolean removeValue(String key) throws SQLException { - return db.getDataBaseCore().update("DELETE FROM " + tableName + " WHERE " + kfields + " = '" + key + "'") != 0; + return db.getDataBaseCore().update("DELETE FROM " + tableName + " WHERE `" + kfields + "` = '" + key + "'") != 0; } private boolean incValue(String key, int value) throws SQLException { - return db.getDataBaseCore().update("UPDATE " + tableName + " SET " + vfields + " = " + vfields + " + " + value + " WHERE " + kfields + " = '" + key + "'") != 0; + return db.getDataBaseCore().update("UPDATE " + tableName + " SET `" + vfields + "` = " + vfields + " + " + value + " WHERE `" + kfields + "` = '" + key + "'") != 0; } private boolean decValue(String key, int value) throws SQLException { - return db.getDataBaseCore().update("UPDATE " + tableName + " SET " + vfields + " = " + vfields + " + " + value + " WHERE " + kfields + " = '" + key + "'") != 0; + return db.getDataBaseCore().update("UPDATE " + tableName + " SET `" + vfields + "` = `" + vfields + "` - " + value + " WHERE `" + kfields + "` = '" + key + "'") != 0; } private int getValue(String key) throws SQLException { - ResultSet result = db.getDataBaseCore().query("SELECT " + vfields + " FROM " + tableName + " WHERE " + kfields + " = '" + key + "' LIMIT 1"); + ResultSet result = db.getDataBaseCore().query("SELECT `" + vfields + "` FROM " + tableName + " WHERE `" + kfields + "` = '" + key + "' LIMIT 1"); if (result.next()) { return result.getInt(1); } return 0; }