Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Sep 24, 2024
1 parent 4162246 commit a445b39
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 37 deletions.
4 changes: 2 additions & 2 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -403,7 +403,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.0</version>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.wdsj.asw.bukkit.AdvancedSensitiveWords;
import io.wdsj.asw.bukkit.manage.punish.PlayerShadowController;
import io.wdsj.asw.bukkit.manage.punish.ViolationCounter;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -35,8 +36,8 @@ public String onRequest(OfflinePlayer player, @NotNull String params) {
if (params.equalsIgnoreCase("version")) {
return getVersion();
}
if (params.equalsIgnoreCase("current_total")) {
return String.valueOf(messagesFilteredNum);
if (params.equalsIgnoreCase("total_filtered")) {
return String.valueOf(messagesFilteredNum.get());
}
if (params.equalsIgnoreCase("is_shadow")) {
if (player != null) {
Expand All @@ -46,6 +47,14 @@ public String onRequest(OfflinePlayer player, @NotNull String params) {
}
}
}
if (params.equalsIgnoreCase("violation_count")) {
if (player != null) {
Player onlinePlayer = player.getPlayer();
if (onlinePlayer != null) {
return String.valueOf(ViolationCounter.getViolationCount(onlinePlayer));
}
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BukkitLibraryService {
.groupId("dev{}ai4j")
.artifactId("openai4j")
.resolveTransitiveDependencies(true)
.version("0.21.0")
.version("0.22.0")
.build();

private static final Library caffeine = Library.builder()
Expand Down
20 changes: 10 additions & 10 deletions bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,21 @@ public class PluginSettings implements SettingsHolder {
"Whether to enable punishment"})
public static final Property<Boolean> CHAT_PUNISH = newProperty("Chat.punish", true);

@Comment({"*是否启用服务器广播消息检测(仅提供取消和替换模式,配置跟随聊天检测)(不会触发API事件)",
"*Whether to enable server broadcast message checks (only offers cancel and replace modes, configuration follows chat checks) (does not trigger API events)"})
public static final Property<Boolean> CHAT_BROADCAST_CHECK = newProperty("Chat.broadcastCheck", true);
@Comment({"*是否启用服务器广播消息检测(仅提供取消和替换模式,配置跟随聊天检测)",
"*Whether to enable server broadcast message checks (only offers cancel and replace modes, configuration follows chat checks)"})
public static final Property<Boolean> CHAT_BROADCAST_CHECK = newProperty("Chat.broadcastCheck", false);

@Comment({"是否开启聊天上下文检测(仅提供取消和假消息模式,配置跟随聊天检测)",
"Whether to enable chat context checks (only offers cancel and fake message modes, configuration follows chat checks)"})
public static final Property<Boolean> CHAT_CONTEXT_CHECK = newProperty("Chat.contextCheck", false);
public static final Property<Boolean> CHAT_CONTEXT_CHECK = newProperty("Chat.contextCheck", true);

@Comment({"最大检测上下文大小",
"Maximum context size for checks"})
public static final Property<Integer> CHAT_CONTEXT_MAX_SIZE = newProperty("Chat.contextMaxSize", 4);

@Comment({"最大检测上下文时间(单位: 秒)",
"Maximum context time for checks(seconds)"})
public static final Property<Integer> CHAT_CONTEXT_TIME_LIMIT = newProperty("Chat.contextMaxTime", 120);
public static final Property<Integer> CHAT_CONTEXT_TIME_LIMIT = newProperty("Chat.contextMaxTime", 90);

@Comment({"是否反转指令白名单为黑名单",
"Whether to invert the command whitelist to a blacklist"})
Expand Down Expand Up @@ -327,14 +327,14 @@ public class PluginSettings implements SettingsHolder {
public static final Property<Boolean> BOOK_PUNISH = newProperty("Book.punish", true);
@Comment({"是否启用书检测缓存(有助于优化性能)",
"Whether to enable book check caching (helps optimize performance)"})
public static final Property<Boolean> BOOK_CACHE = newProperty("Book.cache.enableCache", false);
public static final Property<Boolean> BOOK_CACHE = newProperty("Book.cache.enableCache", true);

@Comment({"*最大缓存数量(默认200)",
"*Maximum cache size (default is 200)"})
public static final Property<Integer> BOOK_MAXIMUM_CACHE_SIZE = newProperty("Book.cache.maximumCacheSize", 200);
@Comment({"*最大缓存数量",
"*Maximum cache size"})
public static final Property<Integer> BOOK_MAXIMUM_CACHE_SIZE = newProperty("Book.cache.maximumCacheSize", 400);
@Comment({"*缓存最大保存时间(分)",
"*Cache expire time (minutes)"})
public static final Property<Integer> BOOK_CACHE_EXPIRE_TIME = newProperty("Book.cache.expireTime", 60);
public static final Property<Integer> BOOK_CACHE_EXPIRE_TIME = newProperty("Book.cache.expireTime", 10);

@Comment({"重载时是否清空缓存",
"Whether to clear cache on reload"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
import io.wdsj.asw.bukkit.manage.punish.ViolationCounter;
import io.wdsj.asw.bukkit.setting.PluginMessages;
import io.wdsj.asw.bukkit.setting.PluginSettings;
import io.wdsj.asw.bukkit.util.SchedulingUtils;
import io.wdsj.asw.bukkit.util.message.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.messagesManager;
import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager;

/**
* **Asynchronous** task to reset the violation count of players.
*/
public class ViolationResetTask extends UniversalRunnable {
@Override
public void run() {
if (settingsManager.getProperty(PluginSettings.ONLY_RESET_ONLINE_PLAYERS)) {
for (Player player : Bukkit.getOnlinePlayers()) {
for (Player player : SchedulingUtils.callSyncMethod(Bukkit::getOnlinePlayers)) {
ViolationCounter.resetViolationCount(player);
}
} else {
ViolationCounter.resetAllViolations();
}
String message = ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.MESSAGE_ON_VIOLATION_RESET));
String message = MessageUtils.retrieveMessage(PluginMessages.MESSAGE_ON_VIOLATION_RESET);
Notifier.normalNotice(message);
}
}
10 changes: 10 additions & 0 deletions bukkit/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.bukkit.Location;
import org.bukkit.entity.Entity;

import java.util.concurrent.Callable;

public class SchedulingUtils {
private SchedulingUtils() {
}
Expand Down Expand Up @@ -41,4 +43,12 @@ public static void cancelTaskSafely(MyScheduledTask task) {
task.cancel();
}

public static <T> T callSyncMethod(Callable<T> callable) {
try {
return AdvancedSensitiveWords.getScheduler().callSyncMethod(callable).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import io.wdsj.asw.common.datatype.TimedString;
import org.bukkit.entity.Player;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager;

Expand All @@ -18,7 +18,7 @@ public class ChatContext {
*/
public static void addMessage(Player player, String message) {
final UUID uuid = player.getUniqueId();
chatHistory.computeIfAbsent(uuid, k -> new ArrayDeque<>());
chatHistory.computeIfAbsent(uuid, k -> new ConcurrentLinkedDeque<>());
Deque<TimedString> history = chatHistory.get(uuid);
while (history.size() >= settingsManager.getProperty(PluginSettings.CHAT_CONTEXT_MAX_SIZE)) {
history.pollFirst();
Expand All @@ -29,11 +29,12 @@ public static void addMessage(Player player, String message) {

public static Deque<String> getHistory(Player player) {
final UUID uuid = player.getUniqueId();
Deque<TimedString> tsHistory = chatHistory.getOrDefault(uuid, new ArrayDeque<>());
Deque<TimedString> tsHistory = chatHistory.getOrDefault(uuid, new ConcurrentLinkedDeque<>());
if (tsHistory.isEmpty()) return new ConcurrentLinkedDeque<>();
tsHistory.removeIf(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 > settingsManager.getProperty(PluginSettings.CHAT_CONTEXT_TIME_LIMIT));
return tsHistory.stream()
.filter(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 < settingsManager.getProperty(PluginSettings.CHAT_CONTEXT_TIME_LIMIT))
.map(TimedString::getString)
.collect(ArrayDeque::new, ArrayDeque::offerLast, ArrayDeque::addAll);
.collect(ConcurrentLinkedDeque::new, ConcurrentLinkedDeque::offerLast, ConcurrentLinkedDeque::addAll);
}

public static void clearPlayerContext(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import io.wdsj.asw.common.datatype.TimedString;
import org.bukkit.entity.Player;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;

import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager;

Expand All @@ -18,7 +18,7 @@ public class SignContext {
*/
public static void addMessage(Player player, String message) {
final UUID uuid = player.getUniqueId();
signEditHistory.computeIfAbsent(uuid, k -> new ArrayDeque<>());
signEditHistory.computeIfAbsent(uuid, k -> new ConcurrentLinkedDeque<>());
Deque<TimedString> history = signEditHistory.get(uuid);
while (history.size() >= settingsManager.getProperty(PluginSettings.SIGN_CONTEXT_MAX_SIZE)) {
history.pollFirst();
Expand All @@ -29,11 +29,12 @@ public static void addMessage(Player player, String message) {

public static Deque<String> getHistory(Player player) {
final UUID uuid = player.getUniqueId();
Deque<TimedString> tsHistory = signEditHistory.getOrDefault(uuid, new ArrayDeque<>());
Deque<TimedString> tsHistory = signEditHistory.getOrDefault(uuid, new ConcurrentLinkedDeque<>());
if (tsHistory.isEmpty()) return new ConcurrentLinkedDeque<>();
tsHistory.removeIf(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 > settingsManager.getProperty(PluginSettings.SIGN_CONTEXT_TIME_LIMIT));
return tsHistory.stream()
.filter(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 < settingsManager.getProperty(PluginSettings.SIGN_CONTEXT_TIME_LIMIT))
.map(TimedString::getString)
.collect(ArrayDeque::new, ArrayDeque::offerLast, ArrayDeque::addAll);
.collect(ConcurrentLinkedDeque::new, ConcurrentLinkedDeque::offerLast, ConcurrentLinkedDeque::addAll);
}

public static void clearPlayerContext(Player player) {
Expand Down
1 change: 0 additions & 1 deletion bukkit/src/main/resources/sensitive_word_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
0售麻古
0售麻果
0在这上边3上我们5加2企鹅4聊吧9如果5不介意0
0定金
1000人斩下载
100bb成人小电影
100到200不等
Expand Down
4 changes: 2 additions & 2 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.0</version>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -34,7 +34,7 @@
<goal>filter-sources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/templates</outputDirectory>
<outputDirectory>${project.build.directory}/templates</outputDirectory>
<sourceDirectory>src/main/java/io/wdsj/asw/common/template</sourceDirectory>
</configuration>
</execution>
Expand Down
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>1.0</version>
<version>1.1</version>
<packaging>pom</packaging>

<name>AdvancedSensitiveWords</name>
Expand Down
4 changes: 2 additions & 2 deletions velocity/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -122,7 +122,7 @@
<dependency>
<groupId>io.wdsj</groupId>
<artifactId>AdvancedSensitiveWords-common</artifactId>
<version>1.0</version>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down

0 comments on commit a445b39

Please sign in to comment.