From ffef13ef47f95d82471074b1c0b1a87bea4edfdb Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Fri, 10 Jan 2025 14:59:48 +0800 Subject: [PATCH 1/9] refactor(data): convert AuthData, PlayerData, and PlayerRecord classes to record classes --- .../suisuroru/data/AuthData/AuthData.java | 50 +------------------ .../suya/suisuroru/data/AuthData/DataGet.java | 6 +-- .../suisuroru/data/AuthData/DataProcess.java | 16 +++--- .../suisuroru/data/AuthData/PlayerData.java | 19 +------ .../suisuroru/data/AuthData/PlayerRecord.java | 50 +------------------ 5 files changed, 16 insertions(+), 125 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/AuthData.java b/src/main/java/fun/suya/suisuroru/data/AuthData/AuthData.java index 23a2d61..20710b9 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/AuthData.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/AuthData.java @@ -1,51 +1,5 @@ package fun.suya.suisuroru.data.AuthData; -public class AuthData { - private final PlayerData playerData; - private final long firstJoin; - private final long lastJoin; - private final long qqNumber; - private final long linkedTime; - private final String firstJoinIp; - private final String lastJoinIp; - - // 构造函数 - public AuthData(PlayerData playerData, long firstJoin, long lastJoin, long qqNumber, long linkedTime, String firstJoinIp, String lastJoinIp) { - this.playerData = playerData; - this.firstJoin = firstJoin; - this.lastJoin = lastJoin; - this.qqNumber = qqNumber; - this.linkedTime = linkedTime; - this.firstJoinIp = firstJoinIp; - this.lastJoinIp = lastJoinIp; - } - - // Getters - public PlayerData getPlayerData() { - return playerData; - } - - public long getFirstJoin() { - return firstJoin; - } - - public long getLastJoin() { - return lastJoin; - } - - public long getQqNumber() { - return qqNumber; - } - - public long getLinkedTime() { - return linkedTime; - } - - public String getFirstJoinIp() { - return firstJoinIp; - } - - public String getLastJoinIp() { - return lastJoinIp; - } +public record AuthData(PlayerData playerData, long firstJoin, long lastJoin, long qqNumber, long linkedTime, + String firstJoinIp, String lastJoinIp) { } diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java index bb7ef3b..111fb40 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java @@ -34,20 +34,20 @@ private List readDataFromFile(File file) { public List getPlayersByQQ(long qqNumber) { return playerRecords.stream() - .filter(record -> record.getQqNumber() == qqNumber) + .filter(record -> record.qqNumber() == qqNumber) .toList(); } public List getPlayersByName(String playerName) { return playerRecords.stream() - .filter(record -> record.getPlayerData().getPlayerName().equals(playerName)) + .filter(record -> record.playerData().playerName().equals(playerName)) .toList(); } public List getPlayersByUUID(UUID playerUuid) { return playerRecords.stream() .filter(record -> { - UUID recordUuid = record.getPlayerData().getPlayerUuid(); + UUID recordUuid = record.playerData().playerUuid(); return recordUuid.equals(playerUuid); }) .toList(); diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java index 7abcebc..639bd4f 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java @@ -8,14 +8,14 @@ public static String processData(String jsonData) { Gson gson = new Gson(); AuthData authData = gson.fromJson(jsonData, AuthData.class); StringBuilder result = new StringBuilder(); - result.append("玩家名称: ").append(authData.getPlayerData().getPlayerName()).append("\n"); - result.append("玩家UUID: ").append(authData.getPlayerData().getPlayerUuid()).append("\n"); - result.append("首次加入时间: ").append(authData.getFirstJoin()).append("\n"); - result.append("最后加入时间: ").append(authData.getLastJoin()).append("\n"); - result.append("QQ号码: ").append(authData.getQqNumber()).append("\n"); - result.append("绑定时间: ").append(authData.getLinkedTime()).append("\n"); - result.append("首次加入IP: ").append(authData.getFirstJoinIp()).append("\n"); - result.append("最后加入IP: ").append(authData.getLastJoinIp()).append("\n"); + result.append("玩家名称: ").append(authData.playerData().playerName()).append("\n"); + result.append("玩家UUID: ").append(authData.playerData().playerUuid()).append("\n"); + result.append("首次加入时间: ").append(authData.firstJoin()).append("\n"); + result.append("最后加入时间: ").append(authData.lastJoin()).append("\n"); + result.append("QQ号码: ").append(authData.qqNumber()).append("\n"); + result.append("绑定时间: ").append(authData.linkedTime()).append("\n"); + result.append("首次加入IP: ").append(authData.firstJoinIp()).append("\n"); + result.append("最后加入IP: ").append(authData.lastJoinIp()).append("\n"); return result.toString(); } diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerData.java b/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerData.java index 993b15c..8112d9a 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerData.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerData.java @@ -2,24 +2,7 @@ import java.util.UUID; -public class PlayerData { - private final String playerName; - private final UUID playerUuid; - - // Constructor - public PlayerData(String playerName, UUID playerUuid) { - this.playerName = playerName; - this.playerUuid = playerUuid; - } - - // Getters - public String getPlayerName() { - return playerName; - } - - public UUID getPlayerUuid() { - return playerUuid; - } +public record PlayerData(String playerName, UUID playerUuid) { @Override public String toString() { diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerRecord.java b/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerRecord.java index 680456e..a3e54a8 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerRecord.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/PlayerRecord.java @@ -1,53 +1,7 @@ package fun.suya.suisuroru.data.AuthData; -public class PlayerRecord { - private final PlayerData playerData; - private final long firstJoin; - private final long lastJoin; - private final long qqNumber; - private final long linkedTime; - private final String firstJoinIp; - private final String lastJoinIp; - - // Constructor - public PlayerRecord(PlayerData playerData, long firstJoin, long lastJoin, long qqNumber, long linkedTime, String firstJoinIp, String lastJoinIp) { - this.playerData = playerData; - this.firstJoin = firstJoin; - this.lastJoin = lastJoin; - this.qqNumber = qqNumber; - this.linkedTime = linkedTime; - this.firstJoinIp = firstJoinIp; - this.lastJoinIp = lastJoinIp; - } - - // Getters - public PlayerData getPlayerData() { - return playerData; - } - - public long getFirstJoin() { - return firstJoin; - } - - public long getLastJoin() { - return lastJoin; - } - - public long getQqNumber() { - return qqNumber; - } - - public long getLinkedTime() { - return linkedTime; - } - - public String getFirstJoinIp() { - return firstJoinIp; - } - - public String getLastJoinIp() { - return lastJoinIp; - } +public record PlayerRecord(PlayerData playerData, long firstJoin, long lastJoin, long qqNumber, long linkedTime, + String firstJoinIp, String lastJoinIp) { @Override public String toString() { From c8bfcefa6034619b774dfe64580373447695206f Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Sun, 12 Jan 2025 14:13:30 +0800 Subject: [PATCH 2/9] refactor(data): optimize AuthData output logic --- .../suisuroru/data/AuthData/DataProcess.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java index 639bd4f..fe0b733 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataProcess.java @@ -8,15 +8,22 @@ public static String processData(String jsonData) { Gson gson = new Gson(); AuthData authData = gson.fromJson(jsonData, AuthData.class); StringBuilder result = new StringBuilder(); - result.append("玩家名称: ").append(authData.playerData().playerName()).append("\n"); - result.append("玩家UUID: ").append(authData.playerData().playerUuid()).append("\n"); - result.append("首次加入时间: ").append(authData.firstJoin()).append("\n"); - result.append("最后加入时间: ").append(authData.lastJoin()).append("\n"); - result.append("QQ号码: ").append(authData.qqNumber()).append("\n"); - result.append("绑定时间: ").append(authData.linkedTime()).append("\n"); - result.append("首次加入IP: ").append(authData.firstJoinIp()).append("\n"); - result.append("最后加入IP: ").append(authData.lastJoinIp()).append("\n"); + + appendIfNotNull(result, "玩家名称: ", authData.playerData().playerName()); + appendIfNotNull(result, "玩家UUID: ", authData.playerData().playerUuid()); + appendIfNotNull(result, "首次加入时间: ", authData.firstJoin()); + appendIfNotNull(result, "最后加入时间: ", authData.lastJoin()); + appendIfNotNull(result, "QQ号码: ", authData.qqNumber()); + appendIfNotNull(result, "绑定时间: ", authData.linkedTime()); + appendIfNotNull(result, "首次加入IP: ", authData.firstJoinIp()); + appendIfNotNull(result, "最后加入IP: ", authData.lastJoinIp()); return result.toString(); } + + private static void appendIfNotNull(StringBuilder result, String label, Object value) { + if (value != null) { + result.append(label).append(value).append("\n"); + } + } } From 422aa53d9222f672063676d6af4e6807ca0f0965 Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Wed, 15 Jan 2025 20:07:26 +0800 Subject: [PATCH 3/9] logger: replace e.printStackTrace with logger --- .../suisuroru/commands/execute/othercommands/ReportQuery.java | 4 +++- .../commands/execute/othercommands/config/Query.java | 4 +++- .../commands/execute/othercommands/config/Reload.java | 4 +++- .../suisuroru/commands/execute/othercommands/config/Set.java | 4 +++- src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java | 3 ++- .../fun/suya/suisuroru/data/Report/ReportCharmProcess.java | 2 +- .../java/fun/suya/suisuroru/data/UnionBan/LocalCache.java | 4 ++-- src/main/java/fun/suya/suisuroru/message/Webhook4Email.java | 2 +- src/main/java/fun/xd/suka/command/ReportCommand.java | 4 +++- 9 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java index d2ac67a..ef49bbc 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java @@ -8,6 +8,8 @@ import java.util.List; +import static fun.xd.suka.Main.LOGGER; + /** * @author Suisuroru * Date: 2024/9/29 22:08 @@ -46,7 +48,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } catch (Exception e) { sender.sendMessage("查询数据失败!"); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); return false; } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Query.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Query.java index 238fe3c..374acd3 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Query.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Query.java @@ -11,6 +11,8 @@ import java.lang.reflect.Field; import java.util.Map; +import static fun.xd.suka.Main.LOGGER; + /** * @author Suisuroru * Date: 2024/10/15 00:43 @@ -48,7 +50,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command sender.sendMessage("§a配置项 " + configName + " 当前的值为: " + value); } catch (NoSuchFieldException | IllegalAccessException e) { sender.sendMessage("§c无法获取配置项 " + configName + " 的值,请检查配置文件或联系开发人员。"); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); } } return true; diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java index f502c43..d8973bb 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java @@ -6,6 +6,8 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import static fun.xd.suka.Main.LOGGER; + /** * @author Suisuroru * Date: 2024/9/28 13:24 @@ -29,7 +31,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } catch (Exception e) { sender.sendMessage("重新加载配置文件失败!"); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); return false; } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java index e2960d8..aa9ba1b 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java @@ -9,6 +9,8 @@ import java.util.Map; +import static fun.xd.suka.Main.LOGGER; + /** * @author Suisuroru * Date: 2024/10/15 02:06 @@ -53,7 +55,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command sender.sendMessage("§a配置项 " + configName + " 已成功设置为 " + value); } catch (Exception e) { sender.sendMessage("§c修改配置项 " + configName + " 的值时出错,请检查配置文件或联系开发人员。"); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); return false; } diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java index 111fb40..b5ace89 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java @@ -12,6 +12,7 @@ import java.util.UUID; import static fun.xd.suka.Main.DATA_FILE; +import static fun.xd.suka.Main.LOGGER; public class DataGet { private final List playerRecords; @@ -27,7 +28,7 @@ private List readDataFromFile(File file) { }.getType(); return gson.fromJson(reader, listType); } catch (IOException e) { - e.printStackTrace(); + LOGGER.warning(e.getMessage()); return new ArrayList<>(); } } diff --git a/src/main/java/fun/suya/suisuroru/data/Report/ReportCharmProcess.java b/src/main/java/fun/suya/suisuroru/data/Report/ReportCharmProcess.java index b10475a..55f59a4 100644 --- a/src/main/java/fun/suya/suisuroru/data/Report/ReportCharmProcess.java +++ b/src/main/java/fun/suya/suisuroru/data/Report/ReportCharmProcess.java @@ -87,7 +87,7 @@ public static void reportCharmProcess(String message) { LOGGER.info("Image saved to: " + outputFile.getAbsolutePath()); } catch (IOException e) { LOGGER.severe("Failed to write image: " + e.getMessage()); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); } } } diff --git a/src/main/java/fun/suya/suisuroru/data/UnionBan/LocalCache.java b/src/main/java/fun/suya/suisuroru/data/UnionBan/LocalCache.java index eb716ab..df19b2f 100644 --- a/src/main/java/fun/suya/suisuroru/data/UnionBan/LocalCache.java +++ b/src/main/java/fun/suya/suisuroru/data/UnionBan/LocalCache.java @@ -89,7 +89,7 @@ private static Map readJsonFile(File file) { }); } catch (IOException e) { LOGGER.severe("Failed to read JSON file: " + file.getAbsolutePath()); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); return new HashMap<>(); } } @@ -99,7 +99,7 @@ private static void writeJsonFile(File file, Map data) { objectMapper.writeValue(file, data); } catch (IOException e) { LOGGER.severe("Failed to write JSON file: " + file.getAbsolutePath()); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); } } } diff --git a/src/main/java/fun/suya/suisuroru/message/Webhook4Email.java b/src/main/java/fun/suya/suisuroru/message/Webhook4Email.java index 4c6c081..153ccf1 100644 --- a/src/main/java/fun/suya/suisuroru/message/Webhook4Email.java +++ b/src/main/java/fun/suya/suisuroru/message/Webhook4Email.java @@ -61,7 +61,7 @@ public void sendWebhookData(Data data) { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.warning(e.getMessage()); LOGGER.info("Error sending webhook: " + e.getMessage()); } } diff --git a/src/main/java/fun/xd/suka/command/ReportCommand.java b/src/main/java/fun/xd/suka/command/ReportCommand.java index e438684..d2dd3e6 100644 --- a/src/main/java/fun/xd/suka/command/ReportCommand.java +++ b/src/main/java/fun/xd/suka/command/ReportCommand.java @@ -19,6 +19,8 @@ import java.util.Objects; +import static fun.xd.suka.Main.LOGGER; + public class ReportCommand implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { @@ -64,7 +66,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command webhook4Email.formatAndSendWebhook(subject, content); } catch (Exception e) { sender.sendMessage("§c邮件发送失败"); - e.printStackTrace(); + LOGGER.warning(e.getMessage()); } MessageChainBuilder builder_qq = new MessageChainBuilder(); From 3327fd1fc635288f513bb0ad6711f6d630e86717 Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Wed, 15 Jan 2025 20:16:45 +0800 Subject: [PATCH 4/9] upgrade: plugin.yml --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 48cbab2..9a678c1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,7 @@ name: BasePlugin version: 2.7.2 main: fun.xd.suka.Main description: Encoded by Blue Millennium -authors: [SukaXD, Suisuroru] +authors: [ SukaXD, Suisuroru ] commands: kill: From 0422c2e2ac043df84dabcff189f72e78bdc35547 Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Mon, 20 Jan 2025 00:23:09 +0800 Subject: [PATCH 5/9] refactor(data): refactoring player data query logic -Modify the getPlayersByQQAsJson method to remove special handling for individual players -Update the data processing method in DataQueryByQQ to support returning multiple player data - optimize the display logic of data query results to improve user experience --- .../data/QueryFunctions/DataQueryByQQ.java | 13 ++++++++++++- .../fun/suya/suisuroru/data/AuthData/DataGet.java | 3 --- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java index bba3ff3..ab1bde6 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java @@ -1,5 +1,7 @@ package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import fun.suya.suisuroru.data.AuthData.DataGet; import fun.suya.suisuroru.data.AuthData.DataProcess; import org.bukkit.command.Command; @@ -7,6 +9,9 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Type; +import java.util.List; + import static fun.xd.suka.Main.LOGGER; public class DataQueryByQQ implements CommandExecutor { @@ -30,7 +35,13 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } String playerJson = dataGet.getPlayersByQQAsJson(QQNum); if (!playerJson.isEmpty() && !playerJson.equals("[]")) { - sender.sendMessage(DataProcess.processData(playerJson)); + Gson gson = new Gson(); + Type listType = new TypeToken>() {}.getType(); + List playerList = gson.fromJson(playerJson, listType); + for (Object player : playerList) { + String processedData = DataProcess.processData(gson.toJson(player)); + sender.sendMessage(processedData); + } return true; } else { sender.sendMessage("查询的数据不存在"); diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java index b5ace89..f7929bf 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java @@ -56,9 +56,6 @@ public List getPlayersByUUID(UUID playerUuid) { public String getPlayersByQQAsJson(long qqNumber) { List players = getPlayersByQQ(qqNumber); - if (players.size() == 1) { - return gson.toJson(players.get(0)); - } return gson.toJson(players); } From 26366f1c3b34ffdba78f2c92e5884c83bda7a25f Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Mon, 20 Jan 2025 00:27:20 +0800 Subject: [PATCH 6/9] refactor(data): refactoring data query logic -Removed special handling of individual player records in the DataGet class -Refactored the data processing logic in the DataQueryByName and DataQueryByQQ classes -Added ProcessFinalData method in DataQueryByUUID class for unified processing of query results -Optimized code structure, improved maintainability and reusability --- .../data/QueryFunctions/DataQueryByName.java | 10 ++------- .../data/QueryFunctions/DataQueryByQQ.java | 21 ++----------------- .../data/QueryFunctions/DataQueryByUUID.java | 18 +++++++++++++++- .../suya/suisuroru/data/AuthData/DataGet.java | 6 ------ 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java index 1871cbc..3bfb3e4 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java @@ -1,12 +1,12 @@ package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions; import fun.suya.suisuroru.data.AuthData.DataGet; -import fun.suya.suisuroru.data.AuthData.DataProcess; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import static fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions.DataQueryByUUID.ProcessFinalData; import static fun.xd.suka.Main.LOGGER; public class DataQueryByName implements CommandExecutor { @@ -25,12 +25,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return false; } String playerJson = dataGet.getPlayersByNameAsJson(Name); - if (!playerJson.isEmpty() && !playerJson.equals("[]")) { - sender.sendMessage(DataProcess.processData(playerJson)); - return true; - } else { - sender.sendMessage("查询的数据不存在"); - return false; - } + return ProcessFinalData(sender, playerJson); } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java index ab1bde6..7061ec3 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java @@ -1,17 +1,12 @@ package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions; -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; import fun.suya.suisuroru.data.AuthData.DataGet; -import fun.suya.suisuroru.data.AuthData.DataProcess; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Type; -import java.util.List; - +import static fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions.DataQueryByUUID.ProcessFinalData; import static fun.xd.suka.Main.LOGGER; public class DataQueryByQQ implements CommandExecutor { @@ -34,18 +29,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return false; } String playerJson = dataGet.getPlayersByQQAsJson(QQNum); - if (!playerJson.isEmpty() && !playerJson.equals("[]")) { - Gson gson = new Gson(); - Type listType = new TypeToken>() {}.getType(); - List playerList = gson.fromJson(playerJson, listType); - for (Object player : playerList) { - String processedData = DataProcess.processData(gson.toJson(player)); - sender.sendMessage(processedData); - } - return true; - } else { - sender.sendMessage("查询的数据不存在"); - return false; - } + return ProcessFinalData(sender, playerJson); } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java index bcf2de6..5d8ba3c 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java @@ -1,5 +1,7 @@ package fun.suya.suisuroru.commands.execute.othercommands.data.QueryFunctions; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import fun.suya.suisuroru.data.AuthData.DataGet; import fun.suya.suisuroru.data.AuthData.DataProcess; import org.bukkit.command.Command; @@ -7,11 +9,14 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Type; +import java.util.List; import java.util.UUID; import static fun.xd.suka.Main.LOGGER; public class DataQueryByUUID implements CommandExecutor { + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.isOp()) { @@ -34,8 +39,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return false; } String playerJson = dataGet.getPlayersByUUIDAsJson(Uuid); + return ProcessFinalData(sender, playerJson); + } + + static boolean ProcessFinalData(@NotNull CommandSender sender, String playerJson) { if (!playerJson.isEmpty() && !playerJson.equals("[]")) { - sender.sendMessage(DataProcess.processData(playerJson)); + Gson gson = new Gson(); + Type listType = new TypeToken>() { + }.getType(); + List playerList = gson.fromJson(playerJson, listType); + for (Object player : playerList) { + String processedData = DataProcess.processData(gson.toJson(player)); + sender.sendMessage(processedData); + } return true; } else { sender.sendMessage("查询的数据不存在"); diff --git a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java index f7929bf..8a70f7e 100644 --- a/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java +++ b/src/main/java/fun/suya/suisuroru/data/AuthData/DataGet.java @@ -61,17 +61,11 @@ public String getPlayersByQQAsJson(long qqNumber) { public String getPlayersByNameAsJson(String playerName) { List players = getPlayersByName(playerName); - if (players.size() == 1) { - return gson.toJson(players.get(0)); - } return gson.toJson(players); } public String getPlayersByUUIDAsJson(UUID playerUuid) { List players = getPlayersByUUID(playerUuid); - if (players.size() == 1) { - return gson.toJson(players.get(0)); - } return gson.toJson(players); } From 14435701c35786c7f4b53e91d8c2330d8d17da09 Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Mon, 20 Jan 2025 00:31:27 +0800 Subject: [PATCH 7/9] refactor(commands): optimize command execution logic --- .../commands/execute/othercommands/ReportQuery.java | 2 +- .../commands/execute/othercommands/config/Reload.java | 2 +- .../commands/execute/othercommands/config/Set.java | 2 +- .../data/QueryFunctions/DataQueryByName.java | 4 ++-- .../othercommands/data/QueryFunctions/DataQueryByQQ.java | 4 ++-- .../data/QueryFunctions/DataQueryByUUID.java | 9 ++++----- .../fun/suya/suisuroru/commands/execute/vanilla/Ban.java | 6 +++--- .../suya/suisuroru/commands/execute/vanilla/Kill.java | 4 ++-- .../suya/suisuroru/commands/execute/vanilla/Pardon.java | 6 +++--- 9 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java index ef49bbc..967e7a4 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/ReportQuery.java @@ -49,7 +49,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } catch (Exception e) { sender.sendMessage("查询数据失败!"); LOGGER.warning(e.getMessage()); - return false; + return true; } } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java index d8973bb..5297c3b 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Reload.java @@ -32,7 +32,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } catch (Exception e) { sender.sendMessage("重新加载配置文件失败!"); LOGGER.warning(e.getMessage()); - return false; + return true; } } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java index aa9ba1b..12b40da 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/config/Set.java @@ -56,7 +56,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } catch (Exception e) { sender.sendMessage("§c修改配置项 " + configName + " 的值时出错,请检查配置文件或联系开发人员。"); LOGGER.warning(e.getMessage()); - return false; + return true; } return true; diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java index 3bfb3e4..7413cbf 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByName.java @@ -14,7 +14,7 @@ public class DataQueryByName implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } DataGet dataGet = new DataGet(); String Name; @@ -22,7 +22,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Name = args[0]; } catch (Exception e) { LOGGER.info(String.valueOf(e)); - return false; + return true; } String playerJson = dataGet.getPlayersByNameAsJson(Name); return ProcessFinalData(sender, playerJson); diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java index 7061ec3..ebb8dbc 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByQQ.java @@ -15,7 +15,7 @@ public class DataQueryByQQ implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } DataGet dataGet = new DataGet(); long QQNum = 0; @@ -26,7 +26,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } catch (Exception e) { LOGGER.info(String.valueOf(e)); - return false; + return true; } String playerJson = dataGet.getPlayersByQQAsJson(QQNum); return ProcessFinalData(sender, playerJson); diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java index 5d8ba3c..9d455e5 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/othercommands/data/QueryFunctions/DataQueryByUUID.java @@ -21,7 +21,7 @@ public class DataQueryByUUID implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } DataGet dataGet = new DataGet(); UUID Uuid; @@ -33,10 +33,10 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command Uuid = UUID.fromString(uuidString); } catch (IllegalArgumentException e) { LOGGER.info("§c输入的数据不是UUID"); - return false; + return true; } catch (Exception e) { LOGGER.info(String.valueOf(e)); - return false; + return true; } String playerJson = dataGet.getPlayersByUUIDAsJson(Uuid); return ProcessFinalData(sender, playerJson); @@ -52,11 +52,10 @@ static boolean ProcessFinalData(@NotNull CommandSender sender, String playerJson String processedData = DataProcess.processData(gson.toJson(player)); sender.sendMessage(processedData); } - return true; } else { sender.sendMessage("查询的数据不存在"); - return false; } + return true; } private String insertHyphens(String uuid) { diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Ban.java b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Ban.java index 4b95ca3..661f2fd 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Ban.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Ban.java @@ -39,12 +39,12 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (Config.UnionBanEnabled) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } if (args.length == 0) { sender.sendMessage("Usage: /ban [reason]"); - return false; + return true; } String playerName = args[0]; @@ -53,7 +53,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (targetPlayer == null) { sender.sendMessage("未找到玩家: " + playerName); - return false; + return true; } // 调用原版的 ban 命令 diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Kill.java b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Kill.java index b88fd96..03b6442 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Kill.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Kill.java @@ -11,7 +11,7 @@ public class Kill implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } switch (args[0]) { case "@e" -> { @@ -38,6 +38,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return Bukkit.dispatchCommand(sender, "minecraft:kill " + String.join(" ", args)); } } - return false; + return true; } } diff --git a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Pardon.java b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Pardon.java index fcd9b6a..58adeb9 100644 --- a/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Pardon.java +++ b/src/main/java/fun/suya/suisuroru/commands/execute/vanilla/Pardon.java @@ -39,19 +39,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if (Config.UnionBanEnabled) { if (!sender.isOp()) { sender.sendMessage("您没有权限这么做"); - return false; + return true; } if (args.length == 0) { sender.sendMessage("Usage: /pardon "); - return false; + return true; } String playerName = args[0]; if (!Bukkit.getBanList(BanList.Type.PROFILE).isBanned(playerName)) { sender.sendMessage("玩家 " + playerName + " 未被封禁"); - return false; + return true; } // 调用原版的 pardon 命令 From 106548e584e13e4fcf625b0628585b4f82af8a2e Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Mon, 20 Jan 2025 00:41:03 +0800 Subject: [PATCH 8/9] build(gradle): update dependencies and upgrade Shadow plugin -Upgrade Shadow plugin version from 8.3.3 to 8.3.5 -Remove jitpack.io repository -Update rcon Java dependency version -Delete redundant Sonatype and Spigotmc repositories -Update the spider API dependency version -Fix the version of Mirai related dependencies -Update the version of Jackson related dependencies --- build.gradle | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 829dcea..e73e774 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,11 @@ plugins { id 'java' - id 'com.gradleup.shadow' version '8.3.3' + id 'com.gradleup.shadow' version '8.3.5' id 'idea' } group = 'Blue-Millennium' -version = '2.7.2' +version = '2.7.3' idea { module { @@ -14,12 +14,10 @@ idea { } repositories { - maven { url 'https://jitpack.io' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' } - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } + maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots' } mavenCentral() } @@ -28,7 +26,7 @@ dependencies { implementation 'top.mrxiaom.mirai:overflow-core-api:1.0.2' implementation 'top.mrxiaom.mirai:overflow-core:1.0.2' implementation 'net.mamoe:mirai-core-api:2.16.0' - implementation 'com.github.Glavo:rcon-java:2.0.2' + implementation 'org.glavo:rcon-java:3.0' implementation 'com.fasterxml.jackson.core:jackson-core:2.18.2' implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.18.2' From 418b5c903e1f1bc60971d6207d50e7fbe09d00aa Mon Sep 17 00:00:00 2001 From: Suisuroru Date: Mon, 20 Jan 2025 00:44:31 +0800 Subject: [PATCH 9/9] build: update version to 2.7.3 --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9a678c1..db88271 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: BasePlugin -version: 2.7.2 +version: 2.7.3 main: fun.xd.suka.Main description: Encoded by Blue Millennium authors: [ SukaXD, Suisuroru ]