Skip to content

Commit

Permalink
Version Horizon
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 12, 2024
1 parent a5f3f45 commit c5b2527
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>Starry</version>
<version>Horizon</version>
<packaging>jar</packaging>

<name>AdvancedSensitiveWords</name>
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
});
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wdsj/asw/listener/AnvilListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wdsj/asw/listener/BookListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wdsj/asw/listener/SignListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/wdsj/asw/manage/notice/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

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;

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<? extends Player> 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);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/wdsj/asw/setting/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> ENABLE_DEFAULT_WORDS = newProperty("Plugin.enableDefaultWords", false);
public static final Property<Boolean> ENABLE_DEFAULT_WORDS = newProperty("Plugin.enableDefaultWords", true);
@Comment({"是否启用更新检查",
"Whether to enable updater"})
public static final Property<Boolean> CHECK_FOR_UPDATE = newProperty("Plugin.checkForUpdate", true);

@Comment({"是否启用在线词库",
"Whether to enable online word library"})
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/io/wdsj/asw/update/Updater.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
39 changes: 0 additions & 39 deletions src/main/resources/dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36555,28 +36555,13 @@ z以留吧以其以武
武力统1
武士直刀
武思伦
武村梨乃种子
武林启示录
武林启示录全集txt
武林启示录电子书下载
武林外史
武林外转
武林情皇传
武林淫乱史
武林状元
武林红杏传
武林红杏传txt
武林群侠传
武林花主
武林花劫
武汉mm上门服务
武汉办证
武汉地下肉类加工厂
武汉妹
武汉爆发大规模牛传染病
武汉诚诺电子
武神
武腾兰
武腾兰无码下载
武腾兰种子下载
武藤兰
Expand All @@ -36586,7 +36571,6 @@ z以留吧以其以武
武藤早纪种子
武藤爱
武装镇压
武警
武警作战服供应
武警作战服出售
武警作战服直销
Expand Down Expand Up @@ -48007,20 +47991,6 @@ z以留吧以其以武
至尊开户网站
至尊情色王朝
至尊爱妃别太坏
至尊狼威
至尊百家乐
至尊邪帝
至淫绝地
致命女人心
致命接触
致幻
致幻剂
致幻剂出售qq
致幻植物
致敬仁波切上师
致胡书记的公开信
舅子李平经营学校
舆论
舆论反制
舆论钳制
舌ma眼
Expand All @@ -48036,17 +48006,9 @@ z以留吧以其以武
舌尖不断在肉缝里上下舔着
舌尖刮著阴唇上的淫水
舌尖欲望
舌尖漫游
舌尖舔着肉棒阴门
舌战法庭
舌战法庭txt
舌战法庭txt全集
舌战法庭电子书下载
舍生取义庭
舐她的小穴
舒晓琴
舒服死大鸡巴插
舒淇
舔b
舔jb
舔下体
Expand Down Expand Up @@ -56673,7 +56635,6 @@ z以留吧以其以武
高压锅炸弹制作步骤
高压锅炸弹制造图
高压麻醉枪出售
高官
高官互调
高官子女
高官情人女记者官密txt
Expand Down

0 comments on commit c5b2527

Please sign in to comment.