Skip to content

Commit

Permalink
feat(bukkit): Number full-match
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Sep 20, 2024
1 parent 7ac6d88 commit 1081946
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.wdsj.asw.bukkit.ai.OpenAIProcessor;
import io.wdsj.asw.bukkit.command.ConstructCommandExecutor;
import io.wdsj.asw.bukkit.command.ConstructTabCompleter;
import io.wdsj.asw.bukkit.core.condition.WordResultConditionNumMatch;
import io.wdsj.asw.bukkit.integration.placeholder.ASWExpansion;
import io.wdsj.asw.bukkit.listener.*;
import io.wdsj.asw.bukkit.listener.packet.ASWBookPacketListener;
Expand Down Expand Up @@ -246,6 +247,9 @@ public void doInitTasks() {
case 2:
condition = WordResultConditions.englishWordNumMatch();
break;
case 3:
condition = new WordResultConditionNumMatch();
break;
default:
condition = WordResultConditions.alwaysTrue();
LOGGER.warning("Invalid full match mode, will turn off full match.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.wdsj.asw.bukkit.core.condition;

import com.github.houbb.heaven.util.lang.CharUtil;
import com.github.houbb.sensitive.word.api.IWordContext;
import com.github.houbb.sensitive.word.api.IWordResult;
import com.github.houbb.sensitive.word.constant.enums.WordValidModeEnum;
import com.github.houbb.sensitive.word.support.resultcondition.AbstractWordResultCondition;

public class WordResultConditionNumMatch extends AbstractWordResultCondition {
@Override
protected boolean doMatch(IWordResult wordResult, String text, WordValidModeEnum modeEnum, IWordContext context) {
final int startIndex = wordResult.startIndex();
final int endIndex = wordResult.endIndex();
if (startIndex > 0) {
char preC = text.charAt(startIndex-1);
if (CharUtil.isDigit(preC)) {
return false;
}
}
if (endIndex < text.length()) {
char afterC = text.charAt(endIndex);
if (CharUtil.isDigit(afterC)) {
return false;
}
}
for (int i = startIndex; i < endIndex; i++) {
char c = text.charAt(i);
if (!CharUtil.isDigit(c)) {
return true;
}
}
return true;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ public class PluginSettings implements SettingsHolder {

@Comment({"是否启用全词匹配",
"(例:屏蔽了av但又不想让have被屏蔽)",
"(匹配模式: 0-关闭全词匹配, 1-英文全词匹配, 2-英文&数字全词匹配)",
"(匹配模式: 0-关闭全词匹配, 1-英文全词匹配, 2-英文&数字全词匹配, 3-数字全词匹配)",
"Whether to force full-word matches",
"(e.g., to block 'av' without blocking 'have')",
"(Modes: 0-Off, 1-English full match, 2-English&Number full match)"})
"(Modes: 0-Off, 1-English full match, 2-English&Number full match, 3-Number full match)"})
public static final Property<Integer> FULL_MATCH_MODE = newProperty("Plugin.fullMatchMode", 0);

@Comment({"检测重复字符(例:SSSSSBBBBB)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.wdsj.asw.bukkit.listener

import io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager
import io.wdsj.asw.bukkit.manage.punish.PlayerShadowController
import io.wdsj.asw.bukkit.setting.PluginSettings
import io.wdsj.asw.bukkit.util.context.ChatContext
import io.wdsj.asw.bukkit.util.context.SignContext
Expand Down Expand Up @@ -29,5 +30,6 @@ class QuitDataCleaner : Listener {
private fun doCleanTask(player: Player) {
ChatContext.clearPlayerContext(player)
SignContext.clearPlayerContext(player)
PlayerShadowController.unshadowPlayer(player)
}
}

0 comments on commit 1081946

Please sign in to comment.