diff --git a/plumbot-bukkit/pom.xml b/plumbot-bukkit/pom.xml
index 702269a..8f0146f 100644
--- a/plumbot-bukkit/pom.xml
+++ b/plumbot-bukkit/pom.xml
@@ -6,7 +6,7 @@
me.regadpole
plumbot
- 1.3.2
+ 1.3.3
plumbot-bukkit
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/command/Commands.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/command/Commands.java
index 7e53519..ece2e0a 100644
--- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/command/Commands.java
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/command/Commands.java
@@ -4,6 +4,7 @@
import me.regadpole.plumbot.bot.KookBot;
import me.regadpole.plumbot.config.Config;
import me.regadpole.plumbot.config.DataBase;
+import me.regadpole.plumbot.internal.WhitelistHelper;
import me.regadpole.plumbot.internal.database.DatabaseManager;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
@@ -13,6 +14,7 @@
import snw.jkook.plugin.Plugin;
import java.util.Arrays;
+import java.util.List;
import java.util.stream.Collectors;
public class Commands implements CommandExecutor{
@@ -65,6 +67,69 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
sender.sendMessage("§6/pb info :§f插件基本信息");
sender.sendMessage("§6/pb kook help :§f获取kook帮助");
sender.sendMessage("§6/pb kook plugins :§f获取kook插件列表");
+ sender.sendMessage("§6/pb queryBind :§f查询id或qq绑定数据");
+ sender.sendMessage("§6/pb addBind :§f为qq添加ID白名单");
+ break;
+ case "queryBind":
+ if (args.length == 1) {
+ sender.sendMessage("命令错误,格式:/plumbot queryBind ");
+ return true;
+ }
+ if (args.length > 2) {
+ sender.sendMessage("命令错误,格式:/plumbot queryBind ");
+ return true;
+ }
+ if (args.length == 2) {
+ if (args[1].startsWith("id:")) {
+ String name = args[1].substring(3);
+ if (name.isEmpty()) {
+ sender.sendMessage("id不能为空");
+ return true;
+ }
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ long qq = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (qq==0L) {
+ sender.sendMessage("ID尚未申请白名单");
+ return;
+ }
+ sender.sendMessage(name+"的申请用户为"+qq);
+ });
+ return true;
+ } else if (args[1].startsWith("qq:")) {
+ String qq = args[1].substring(3);
+ if (qq.isEmpty()) {
+ sender.sendMessage("QQ不能为空");
+ return true;
+ }
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ List id = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (id.isEmpty()) {
+ sender.sendMessage(qq+"尚未申请白名单");
+ return;
+ }
+ sender.sendMessage(qq+"拥有白名单ID:"+id);
+ });
+ return true;
+ }
+ break;
+ }
+ case "addBind":
+ if (args.length == 1) {
+ sender.sendMessage("命令错误,格式:/plumbot queryBind ");
+ return true;
+ }
+ if (args.length > 2) {
+ sender.sendMessage("命令错误,格式:/plumbot queryBind ");
+ return true;
+ }
+ if (args.length == 2) {
+ if (!WhitelistHelper.checkIDNotExist(args[1])) {
+ sender.sendMessage("绑定失败,此ID已绑定用户" + DatabaseManager.getBindId(args[1], DataBase.type().toLowerCase(), PlumBot.getDatabase()));
+ return true;
+ }
+ List id = WhitelistHelper.addAndGet(args[1], args[0], DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ sender.sendMessage("成功申请白名单," + args[0] + "目前的白名单为" + id);
+ }
break;
case "kook":
if (args.length == 1) {
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/config/Config.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/config/Config.java
index 01a162a..5233767 100644
--- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/config/Config.java
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/config/Config.java
@@ -41,7 +41,7 @@ public static void createConfig(){
if (!Config.getBotYamlVersion().equals("1.3.0")){
INSTANCE.saveResource(botFile.getName(), true);
}
- if (!Config.getConfigYamlVersion().equals("1.3.1")){
+ if (!Config.getConfigYamlVersion().equals("1.3.2")){
INSTANCE.saveResource(configFile.getName(), true);
}
if (!Config.getCommandsYamlVersion().equals("1.2.2")){
@@ -126,6 +126,10 @@ public static boolean WhiteList(){
return getConfigYaml().getBoolean("WhiteList.enable");
}
+ public static int WhiteListMaxCount(){
+ return getConfigYaml().getInt("WhiteList.maxCount");
+ }
+
public static boolean JoinAndLeave(){
return getConfigYaml().getBoolean("JoinAndLeave");
}
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java
index bc2feb3..758bafc 100644
--- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java
@@ -126,8 +126,8 @@ public void onChannelMessageReceive(ChannelMessageEvent e) {
return;
}
PlumBot.getScheduler().runTaskAsynchronously(() -> {
- String idForName = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (idForName == null) {
+ List idForName = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
e.getMessage().reply("尚未申请白名单");
return;
}
@@ -225,8 +225,8 @@ public void onChannelMessageReceive(ChannelMessageEvent e) {
return;
}
PlumBot.getScheduler().runTaskAsynchronously(() -> {
- String idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (idForName == null || idForName.isEmpty()) {
+ List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
e.getMessage().reply("您尚未申请白名单");
return;
}
@@ -348,10 +348,10 @@ public void onPrivateMessageReceive(PrivateMessageReceivedEvent e) {
public void onGroupDecreaseNotice(UserLeaveGuildEvent e) {
String userId = e.getUser().getId();
String groupId = e.getGuildId();
- String player = DatabaseManager.getBind(userId, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (player == null) {
+ List player = DatabaseManager.getBind(userId, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (player.isEmpty()) {
return;
}
- DatabaseManager.removeBindid(player, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ DatabaseManager.removeBind(userId, DataBase.type().toLowerCase(), PlumBot.getDatabase());
}
}
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java
index ed2e1d0..ad31f6e 100644
--- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java
@@ -8,6 +8,7 @@
import me.regadpole.plumbot.event.server.ServerManager;
import me.regadpole.plumbot.event.server.ServerTps;
import me.regadpole.plumbot.internal.FoliaSupport;
+import me.regadpole.plumbot.internal.WhitelistHelper;
import me.regadpole.plumbot.internal.database.DatabaseManager;
import me.regadpole.plumbot.tool.StringTool;
import org.bukkit.Bukkit;
@@ -124,43 +125,54 @@ public void onGroupMessageReceive(GroupMessage e){
if (!Config.WhiteList()) {
return;
}
- String name = matcher.group().replace(Prefix + "删除白名单 ", "");
- if (name.isEmpty()) {
- bot.sendMsg(true, "id不能为空", groupID);
+ String para = matcher.group().replace(Prefix + "删除白名单 ", "");
+ if (para.isEmpty()) {
+ bot.sendMsg(true, "参数不能为空", groupID);
return;
}
- PlumBot.getScheduler().runTaskAsynchronously(() -> {
- long nameForId = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (nameForId == 0L) {
- bot.sendMsg(true, "尚未申请白名单", groupID);
+ if (para.startsWith("id:")) {
+ String name = para.substring(3);
+ if (name.isEmpty()) {
+ bot.sendMsg(true, "id不能为空", groupID);
return;
}
- DatabaseManager.removeBindid(name, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- bot.sendMsg(true, "成功移出白名单", groupID);
- });
- return;
- }
-
- pattern = Pattern.compile(Prefix + "删除User白名单 .*");
- matcher = pattern.matcher(msg);
- if (matcher.find()) {
- if (!Config.WhiteList()) {
- return;
- }
- String qq = matcher.group().replace(Prefix + "删除User白名单 ", "");
- if (qq.isEmpty()) {
- bot.sendMsg(true, "QQ不能为空", groupID);
- return;
- }
- PlumBot.getScheduler().runTaskAsynchronously(() -> {
- String idForName = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (idForName == null) {
- bot.sendMsg(true, "尚未申请白名单", groupID);
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ if (WhitelistHelper.checkIDNotExist(name)) {
+ bot.sendMsg(true, "ID尚未申请白名单", groupID);
+ return;
+ }
+ DatabaseManager.removeBindid(name, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功移出白名单", groupID);
+ });
+ } else if (para.startsWith("qq:")) {
+ String qq = para.substring(3);
+ if (qq.isEmpty()) {
+ bot.sendMsg(true, "QQ不能为空", groupID);
return;
}
- DatabaseManager.removeBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
- bot.sendMsg(true, "成功移出白名单", groupID);
- });
+ String[] p = qq.split(" ");
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ List idForName = DatabaseManager.getBind(p[0], DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
+ bot.sendMsg(true, p[0]+"尚未申请白名单", groupID);
+ return;
+ }
+ int num = Integer.parseInt(p[1]);
+ DatabaseManager.removeBind(p[0], num, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功移出白名单,"+p[0]+"目前拥有的白名单为"+DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ });
+ } else {
+ int num = Integer.parseInt(matcher.group().replace(Prefix + "删除白名单 ", ""));
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
+ bot.sendMsg(true, "您尚未申请白名单", groupID);
+ return;
+ }
+ DatabaseManager.removeBind(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功移出白名单,您目前拥有的白名单为"+DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ });
+ }
return;
}
@@ -190,12 +202,14 @@ public void onGroupMessageReceive(GroupMessage e){
messages.add(Prefix+"在线人数 查看服务器当前在线人数");
messages.add(Prefix+"tps 查看服务器当前tps");
messages.add(Prefix+"申请白名单 为自己申请白名单");
- messages.add(Prefix+"删除白名单 删除自己的白名单");
+ messages.add(Prefix+"删除白名单 <序号> 删除自己的白名单");
+ messages.add(Prefix+"查询白名单 查询自己的白名单");
messages.add("管理命令:");
messages.add(Prefix+"cmd 向服务器发送命令");
- messages.add(Prefix+"删除白名单 删除指定游戏id的白名单");
- messages.add(Prefix+"删除User白名单 删除指定群成员的白名单");
- for (String message : messages) {
+ messages.add(Prefix+"申请白名单 为指定用户申请白名单");
+ messages.add(Prefix+"删除白名单 删除指定游戏id或qq的白名单");
+ messages.add(Prefix+"查询白名单 查询指定游戏id或qq的白名单");
+ for (String message : messages) {
if (messages.get(messages.size() - 1).equalsIgnoreCase(message)) {
stringBuilder.append(message.replaceAll("§\\S", ""));
} else {
@@ -223,42 +237,129 @@ public void onGroupMessageReceive(GroupMessage e){
return;
}
- pattern = Pattern.compile(Prefix + "申请白名单 .*");
+ pattern = Pattern.compile(Prefix + "查询白名单 .*");
matcher = pattern.matcher(msg);
if (matcher.find()) {
if (!Config.WhiteList()) {
return;
}
- String PlayerName = matcher.group().replace(Prefix + "申请白名单 ", "");
- if (PlayerName.isEmpty()) {
- bot.sendMsg(true, "id不能为空", groupID);
- return;
+ if(Config.getAdmins().contains(senderID)) {
+ String para = matcher.group().replace(Prefix + "查询白名单 ", "");
+ if (para.isEmpty()) {
+ bot.sendMsg(true, "参数不能为空", groupID);
+ return;
+ }
+ if (para.startsWith("id:")) {
+ String name = para.substring(3);
+ if (name.isEmpty()) {
+ bot.sendMsg(true, "id不能为空", groupID);
+ return;
+ }
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ long qq = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (qq==0L) {
+ bot.sendMsg(true, "ID尚未申请白名单", groupID);
+ return;
+ }
+ bot.sendMsg(true, name+"的申请用户为"+qq, groupID);
+ });
+ } else if (para.startsWith("qq:")) {
+ String qq = para.substring(3);
+ if (qq.isEmpty()) {
+ bot.sendMsg(true, "QQ不能为空", groupID);
+ return;
+ }
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ List id = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (id.isEmpty()) {
+ bot.sendMsg(true, qq+"尚未申请白名单", groupID);
+ return;
+ }
+ bot.sendMsg(true, qq+"拥有白名单ID:"+id, groupID);
+ });
+ } else {
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ List id = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (id.isEmpty()) {
+ bot.sendMsg(true, "您尚未申请白名单", groupID);
+ return;
+ }
+ bot.sendMsg(true, senderID+"拥有白名单ID:"+id, groupID);
+ });
+ }
}
PlumBot.getScheduler().runTaskAsynchronously(() -> {
- if ((DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()) != null) || (DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase()) != 0L)) {
- bot.sendMsg(true, "绑定失败", groupID);
+ List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
+ bot.sendMsg(true, "您尚未申请白名单", groupID);
return;
}
- DatabaseManager.addBind(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
- bot.sendMsg(true, "成功申请白名单", groupID);
+ bot.sendMsg(true, senderID +"拥有白名单ID:"+idForName, groupID);
});
return;
}
- pattern = Pattern.compile(Prefix + "删除白名单");
+ pattern = Pattern.compile(Prefix + "申请白名单 .*");
+ matcher = pattern.matcher(msg);
+ if (matcher.find()) {
+ if (!Config.WhiteList()) {
+ return;
+ }
+ String PlayerName = matcher.group().replace(Prefix + "申请白名单 ", "");
+ String[] para = PlayerName.split(" ");
+ if (para.length==1){
+ if (PlayerName.isEmpty()) {
+ bot.sendMsg(true, "id不能为空", groupID);
+ return;
+ }
+ if(Config.getAdmins().contains(senderID)) {
+ if (!WhitelistHelper.checkIDNotExist(PlayerName)) {
+ bot.sendMsg(true, "绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ return;
+ }
+ List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功申请白名单,您目前的白名单为"+id, groupID);
+ }
+ PlumBot.getScheduler().runTaskAsynchronously(() -> {
+ if (WhitelistHelper.checkCount(String.valueOf(senderID))) {
+ bot.sendMsg(true, "绑定失败,该用户已绑定:"+DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ return;
+ }
+ if (!WhitelistHelper.checkIDNotExist(PlayerName)){
+ bot.sendMsg(true, "绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ return;
+ }
+ List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功申请白名单,您目前的白名单为"+id, groupID);
+ });
+ } else if (para.length==2) {
+ if(Config.getAdmins().contains(senderID)) {
+ if (!WhitelistHelper.checkIDNotExist(para[1])) {
+ bot.sendMsg(true, "绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(para[1], DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
+ return;
+ }
+ List id = WhitelistHelper.addAndGet(para[1], para[0], DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功申请白名单,"+para[0]+"目前的白名单为"+id, groupID);
+ }
+ }
+ return;
+ }
+
+ pattern = Pattern.compile(Prefix + "删除白名单 .*");
matcher = pattern.matcher(msg);
if (matcher.find()) {
if (!Config.WhiteList()) {
return;
}
+ int num = Integer.parseInt(matcher.group().replace(Prefix + "删除白名单 ", ""));
PlumBot.getScheduler().runTaskAsynchronously(() -> {
- String idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (idForName == null || idForName.isEmpty()) {
+ List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (idForName.isEmpty()) {
bot.sendMsg(true, "您尚未申请白名单", groupID);
return;
}
- DatabaseManager.removeBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
- bot.sendMsg(true, "成功移出白名单", groupID);
+ DatabaseManager.removeBind(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ bot.sendMsg(true, "成功移出白名单,您目前的白名单为"+DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID);
});
return;
}
@@ -354,8 +455,8 @@ public void onGroupMessageReceive(GroupMessage e){
public void onGroupDecreaseNotice(GroupDecreaseNotice e) {
long userId = e.getUserId();
long groupId = e.getGroupId();
- String player = DatabaseManager.getBind(String.valueOf(userId), DataBase.type().toLowerCase(), PlumBot.getDatabase());
- if (player == null) {
+ List player = DatabaseManager.getBind(String.valueOf(userId), DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ if (player.isEmpty()) {
return;
}
DatabaseManager.removeBind(String.valueOf(userId), DataBase.type().toLowerCase(), PlumBot.getDatabase());
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/WhitelistHelper.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/WhitelistHelper.java
new file mode 100644
index 0000000..4a6d5dd
--- /dev/null
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/WhitelistHelper.java
@@ -0,0 +1,28 @@
+package me.regadpole.plumbot.internal;
+
+import me.regadpole.plumbot.PlumBot;
+import me.regadpole.plumbot.config.Config;
+import me.regadpole.plumbot.config.DataBase;
+import me.regadpole.plumbot.internal.database.Database;
+import me.regadpole.plumbot.internal.database.DatabaseManager;
+
+import java.util.List;
+
+public class WhitelistHelper {
+
+ public static boolean checkCount(String qq){
+ List idList = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase());
+ int maxCount = Config.WhiteListMaxCount();
+ if (idList == null) return true;
+ return idList.size() < maxCount;
+ }
+
+ public static boolean checkIDNotExist(String id){
+ return DatabaseManager.getBindId(id, DataBase.type().toLowerCase(), PlumBot.getDatabase()) == 0L;
+ }
+
+ public static List addAndGet(String id, String qq, String mode, Database db){
+ DatabaseManager.addBind(id, qq, mode, db);
+ return DatabaseManager.getBind(qq, mode, db);
+ }
+}
diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/database/DatabaseManager.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/database/DatabaseManager.java
index a2c1870..45f487a 100644
--- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/database/DatabaseManager.java
+++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/database/DatabaseManager.java
@@ -8,6 +8,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
public class DatabaseManager {
@@ -62,13 +64,7 @@ public static void addBind(String id, String qq, String mode, Database db) {
ResultSet resultSetid = statement.executeQuery(selectid);
ResultSet resultSetqq = statement1.executeQuery(selectqq);
- if (!resultSetid.isBeforeFirst() && resultSetqq.isBeforeFirst()) {
- statement.executeUpdate(updateid);
- } else if (resultSetid.isBeforeFirst() && !resultSetqq.isBeforeFirst()) {
- statement.executeUpdate(updateqq);
- } else if (!resultSetid.isBeforeFirst() && !resultSetqq.isBeforeFirst()) {
- statement.executeUpdate(insert);
- }
+ statement.executeUpdate(insert);
resultSetid.close();
resultSetqq.close();
@@ -85,13 +81,7 @@ public static void addBind(String id, String qq, String mode, Database db) {
ResultSet resultSetid = connection.prepareStatement(selectid).executeQuery();
ResultSet resultSetqq = connection.prepareStatement(selectqq).executeQuery();
- if (!resultSetid.isBeforeFirst() && resultSetqq.isBeforeFirst()) {
- connection.prepareStatement(updateid).executeUpdate();
- } else if (resultSetid.isBeforeFirst() && !resultSetqq.isBeforeFirst()) {
- connection.prepareStatement(updateqq).executeUpdate();
- } else if (!resultSetid.isBeforeFirst() && !resultSetqq.isBeforeFirst()) {
- connection.prepareStatement(insert).executeUpdate();
- }
+ connection.prepareStatement(insert).executeUpdate();
resultSetid.close();
resultSetqq.close();
@@ -107,7 +97,7 @@ public static void addBind(String id, String qq, String mode, Database db) {
public static void removeBindid(String id,String mode, Database db) {
String createTable = "CREATE TABLE IF NOT EXISTS whitelist (id TINYTEXT NOT NULL, qq long NOT NULL);";
- String select = "SELECT * FROM whitelist WHERE id='" + id + "' LIMIT 1;";
+ String select = "SELECT * FROM whitelist WHERE id='" + id + "';";
String delete = "DELETE FROM whitelist WHERE id='" + id + "';";
try {
@@ -149,9 +139,69 @@ public static void removeBindid(String id,String mode, Database db) {
}
}
- public static void removeBind(String qq,String mode, Database db) {
+ public static void removeBind(String qq, int num, String mode, Database db) {
String createTable = "CREATE TABLE IF NOT EXISTS whitelist (id TINYTEXT NOT NULL, qq long NOT NULL);";
- String select = "SELECT * FROM whitelist WHERE qq=" + qq + " LIMIT 1;";
+ String select = "SELECT * FROM whitelist WHERE qq=" + qq + ";";
+
+ try {
+ Connection connection = db.getConnection();
+ switch (mode){
+ case "sqlite":
+ default: {
+ Statement statement = connection.createStatement();
+ statement.executeUpdate(createTable);
+
+ // 如果没有找到记录为false,找到就是true
+ ResultSet resultSet = statement.executeQuery(select);
+
+ if (resultSet.isBeforeFirst()) {
+ resultSet.next();
+ }
+ for (int i = 1; i < num; i++) {
+ resultSet.next();
+ }
+ if (resultSet.isAfterLast()){
+ return;
+ }
+ String id = resultSet.getString("id");
+ String delete = "DELETE FROM whitelist WHERE qq=" + qq+" AND id='" + id + "';";
+ statement.executeUpdate(delete);
+ resultSet.close();
+ statement.close();
+ connection.close();
+
+ break;
+ }
+ case "mysql": {
+ connection.prepareStatement(createTable).executeUpdate();
+
+ ResultSet resultSet = connection.prepareStatement(select).executeQuery();
+
+ if (resultSet.isBeforeFirst()) {
+ resultSet.next();
+ }
+ for (int i = 1; i < num; i++) {
+ resultSet.next();
+ }
+ if (resultSet.isAfterLast()){
+ return;
+ }
+ String id = resultSet.getString("id");
+ String delete = "DELETE FROM whitelist WHERE qq=" + qq+" AND id='" + id + "';";
+ connection.prepareStatement(delete).executeUpdate();
+ resultSet.close();
+ connection.close();
+ break;
+ }
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void removeBind(String qq, String mode, Database db) {
+ String createTable = "CREATE TABLE IF NOT EXISTS whitelist (id TINYTEXT NOT NULL, qq long NOT NULL);";
+ String select = "SELECT * FROM whitelist WHERE qq=" + qq + ";";
String delete = "DELETE FROM whitelist WHERE qq=" + qq+";";
try {
@@ -167,8 +217,8 @@ public static void removeBind(String qq,String mode, Database db) {
if (resultSet.isBeforeFirst()) {
resultSet.next();
- statement.executeUpdate(delete);
}
+ statement.executeUpdate(delete);
resultSet.close();
statement.close();
connection.close();
@@ -182,8 +232,8 @@ public static void removeBind(String qq,String mode, Database db) {
if (resultSet.isBeforeFirst()) {
resultSet.next();
- connection.prepareStatement(delete).executeUpdate();
}
+ connection.prepareStatement(delete).executeUpdate();
resultSet.close();
connection.close();
break;
@@ -194,11 +244,11 @@ public static void removeBind(String qq,String mode, Database db) {
}
}
- public static long getBindId(String id,String mode, Database db) {
+ public static long getBindId(String id, String mode, Database db) {
long qq = 0L;
String createTable = "CREATE TABLE IF NOT EXISTS whitelist (id TINYTEXT NOT NULL, qq long NOT NULL);";
- String select = "SELECT * FROM whitelist WHERE id='" + id + "' LIMIT 1;";
+ String select = "SELECT * FROM whitelist WHERE id='" + id + "' ;";
try {
Connection connection = db.getConnection();
@@ -238,10 +288,9 @@ public static long getBindId(String id,String mode, Database db) {
}
return qq;
}
-
- @Nullable
- public static String getBind(String qq,String mode, Database db) {
- String id = null;
+
+ public static List getBind(String qq,String mode, Database db) {
+ List id = new ArrayList<>();
String createTable = "CREATE TABLE IF NOT EXISTS whitelist (id TINYTEXT NOT NULL, qq long NOT NULL);";
String select = "SELECT * FROM whitelist WHERE qq=" + qq + " LIMIT 1;";
@@ -257,7 +306,10 @@ public static String getBind(String qq,String mode, Database db) {
if (resultSet.isBeforeFirst()) {
resultSet.next();
}
- id = resultSet.getString("id");
+ do {
+ id.add(resultSet.getString("id"));
+ resultSet.next();
+ }while(!resultSet.isAfterLast());
resultSet.close();
connection.close();
break;
@@ -272,7 +324,10 @@ public static String getBind(String qq,String mode, Database db) {
if (resultSet.isBeforeFirst()) {
resultSet.next();
}
- id = resultSet.getString("id");
+ do {
+ id.add(resultSet.getString("id"));
+ resultSet.next();
+ }while(!resultSet.isAfterLast());
resultSet.close();
statement.close();
connection.close();
@@ -285,4 +340,5 @@ public static String getBind(String qq,String mode, Database db) {
}
return id;
}
+
}
diff --git a/plumbot-bukkit/src/main/resources/config.yml b/plumbot-bukkit/src/main/resources/config.yml
index 1da7596..8d1b245 100644
--- a/plumbot-bukkit/src/main/resources/config.yml
+++ b/plumbot-bukkit/src/main/resources/config.yml
@@ -1,5 +1,5 @@
#机器人功能设置
-Ver: "1.3.1"
+Ver: "1.3.2"
#QQ群聊命令前缀
Prefix: "/"
@@ -17,6 +17,7 @@ DieReport: false
WhiteList:
enable: false
kickMsg: "请加入qq群:xxx申请白名单"
+ maxCount: 1
#执行命令功能
CMD: true
diff --git a/plumbot-bungee/pom.xml b/plumbot-bungee/pom.xml
index 87d5ae9..24b3a68 100644
--- a/plumbot-bungee/pom.xml
+++ b/plumbot-bungee/pom.xml
@@ -6,7 +6,7 @@
me.regadpole
plumbot
- 1.3.2
+ 1.3.3
plumbot-bungee
diff --git a/plumbot-velocity/pom.xml b/plumbot-velocity/pom.xml
index d90cc81..2d1b455 100644
--- a/plumbot-velocity/pom.xml
+++ b/plumbot-velocity/pom.xml
@@ -6,7 +6,7 @@
me.regadpole
plumbot
- 1.3.2
+ 1.3.3
plumbot-velocity
diff --git a/pom.xml b/pom.xml
index 8e544af..d506f33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,14 +6,14 @@
me.regadpole
plumbot
- 1.3.2
+ 1.3.3
pom
PlumBot
- plumbot-velocity
plumbot-bukkit
plumbot-bungee
+ plumbot-velocity