Skip to content

Commit a445b39

Browse files
committed
Version 1.1
1 parent 4162246 commit a445b39

File tree

13 files changed

+60
-37
lines changed

13 files changed

+60
-37
lines changed

bukkit/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>io.wdsj</groupId>
1212
<artifactId>AdvancedSensitiveWords</artifactId>
13-
<version>1.0</version>
13+
<version>1.1</version>
1414
<relativePath>../pom.xml</relativePath>
1515
</parent>
1616

@@ -403,7 +403,7 @@
403403
<dependency>
404404
<groupId>io.wdsj</groupId>
405405
<artifactId>AdvancedSensitiveWords-common</artifactId>
406-
<version>1.0</version>
406+
<version>1.1</version>
407407
<scope>compile</scope>
408408
</dependency>
409409
</dependencies>

bukkit/src/main/java/io/wdsj/asw/bukkit/integration/placeholder/ASWExpansion.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.wdsj.asw.bukkit.AdvancedSensitiveWords;
44
import io.wdsj.asw.bukkit.manage.punish.PlayerShadowController;
5+
import io.wdsj.asw.bukkit.manage.punish.ViolationCounter;
56
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
67
import org.bukkit.OfflinePlayer;
78
import org.bukkit.entity.Player;
@@ -35,8 +36,8 @@ public String onRequest(OfflinePlayer player, @NotNull String params) {
3536
if (params.equalsIgnoreCase("version")) {
3637
return getVersion();
3738
}
38-
if (params.equalsIgnoreCase("current_total")) {
39-
return String.valueOf(messagesFilteredNum);
39+
if (params.equalsIgnoreCase("total_filtered")) {
40+
return String.valueOf(messagesFilteredNum.get());
4041
}
4142
if (params.equalsIgnoreCase("is_shadow")) {
4243
if (player != null) {
@@ -46,6 +47,14 @@ public String onRequest(OfflinePlayer player, @NotNull String params) {
4647
}
4748
}
4849
}
50+
if (params.equalsIgnoreCase("violation_count")) {
51+
if (player != null) {
52+
Player onlinePlayer = player.getPlayer();
53+
if (onlinePlayer != null) {
54+
return String.valueOf(ViolationCounter.getViolationCount(onlinePlayer));
55+
}
56+
}
57+
}
4958
return null;
5059
}
5160
}

bukkit/src/main/java/io/wdsj/asw/bukkit/service/BukkitLibraryService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BukkitLibraryService {
1919
.groupId("dev{}ai4j")
2020
.artifactId("openai4j")
2121
.resolveTransitiveDependencies(true)
22-
.version("0.21.0")
22+
.version("0.22.0")
2323
.build();
2424

2525
private static final Library caffeine = Library.builder()

bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,21 @@ public class PluginSettings implements SettingsHolder {
282282
"Whether to enable punishment"})
283283
public static final Property<Boolean> CHAT_PUNISH = newProperty("Chat.punish", true);
284284

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

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

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

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

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

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

339339
@Comment({"重载时是否清空缓存",
340340
"Whether to clear cache on reload"})

bukkit/src/main/java/io/wdsj/asw/bukkit/task/punish/ViolationResetTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@
55
import io.wdsj.asw.bukkit.manage.punish.ViolationCounter;
66
import io.wdsj.asw.bukkit.setting.PluginMessages;
77
import io.wdsj.asw.bukkit.setting.PluginSettings;
8+
import io.wdsj.asw.bukkit.util.SchedulingUtils;
9+
import io.wdsj.asw.bukkit.util.message.MessageUtils;
810
import org.bukkit.Bukkit;
9-
import org.bukkit.ChatColor;
1011
import org.bukkit.entity.Player;
1112

12-
import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.messagesManager;
1313
import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager;
1414

15+
/**
16+
* **Asynchronous** task to reset the violation count of players.
17+
*/
1518
public class ViolationResetTask extends UniversalRunnable {
1619
@Override
1720
public void run() {
1821
if (settingsManager.getProperty(PluginSettings.ONLY_RESET_ONLINE_PLAYERS)) {
19-
for (Player player : Bukkit.getOnlinePlayers()) {
22+
for (Player player : SchedulingUtils.callSyncMethod(Bukkit::getOnlinePlayers)) {
2023
ViolationCounter.resetViolationCount(player);
2124
}
2225
} else {
2326
ViolationCounter.resetAllViolations();
2427
}
25-
String message = ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.MESSAGE_ON_VIOLATION_RESET));
28+
String message = MessageUtils.retrieveMessage(PluginMessages.MESSAGE_ON_VIOLATION_RESET);
2629
Notifier.normalNotice(message);
2730
}
2831
}

bukkit/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.bukkit.Location;
88
import org.bukkit.entity.Entity;
99

10+
import java.util.concurrent.Callable;
11+
1012
public class SchedulingUtils {
1113
private SchedulingUtils() {
1214
}
@@ -41,4 +43,12 @@ public static void cancelTaskSafely(MyScheduledTask task) {
4143
task.cancel();
4244
}
4345

46+
public static <T> T callSyncMethod(Callable<T> callable) {
47+
try {
48+
return AdvancedSensitiveWords.getScheduler().callSyncMethod(callable).get();
49+
} catch (Exception e) {
50+
throw new RuntimeException(e);
51+
}
52+
}
53+
4454
}

bukkit/src/main/java/io/wdsj/asw/bukkit/util/context/ChatContext.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import io.wdsj.asw.common.datatype.TimedString;
55
import org.bukkit.entity.Player;
66

7-
import java.util.ArrayDeque;
87
import java.util.Deque;
98
import java.util.UUID;
109
import java.util.concurrent.ConcurrentHashMap;
10+
import java.util.concurrent.ConcurrentLinkedDeque;
1111

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

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

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

3940
public static void clearPlayerContext(Player player) {

bukkit/src/main/java/io/wdsj/asw/bukkit/util/context/SignContext.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import io.wdsj.asw.common.datatype.TimedString;
55
import org.bukkit.entity.Player;
66

7-
import java.util.ArrayDeque;
87
import java.util.Deque;
98
import java.util.UUID;
109
import java.util.concurrent.ConcurrentHashMap;
10+
import java.util.concurrent.ConcurrentLinkedDeque;
1111

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

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

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

3940
public static void clearPlayerContext(Player player) {

bukkit/src/main/resources/sensitive_word_dict.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
0售麻古
2323
0售麻果
2424
0在这上边3上我们5加2企鹅4聊吧9如果5不介意0
25-
0定金
2625
1000人斩下载
2726
100bb成人小电影
2827
100到200不等

bungee/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>io.wdsj</groupId>
1212
<artifactId>AdvancedSensitiveWords</artifactId>
13-
<version>1.0</version>
13+
<version>1.1</version>
1414
<relativePath>../pom.xml</relativePath>
1515
</parent>
1616

@@ -88,7 +88,7 @@
8888
<dependency>
8989
<groupId>io.wdsj</groupId>
9090
<artifactId>AdvancedSensitiveWords-common</artifactId>
91-
<version>1.0</version>
91+
<version>1.1</version>
9292
<scope>compile</scope>
9393
</dependency>
9494
</dependencies>

0 commit comments

Comments
 (0)