Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ java {
dependencies {
compileOnly("org.jetbrains:annotations:26.1.0")
compileOnly("com.google.code.gson:gson:2.12.1")
compileOnly("com.google.guava:guava:33.4.0-jre")
compileOnly("com.google.guava:guava:${property("guavaVersion")}")
}

buildConfig {
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pluginVersion=2.1.0
versionChannel=release

# dependencies
paperVersion=1.21.11-R0.1-SNAPSHOT
cloudVersion=2.0.0-beta.15
langchain4jVersion=1.16.3
jmhVersion=1.37
caffeineVersion=3.2.4
hikariCPVersion=7.1.0
guavaVersion=33.4.0-jre
13 changes: 10 additions & 3 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ dependencies {
implementation("org.incendo:cloud-paper:${property("cloudVersion")}")
implementation("org.incendo:cloud-minecraft-extras:${property("cloudVersion")}")

compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:${property("paperVersion")}")
compileOnly("me.clip:placeholderapi:2.12.2")
compileOnly("org.geysermc.floodgate:api:2.2.5-SNAPSHOT")
compileOnly("fr.xephi:authme:5.7.0-SNAPSHOT")
compileOnly("com.github.retrooper:packetevents-spigot:2.13.0")
compileOnly("org.jetbrains:annotations:26.1.0")
compileOnly("com.google.guava:guava:33.4.0-jre")
compileOnly("com.github.ben-manes.caffeine:caffeine:${property("caffeineVersion")}")
compileOnly("com.zaxxer:HikariCP:${property("hikariCPVersion")}")
compileOnly("dev.langchain4j:langchain4j-open-ai:${property("langchain4jVersion")}")
compileOnly("dev.langchain4j:langchain4j-anthropic:${property("langchain4jVersion")}")
compileOnly("dev.langchain4j:langchain4j-http-client-jdk:${property("langchain4jVersion")}")
Expand All @@ -55,15 +57,18 @@ dependencies {
runtimeOnly("org.snakeyaml:snakeyaml-engine:2.7")

testImplementation("org.junit.jupiter:junit-jupiter:6.1.1")
testImplementation("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
testImplementation("io.papermc.paper:paper-api:${property("paperVersion")}")
testImplementation("dev.langchain4j:langchain4j-open-ai:${property("langchain4jVersion")}")
testImplementation("dev.langchain4j:langchain4j-anthropic:${property("langchain4jVersion")}")
testImplementation("dev.langchain4j:langchain4j-http-client-jdk:${property("langchain4jVersion")}")
testImplementation("com.zaxxer:HikariCP:${property("hikariCPVersion")}")
testImplementation("com.github.ben-manes.caffeine:caffeine:${property("caffeineVersion")}")
testRuntimeOnly("org.slf4j:slf4j-nop:2.0.17")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.1.0")

add(jmh.implementationConfigurationName, "org.openjdk.jmh:jmh-core:${property("jmhVersion")}")
add(jmh.annotationProcessorConfigurationName, "org.openjdk.jmh:jmh-generator-annprocess:${property("jmhVersion")}")
add(jmh.runtimeOnlyConfigurationName, "com.google.guava:guava:33.4.0-jre")
add(jmh.runtimeOnlyConfigurationName, "com.google.guava:guava:${property("guavaVersion")}")
}

configurations.named(jmh.implementationConfigurationName) {
Expand Down Expand Up @@ -105,6 +110,8 @@ tasks.processResources {
"pluginDescription" to pluginDescription,
"gitCommitShort" to rootProject.extra["gitCommitShort"],
"langchain4jVersion" to project.property("langchain4jVersion"),
"caffeineVersion" to project.property("caffeineVersion"),
"hikariCPVersion" to project.property("hikariCPVersion"),
)
inputs.properties(properties)
filesMatching("plugin.yml") {
Expand Down
115 changes: 109 additions & 6 deletions paper/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import com.github.houbb.sensitive.word.api.IWordAllow;
import com.github.houbb.sensitive.word.api.IWordDeny;
import com.github.houbb.sensitive.word.api.IWordResult;
import com.github.houbb.sensitive.word.api.IWordResultCondition;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import com.github.houbb.sensitive.word.support.allow.WordAllows;
import com.github.houbb.sensitive.word.support.check.WordChecks;
import com.github.houbb.sensitive.word.support.deny.WordDenys;
import com.github.houbb.sensitive.word.support.result.WordResultHandlers;
import com.github.houbb.sensitive.word.support.resultcondition.WordResultConditions;
import com.github.houbb.sensitive.word.support.tag.WordTags;
import io.wdsj.asw.bukkit.command.AswCommandRegistrar;
import io.wdsj.asw.bukkit.ai.LlmChatDetectionService;
import io.wdsj.asw.bukkit.core.condition.WordResultConditionNumMatch;
import io.wdsj.asw.bukkit.integration.placeholder.ASWExpansion;
import io.wdsj.asw.bukkit.manage.playergroup.PlayerGroupService;
import io.wdsj.asw.bukkit.service.chat.antispam.ChatAntiSpamService;
import io.wdsj.asw.bukkit.manage.punish.PlayerAltController;
import io.wdsj.asw.bukkit.manage.punish.PlayerShadowController;
Expand Down Expand Up @@ -44,6 +47,10 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import static io.wdsj.asw.bukkit.util.LoggingUtils.purgeLog;
import static io.wdsj.asw.bukkit.util.TimingUtils.resetStatistics;
import static io.wdsj.asw.bukkit.util.Utils.*;
Expand All @@ -52,6 +59,7 @@
public final class AdvancedSensitiveWords extends JavaPlugin {
public static volatile boolean isInitialized = false;
public static SensitiveWordBs sensitiveWordBs;
public static SensitiveWordBs networkSensitiveWordBs;
public static boolean isAuthMeAvailable;
public static final String PLUGIN_VERSION = PluginBuildInfo.VERSION;
private static AdvancedSensitiveWords instance;
Expand All @@ -62,6 +70,7 @@ public final class AdvancedSensitiveWords extends JavaPlugin {
private PaperConfigurationService configurationService;
private volatile Updater.UpdateResult updateResult = Updater.UpdateResult.noUpdate();
private AswCommandRegistrar commandRegistrar;
private PlayerGroupService playerGroupService;
public static TaskScheduler getScheduler() {
return scheduler;
}
Expand All @@ -85,6 +94,10 @@ public LlmChatDetectionService getLlmChatDetectionService() {
return listenerService.getLlmChatDetectionService();
}

public PlayerGroupService getPlayerGroupService() {
return playerGroupService;
}

public static <T> T setting(SettingKey<T> key) {
return instance.configurationService.get(key);
}
Expand Down Expand Up @@ -112,6 +125,7 @@ public void onEnable() {
BookCache.initialize();
doInitTasks();
if (configurationService.get(PluginSettings.PURGE_LOG_FILE)) purgeLog();
initializePlayerGroups();
listenerService = new ListenerService(this);
listenerService.registerListeners();
commandRegistrar = new AswCommandRegistrar(this);
Expand All @@ -134,6 +148,7 @@ public void doInitTasks() {
IWordAllow wA = WordAllows.chains(WordAllows.defaults(), new WordAllow(), new ExternalWordAllow(this));
isInitialized = false;
sensitiveWordBs = null;
networkSensitiveWordBs = null;
IWordResultCondition condition = createWordResultCondition();
getScheduler().runTaskAsynchronously(() -> {
IWordDeny wordDeny = createWordDeny();
Expand All @@ -145,20 +160,20 @@ public void doInitTasks() {
.ignoreEnglishStyle(configurationService.get(PluginSettings.IGNORE_ENGLISH_STYLE))
.ignoreRepeat(configurationService.get(PluginSettings.IGNORE_REPEAT))
.enableNumCheck(configurationService.get(PluginSettings.ENABLE_NUM_CHECK))
.enableEmailCheck(configurationService.get(PluginSettings.ENABLE_EMAIL_CHECK))
.enableUrlCheck(configurationService.get(PluginSettings.ENABLE_URL_CHECK))
.enableEmailCheck(false)
.enableUrlCheck(false)
.enableWordCheck(configurationService.get(PluginSettings.ENABLE_WORD_CHECK))
.wordResultCondition(condition)
.wordCheckUrl(configurationService.get(PluginSettings.URL_CHECK_NO_PREFIX) ? WordChecks.urlNoPrefix() : WordChecks.url())
.wordDeny(wordDeny)
.wordAllow(wA)
.numCheckLen(configurationService.get(PluginSettings.NUM_CHECK_LEN))
.wordReplace(new WordReplace())
.wordTag(WordTags.none())
.charIgnore(new CharIgnore())
.enableIpv4Check(configurationService.get(PluginSettings.ENABLE_IP_CHECK))
.charIgnore(new CharIgnore(configurationService.get(PluginSettings.IGNORE_CHAR)))
.enableIpv4Check(false)
.wordFailFast(configurationService.get(PluginSettings.FAIL_FAST))
.init();
networkSensitiveWordBs = createNetworkSensitiveWordBs();
isInitialized = true;
});
}
Expand All @@ -178,13 +193,27 @@ public void onDisable() {
ViolationCounter.INSTANCE.resetAllViolations();
SchedulingUtils.cancelTaskSafely(violationResetTask);
if (permCache != null) permCache.disable();
if (isInitialized) sensitiveWordBs.destroy();
if (playerGroupService != null) {
playerGroupService.close();
playerGroupService = null;
}
if (isInitialized) {
sensitiveWordBs.destroy();
if (networkSensitiveWordBs != null) {
networkSensitiveWordBs.destroy();
}
}
commandRegistrar = null;
LOGGER.info("AdvancedSensitiveWords is disabled.");
}

public void reloadPluginConfiguration() {
configurationService.reload();
if (playerGroupService == null && configurationService.get(PluginSettings.PLAYER_GROUPS_ENABLED)) {
initializePlayerGroups();
} else if (playerGroupService != null) {
playerGroupService.reloadConfiguration();
}
if (listenerService != null) {
listenerService.reloadConfiguration();
}
Expand Down Expand Up @@ -220,6 +249,19 @@ private void scheduleViolationResetTask() {
violationResetTask = new ViolationResetTask().runTaskTimerAsynchronously(this, resetIntervalTicks, resetIntervalTicks);
}

private void initializePlayerGroups() {
if (!configurationService.get(PluginSettings.PLAYER_GROUPS_ENABLED)) {
return;
}
try {
playerGroupService = new PlayerGroupService(this);
playerGroupService.start();
} catch (Exception exception) {
LOGGER.error("Failed to initialize player group storage.", exception);
throw new IllegalStateException("Unable to initialize player group storage", exception);
}
}

private void checkForUpdatesAsync() {
if (!configurationService.get(PluginSettings.CHECK_FOR_UPDATE)) {
return;
Expand Down Expand Up @@ -282,6 +324,34 @@ private IWordResultCondition createWordResultCondition() {
};
}

private SensitiveWordBs createNetworkSensitiveWordBs() {
boolean enableEmail = configurationService.get(PluginSettings.ENABLE_EMAIL_CHECK);
boolean enableUrl = configurationService.get(PluginSettings.ENABLE_URL_CHECK);
boolean enableIp = configurationService.get(PluginSettings.ENABLE_IP_CHECK);
if (!enableEmail && !enableUrl && !enableIp) {
return null;
}
return SensitiveWordBs.newInstance()
.ignoreCase(configurationService.get(PluginSettings.IGNORE_CASE))
.ignoreWidth(configurationService.get(PluginSettings.IGNORE_WIDTH))
.ignoreNumStyle(configurationService.get(PluginSettings.IGNORE_NUM_STYLE))
.ignoreChineseStyle(configurationService.get(PluginSettings.IGNORE_CHINESE_STYLE))
.ignoreEnglishStyle(configurationService.get(PluginSettings.IGNORE_ENGLISH_STYLE))
.ignoreRepeat(configurationService.get(PluginSettings.IGNORE_REPEAT))
.enableNumCheck(false)
.enableEmailCheck(enableEmail)
.enableUrlCheck(enableUrl)
.enableWordCheck(false)
.wordResultCondition(WordResultConditions.alwaysTrue())
.wordCheckUrl(configurationService.get(PluginSettings.URL_CHECK_NO_PREFIX) ? WordChecks.urlNoPrefix() : WordChecks.url())
.wordReplace(new WordReplace())
.wordTag(WordTags.none())
.charIgnore(new CharIgnore(configurationService.get(PluginSettings.IGNORE_CHAR), CharIgnore.NETWORK_SYNTAX_CHARS))
.enableIpv4Check(enableIp)
.wordFailFast(configurationService.get(PluginSettings.FAIL_FAST))
.init();
}

private IWordDeny createWordDeny() {
boolean enableDefaultWords = configurationService.get(PluginSettings.ENABLE_DEFAULT_WORDS);
boolean enableOnlineWords = configurationService.get(PluginSettings.ENABLE_ONLINE_WORDS);
Expand All @@ -297,4 +367,37 @@ private IWordDeny createWordDeny() {
return WordDenys.chains(new WordDeny(), new ExternalWordDeny(this));
}

public static List<String> findAllSensitive(String text) {
LinkedHashSet<String> results = new LinkedHashSet<>();
SensitiveWordBs wordBs = sensitiveWordBs;
if (wordBs != null) {
results.addAll(wordBs.findAll(text));
}
SensitiveWordBs networkWordBs = networkSensitiveWordBs;
if (networkWordBs != null) {
results.addAll(networkWordBs.findAll(text));
}
return List.copyOf(results);
}

public static List<IWordResult> findAllSensitiveRaw(String text) {
List<IWordResult> results = new ArrayList<>();
SensitiveWordBs wordBs = sensitiveWordBs;
if (wordBs != null) {
results.addAll(wordBs.findAll(text, WordResultHandlers.raw()));
}
SensitiveWordBs networkWordBs = networkSensitiveWordBs;
if (networkWordBs != null) {
results.addAll(networkWordBs.findAll(text, WordResultHandlers.raw()));
}
return results;
}

public static String replaceSensitive(String text) {
SensitiveWordBs wordBs = sensitiveWordBs;
String result = wordBs == null ? text : wordBs.replace(text);
SensitiveWordBs networkWordBs = networkSensitiveWordBs;
return networkWordBs == null ? result : networkWordBs.replace(result);
}

}
4 changes: 2 additions & 2 deletions paper/src/main/java/io/wdsj/asw/bukkit/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public boolean isInitialized() {
* @see #isInitialized()
*/
public List<String> findSensitiveWords(String text) {
return AdvancedSensitiveWords.sensitiveWordBs.findAll(text);
return AdvancedSensitiveWords.findAllSensitive(text);
}

/**
Expand All @@ -41,6 +41,6 @@ public List<String> findSensitiveWords(String text) {
* @see #isInitialized()
*/
public String replaceSensitiveWords(String text) {
return AdvancedSensitiveWords.sensitiveWordBs.replace(text);
return AdvancedSensitiveWords.replaceSensitive(text);
}
}
Loading