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 ece2e0a..9893108 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 @@ -29,25 +29,25 @@ public Commands(PlumBot plugin){ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 0) { - sender.sendMessage("请使用/pb help查看命令使用方法"); + sender.sendMessage(plugin.getEnvironment().prefix+"§c请使用/pb help查看命令使用方法"); return true; } switch (args[0]) { case "info": StringBuilder stringbuilder = new StringBuilder(); - stringbuilder.append("§1---PlumBot 信息---").append("\n"); - stringbuilder.append("§a作者: ").append("§f").append(plugin.getEnvironment().author).append("\n"); - stringbuilder.append("§a版本: ").append("§f").append(plugin.getEnvironment().version).append("\n"); - stringbuilder.append("§a机器人平台: ").append("§f").append(Config.getBotMode()).append("\n"); - stringbuilder.append("§a数据库模式: ").append("§f").append(DataBase.type()).append("\n"); - stringbuilder.append("§a服务端版本: ").append("§f").append(Bukkit.getVersion()).append("\n"); - stringbuilder.append("§a兼容插件: ").append("\n"); - stringbuilder.append("\t").append("§bAuthMe: ").append(plugin.getEnvironment().authme).append("\n"); - stringbuilder.append("\t").append("§bGriefDefender: ").append(plugin.getEnvironment().griefdefender).append("\n"); - stringbuilder.append("\t").append("§bResidence: ").append(plugin.getEnvironment().residence).append("\n"); - stringbuilder.append("\t").append("§bQuickShop: ").append(plugin.getEnvironment().quickshop).append("\n"); - stringbuilder.append("\t").append("§bQuickShopHikari: ").append(plugin.getEnvironment().quickshophikari).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§1---PlumBot 信息---").append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a作者: ").append("§f").append(plugin.getEnvironment().author).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a版本: ").append("§f").append(plugin.getEnvironment().version).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a机器人平台: ").append("§f").append(Config.getBotMode()).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a数据库模式: ").append("§f").append(DataBase.type()).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a服务端版本: ").append("§f").append(Bukkit.getVersion()).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("§a兼容插件: ").append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("\t").append("§bAuthMe: ").append(plugin.getEnvironment().authme).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("\t").append("§bGriefDefender: ").append(plugin.getEnvironment().griefdefender).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("\t").append("§bResidence: ").append(plugin.getEnvironment().residence).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("\t").append("§bQuickShop: ").append(plugin.getEnvironment().quickshop).append("\n"); + stringbuilder.append(plugin.getEnvironment().prefix).append("\t").append("§bQuickShopHikari: ").append(plugin.getEnvironment().quickshophikari).append("\n"); sender.sendMessage(stringbuilder.toString()); break; case "reload": @@ -57,90 +57,90 @@ public boolean onCommand(CommandSender sender, Command command, String label, St Config.loadConfig(); DatabaseManager.start(); PlumBot.getBot().start(); - sender.sendMessage("PlumBot已重载"); + sender.sendMessage(plugin.getEnvironment().prefix+"§aPlumBot已重载"); break; case "help": if (args.length != 1) return true; - sender.sendMessage("§6PlumBot 机器人帮助菜单"); - sender.sendMessage("§6/pb reload :§f重载插件"); - sender.sendMessage("§6/pb help :§f获取插件帮助"); - 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白名单"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6PlumBot 机器人帮助菜单"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb reload :§f重载插件"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb help :§f获取插件帮助"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb info :§f插件基本信息"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb kook help :§f获取kook帮助"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb kook plugins :§f获取kook插件列表"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb queryBind :§f查询id或qq绑定数据"); + sender.sendMessage(plugin.getEnvironment().prefix+"§6/pb addBind :§f为qq添加ID白名单"); break; case "queryBind": if (args.length == 1) { - sender.sendMessage("命令错误,格式:/plumbot queryBind "); + sender.sendMessage(plugin.getEnvironment().prefix+"§c命令错误,格式:/plumbot queryBind "); return true; } if (args.length > 2) { - sender.sendMessage("命令错误,格式:/plumbot queryBind "); + sender.sendMessage(plugin.getEnvironment().prefix+"§c命令错误,格式:/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不能为空"); + sender.sendMessage(plugin.getEnvironment().prefix+"§cid不能为空"); return true; } PlumBot.getScheduler().runTaskAsynchronously(() -> { long qq = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); if (qq==0L) { - sender.sendMessage("ID尚未申请白名单"); + sender.sendMessage(plugin.getEnvironment().prefix+"§cID尚未申请白名单"); return; } - sender.sendMessage(name+"的申请用户为"+qq); + sender.sendMessage(plugin.getEnvironment().prefix+"§a"+name+"的申请用户为"+qq); }); return true; } else if (args[1].startsWith("qq:")) { String qq = args[1].substring(3); if (qq.isEmpty()) { - sender.sendMessage("QQ不能为空"); + sender.sendMessage(plugin.getEnvironment().prefix+"§cQQ不能为空"); return true; } PlumBot.getScheduler().runTaskAsynchronously(() -> { List id = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase()); if (id.isEmpty()) { - sender.sendMessage(qq+"尚未申请白名单"); + sender.sendMessage(plugin.getEnvironment().prefix+"§c"+qq+"尚未申请白名单"); return; } - sender.sendMessage(qq+"拥有白名单ID:"+id); + sender.sendMessage(plugin.getEnvironment().prefix+"§a"+qq+"拥有白名单ID:"+id); }); return true; } break; } case "addBind": - if (args.length == 1) { - sender.sendMessage("命令错误,格式:/plumbot queryBind "); + if (args.length < 3) { + sender.sendMessage(plugin.getEnvironment().prefix+"§c命令错误,格式:/plumbot addBind "); return true; } - if (args.length > 2) { - sender.sendMessage("命令错误,格式:/plumbot queryBind "); + if (args.length > 3) { + sender.sendMessage(plugin.getEnvironment().prefix+"§c命令错误,格式:/plumbot addBind "); return true; } - if (args.length == 2) { + if (args.length == 3) { if (!WhitelistHelper.checkIDNotExist(args[1])) { - sender.sendMessage("绑定失败,此ID已绑定用户" + DatabaseManager.getBindId(args[1], DataBase.type().toLowerCase(), PlumBot.getDatabase())); + sender.sendMessage(plugin.getEnvironment().prefix+"§c绑定失败,此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); + sender.sendMessage(plugin.getEnvironment().prefix+"§a成功申请白名单," + args[0] + "目前的白名单为" + id); } break; case "kook": if (args.length == 1) { - sender.sendMessage("命令错误,格式:/plumbot kook "); - sender.sendMessage("value可选值:plugins,help"); + sender.sendMessage(plugin.getEnvironment().prefix+"§c命令错误,格式:/plumbot kook "); + sender.sendMessage(plugin.getEnvironment().prefix+"§cvalue可选值:plugins,help"); return true; } if (args.length > 2) return true; if (args.length == 2) { if (KookBot.isKookEnabled()) { - sender.sendMessage("kook客户端未启动"); + sender.sendMessage(plugin.getEnvironment().prefix+"§ckook客户端未启动"); return true; } switch (args[1]) { @@ -156,7 +156,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St break; default: if (args.length != 1) return true; - sender.sendMessage("错误的指令用法,请使用/pb help查看命令使用方法"); + sender.sendMessage(plugin.getEnvironment().prefix+"§c错误的指令用法,请使用/pb help查看命令使用方法"); break; } return true; 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 ad31f6e..7a2e242 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 @@ -144,6 +144,7 @@ public void onGroupMessageReceive(GroupMessage e){ DatabaseManager.removeBindid(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); bot.sendMsg(true, "成功移出白名单", groupID); }); + return; } else if (para.startsWith("qq:")) { String qq = para.substring(3); if (qq.isEmpty()) { @@ -158,9 +159,10 @@ public void onGroupMessageReceive(GroupMessage e){ 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); + List id = WhitelistHelper.removeAndGet(p[0], num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + bot.sendMsg(true, "成功移出白名单,"+p[0]+"目前拥有的白名单为"+id, groupID); }); + return; } else { int num = Integer.parseInt(matcher.group().replace(Prefix + "删除白名单 ", "")); PlumBot.getScheduler().runTaskAsynchronously(() -> { @@ -169,11 +171,11 @@ public void onGroupMessageReceive(GroupMessage e){ 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); + List id = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + bot.sendMsg(true, "成功移出白名单,您目前拥有的白名单为"+id, groupID); }); + return; } - return; } pattern = Pattern.compile(Prefix+".*"); @@ -193,6 +195,51 @@ public void onGroupMessageReceive(GroupMessage e){ } } + pattern = Pattern.compile(Prefix + "查询白名单 .*"); + matcher = pattern.matcher(msg); + if (matcher.find()) { + if (!Config.WhiteList()) { + return; + } + 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); + }); + return; + } 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); + }); + return; + } + return; + } + } if(msg.equals(Prefix+"帮助")) { @@ -237,57 +284,12 @@ 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; } - 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(() -> { List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); if (idForName.isEmpty()) { @@ -319,9 +321,10 @@ public void onGroupMessageReceive(GroupMessage e){ } List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); bot.sendMsg(true, "成功申请白名单,您目前的白名单为"+id, groupID); + return; } PlumBot.getScheduler().runTaskAsynchronously(() -> { - if (WhitelistHelper.checkCount(String.valueOf(senderID))) { + if (!WhitelistHelper.checkCount(String.valueOf(senderID))) { bot.sendMsg(true, "绑定失败,该用户已绑定:"+DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()), groupID); return; } @@ -332,6 +335,7 @@ public void onGroupMessageReceive(GroupMessage e){ List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); bot.sendMsg(true, "成功申请白名单,您目前的白名单为"+id, groupID); }); + return; } else if (para.length==2) { if(Config.getAdmins().contains(senderID)) { if (!WhitelistHelper.checkIDNotExist(para[1])) { @@ -340,6 +344,7 @@ public void onGroupMessageReceive(GroupMessage e){ } List id = WhitelistHelper.addAndGet(para[1], para[0], DataBase.type().toLowerCase(), PlumBot.getDatabase()); bot.sendMsg(true, "成功申请白名单,"+para[0]+"目前的白名单为"+id, groupID); + return; } } return; @@ -358,8 +363,8 @@ public void onGroupMessageReceive(GroupMessage e){ 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); + List result = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + bot.sendMsg(true, "成功移出白名单,您目前的白名单为"+result, groupID); }); return; } diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/Environment.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/Environment.java index 5f652e8..c283cf0 100644 --- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/Environment.java +++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/Environment.java @@ -18,6 +18,7 @@ public final class Environment { public final String quickshop = getPluginHooked(QuickShopHook.hasQs); public final String quickshophikari = getPluginHooked(QuickShopHook.hasQsHikari); public final String residence = getPluginHooked(ResidenceHook.hasRes); + public final String prefix = "§b§l[PlumBot]§r "; private String getPluginHooked(boolean hooked){ if (hooked){ 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 index 4a6d5dd..9a8a90b 100644 --- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/WhitelistHelper.java +++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/internal/WhitelistHelper.java @@ -13,7 +13,7 @@ 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; + if (idList.isEmpty()) return true; return idList.size() < maxCount; } @@ -25,4 +25,9 @@ public static List addAndGet(String id, String qq, String mode, Database DatabaseManager.addBind(id, qq, mode, db); return DatabaseManager.getBind(qq, mode, db); } + + public static List removeAndGet(String qq, int num, String mode, Database db){ + DatabaseManager.removeBind(qq, num, 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 45f487a..fedb559 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 @@ -202,7 +202,7 @@ public static void removeBind(String qq, int num, String mode, Database db) { 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+";"; + String delete = "DELETE FROM whitelist WHERE qq=" + qq + ";"; try { Connection connection = db.getConnection(); @@ -293,7 +293,7 @@ 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;"; + String select = "SELECT * FROM whitelist WHERE qq=" + qq + " ;"; try { Connection connection = db.getConnection();