From c5b252764cb44e4a6f062963dc47528805d37aa7 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Tue, 12 Mar 2024 21:52:31 +0800 Subject: [PATCH] Version Horizon --- pom.xml | 2 +- .../io/wdsj/asw/AdvancedSensitiveWords.java | 10 +++++ .../io/wdsj/asw/listener/AnvilListener.java | 2 +- .../io/wdsj/asw/listener/BookListener.java | 2 +- .../asw/listener/PlayerHeldItemListener.java | 2 +- .../asw/listener/PlayerLoginListener.java | 2 +- .../io/wdsj/asw/listener/SignListener.java | 2 +- .../listener/packet/ASWPacketListener.java | 6 +-- .../listener/packet/ProtocolLibListener.java | 4 +- .../io/wdsj/asw/manage/notice/Notifier.java | 6 +-- .../io/wdsj/asw/setting/PluginSettings.java | 5 ++- src/main/java/io/wdsj/asw/update/Updater.java | 43 +++++++++++++++++++ src/main/resources/dict.txt | 39 ----------------- 13 files changed, 70 insertions(+), 55 deletions(-) create mode 100644 src/main/java/io/wdsj/asw/update/Updater.java diff --git a/pom.xml b/pom.xml index 030bb63..ee8ac29 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.wdsj AdvancedSensitiveWords - Starry + Horizon jar AdvancedSensitiveWords diff --git a/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java b/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java index ea8a1b2..9adefcf 100644 --- a/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java +++ b/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java @@ -21,6 +21,7 @@ import io.wdsj.asw.method.*; import io.wdsj.asw.setting.PluginMessages; import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.update.Updater; import io.wdsj.asw.util.TimingUtils; import io.wdsj.asw.util.cache.BookCache; import io.wdsj.asw.util.context.ChatContext; @@ -125,6 +126,15 @@ public void onEnable() { } long endTime = System.currentTimeMillis(); getLogger().info("AdvancedSensitiveWords is enabled!(took " + (endTime - startTime) + "ms)"); + if (settingsManager.getProperty(PluginSettings.CHECK_FOR_UPDATE)) { + getScheduler().runTaskAsynchronously(() -> { + Updater updater = new Updater(getDescription().getVersion()); + if (updater.isUpdateAvailable()) { + getLogger().warning("There is a new version available: " + updater.getLatestVersion() + + ", you're on: " + updater.getCurrentVersion()); + } + }); + } } diff --git a/src/main/java/io/wdsj/asw/listener/AnvilListener.java b/src/main/java/io/wdsj/asw/listener/AnvilListener.java index ba584dd..4fe6b89 100644 --- a/src/main/java/io/wdsj/asw/listener/AnvilListener.java +++ b/src/main/java/io/wdsj/asw/listener/AnvilListener.java @@ -68,7 +68,7 @@ public void onAnvil(InventoryClickEvent event) { } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); - Notifier.notice(player, EventType.ANVIL, originalItemName); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ANVIL, originalItemName); Punishment.punish(player); } } diff --git a/src/main/java/io/wdsj/asw/listener/BookListener.java b/src/main/java/io/wdsj/asw/listener/BookListener.java index ea11117..4c7fcfa 100644 --- a/src/main/java/io/wdsj/asw/listener/BookListener.java +++ b/src/main/java/io/wdsj/asw/listener/BookListener.java @@ -113,7 +113,7 @@ public void onBook(PlayerEditBookEvent event) { } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); - Notifier.notice(player, EventType.BOOK, outMessage); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.BOOK, outMessage); Punishment.punish(player); } diff --git a/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java b/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java index 1038079..a2e76df 100644 --- a/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java +++ b/src/main/java/io/wdsj/asw/listener/PlayerHeldItemListener.java @@ -58,7 +58,7 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) { } long endTime = System.currentTimeMillis(); TimingUtils.addProcessStatistic(endTime, startTime); - Notifier.notice(player, EventType.ITEM, originalName); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ITEM, originalName); Punishment.punish(player); } } diff --git a/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java b/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java index 1fa3f29..bd4f72c 100644 --- a/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java +++ b/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java @@ -57,7 +57,7 @@ public void onLogin(PlayerLoginEvent event) { } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); - Notifier.notice(player, EventType.NAME, playerName); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.NAME, playerName); Punishment.punish(player); } } diff --git a/src/main/java/io/wdsj/asw/listener/SignListener.java b/src/main/java/io/wdsj/asw/listener/SignListener.java index 4c7e99d..38f4e79 100644 --- a/src/main/java/io/wdsj/asw/listener/SignListener.java +++ b/src/main/java/io/wdsj/asw/listener/SignListener.java @@ -97,7 +97,7 @@ public void onSign(SignChangeEvent event) { messagesFilteredNum.getAndIncrement(); long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); - Notifier.notice(player, EventType.SIGN, outMessage); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.SIGN, outMessage); Punishment.punish(player); } } diff --git a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java b/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java index efb14a7..488f153 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java +++ b/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java @@ -79,7 +79,7 @@ public void onPacketReceive(PacketReceiveEvent event) { long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { - Notifier.notice(player, EventType.CHAT, originalMessage); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalMessage); Punishment.punish(player); }); return; @@ -112,7 +112,7 @@ public void onPacketReceive(PacketReceiveEvent event) { long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { - Notifier.notice(player, EventType.CHAT, originalContext); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalContext); Punishment.punish(player); }); } @@ -148,7 +148,7 @@ public void onPacketReceive(PacketReceiveEvent event) { long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { - Notifier.notice(player, EventType.CHAT, originalCommand); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalCommand); Punishment.punish(player); }); } diff --git a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java b/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java index d1b457e..e73f4d6 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java +++ b/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java @@ -76,7 +76,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { - Notifier.notice(player, EventType.CHAT, message); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, message); Punishment.punish(player); }); return; @@ -106,7 +106,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { - Notifier.notice(player, EventType.CHAT, originalContext); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalContext); Punishment.punish(player); }); } diff --git a/src/main/java/io/wdsj/asw/manage/notice/Notifier.java b/src/main/java/io/wdsj/asw/manage/notice/Notifier.java index 2f4745a..bbcae5b 100644 --- a/src/main/java/io/wdsj/asw/manage/notice/Notifier.java +++ b/src/main/java/io/wdsj/asw/manage/notice/Notifier.java @@ -2,7 +2,6 @@ import io.wdsj.asw.event.EventType; import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -10,15 +9,14 @@ import java.util.Collection; import static io.wdsj.asw.AdvancedSensitiveWords.messagesManager; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; public class Notifier { public static void notice(Player violatedPlayer, EventType eventType, String originalMessage) { - if (!settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) return; Collection players = Bukkit.getOnlinePlayers(); + String message = ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.ADMIN_REMINDER).replace("%player%", violatedPlayer.getName()).replace("%type%", eventType.toString()).replace("%message%", originalMessage)); for (Player player : players) { if (player.hasPermission("advancedsensitivewords.notice")) { - player.sendMessage(ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.ADMIN_REMINDER).replace("%player%", violatedPlayer.getName()).replace("%type%", eventType.toString()).replace("%message%", originalMessage))); + player.sendMessage(message); } } } diff --git a/src/main/java/io/wdsj/asw/setting/PluginSettings.java b/src/main/java/io/wdsj/asw/setting/PluginSettings.java index c5787c1..307eee8 100644 --- a/src/main/java/io/wdsj/asw/setting/PluginSettings.java +++ b/src/main/java/io/wdsj/asw/setting/PluginSettings.java @@ -17,7 +17,10 @@ public class PluginSettings implements SettingsHolder { @Comment({"是否启用默认词库(6w+)(强烈建议开启)", "Whether to enable the default word library (60k+ words) (strongly recommended)"}) - public static final Property ENABLE_DEFAULT_WORDS = newProperty("Plugin.enableDefaultWords", false); + public static final Property ENABLE_DEFAULT_WORDS = newProperty("Plugin.enableDefaultWords", true); + @Comment({"是否启用更新检查", + "Whether to enable updater"}) + public static final Property CHECK_FOR_UPDATE = newProperty("Plugin.checkForUpdate", true); @Comment({"是否启用在线词库", "Whether to enable online word library"}) diff --git a/src/main/java/io/wdsj/asw/update/Updater.java b/src/main/java/io/wdsj/asw/update/Updater.java new file mode 100644 index 0000000..064f6a5 --- /dev/null +++ b/src/main/java/io/wdsj/asw/update/Updater.java @@ -0,0 +1,43 @@ +package io.wdsj.asw.update; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Scanner; + +public class Updater { + private final String currentVersion; + private String latestVersion; + private static final String UPDATE_URL = "https://api.github.com/repos/HaHaWTH/AdvancedSensitiveWords/releases/latest"; + + public Updater(String currentVersion) { + this.currentVersion = currentVersion; + } + + public boolean isUpdateAvailable() { + try { + URL url = new URL(UPDATE_URL); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(10000); + conn.setReadTimeout(10000); + Scanner scanner = new Scanner(conn.getInputStream()); + String response = scanner.useDelimiter("\\Z").next(); + scanner.close(); + String latestVersion = response.substring(response.indexOf("tag_name") + 11); + latestVersion = latestVersion.substring(0, latestVersion.indexOf("\"")); + this.latestVersion = latestVersion; + return !currentVersion.equals(latestVersion); + } catch (IOException ignored) { + this.latestVersion = null; + return false; + } + } + + public String getLatestVersion() { + return latestVersion; + } + + public String getCurrentVersion() { + return currentVersion; + } +} diff --git a/src/main/resources/dict.txt b/src/main/resources/dict.txt index 7d270b9..b0fcc4d 100644 --- a/src/main/resources/dict.txt +++ b/src/main/resources/dict.txt @@ -36555,28 +36555,13 @@ z以留吧以其以武 武力统1 武士直刀 武思伦 -武村梨乃种子 -武林启示录 -武林启示录全集txt -武林启示录电子书下载 -武林外史 -武林外转 -武林情皇传 -武林淫乱史 -武林状元 -武林红杏传 -武林红杏传txt -武林群侠传 武林花主 武林花劫 武汉mm上门服务 武汉办证 武汉地下肉类加工厂 -武汉妹 武汉爆发大规模牛传染病 武汉诚诺电子 -武神 -武腾兰 武腾兰无码下载 武腾兰种子下载 武藤兰 @@ -36586,7 +36571,6 @@ z以留吧以其以武 武藤早纪种子 武藤爱 武装镇压 -武警 武警作战服供应 武警作战服出售 武警作战服直销 @@ -48007,20 +47991,6 @@ z以留吧以其以武 至尊开户网站 至尊情色王朝 至尊爱妃别太坏 -至尊狼威 -至尊百家乐 -至尊邪帝 -至淫绝地 -致命女人心 -致命接触 -致幻 -致幻剂 -致幻剂出售qq -致幻植物 -致敬仁波切上师 -致胡书记的公开信 -舅子李平经营学校 -舆论 舆论反制 舆论钳制 舌ma眼 @@ -48036,17 +48006,9 @@ z以留吧以其以武 舌尖不断在肉缝里上下舔着 舌尖刮著阴唇上的淫水 舌尖欲望 -舌尖漫游 舌尖舔着肉棒阴门 -舌战法庭 -舌战法庭txt -舌战法庭txt全集 -舌战法庭电子书下载 -舍生取义庭 舐她的小穴 -舒晓琴 舒服死大鸡巴插 -舒淇 舔b 舔jb 舔下体 @@ -56673,7 +56635,6 @@ z以留吧以其以武 高压锅炸弹制作步骤 高压锅炸弹制造图 高压麻醉枪出售 -高官 高官互调 高官子女 高官情人女记者官密txt