fix: 文档错误 and 修改不合适关键字

This commit is contained in:
xzb23 committed 2026-08-29 12:52:22 +08:00
1 parent ac5749a03e
commit 627ef9bcd8
4 files changed
+30 -30

No files matched your search

@@ -17,42 +17,42 @@ import java.util.Locale;
public class CommandInterceptor { public class CommandInterceptor {
public static final org.slf4j.Logger LOGGER = LogUtils.getLogger(); public static final org.slf4j.Logger LOGGER = LogUtils.getLogger();
private static final int arg_blackLISTCOMMANDNAME = 0; private static final int ARG_BLOCKLIST_COMMAND_NAME = 0;
private static final String CMDSEPARATOR = ":"; private static final String CMDSEPARATOR = ":";
private static final int arg_CHECKINDEX = 1; private static final int ARG_CHECKINDEX = 1;
private static final int arg_PARAMETERS = 2; private static final int ARG_PARAMETERS = 2;
// 从配置获取黑名单命令和白名单玩家列表 // 从配置获取黑名单命令和白名单玩家列表
private static List<List<String>> blackList; private static List<List<String>> blockList;
private static List<String> opUUID; private static List<String> opUUID;
private static String cheatMsg; private static String cheatMsg;
public static void applyConfig() { public static void applyConfig() {
blackList = initblackList(new ArrayList<>(Config.BLACKLIST.get())); blockList = initBlockList(new ArrayList<>(Config.BLOCKLIST.get()));
opUUID = Config.PASSUUID.get().stream() opUUID = Config.PASSUUID.get().stream()
.map(s -> s.toLowerCase(Locale.ROOT)) .map(s -> s.toLowerCase(Locale.ROOT))
.toList(); .toList();
cheatMsg = I18n_.i18nDic.get("aza.stopcheat.broadcast.cheat"); cheatMsg = I18n_.i18nDic.get("aza.stopcheat.broadcast.cheat");
} }
public static List<List<String>> initblackList(List<String> commands){ public static List<List<String>> initBlockList(List<String> commands){
List<List<String>> blackList = new ArrayList<List<String>>(); List<List<String>> blockList = new ArrayList<List<String>>();
for (String command: commands) { for (String command: commands) {
List<String> black = new ArrayList<>(Arrays.asList(command.split(CMDSEPARATOR))); List<String> blockedCommand = new ArrayList<>(Arrays.asList(command.split(CMDSEPARATOR)));
if (black.isEmpty()){ if (blockedCommand.isEmpty()){
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command); LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command);
} else if (black.size() < 3){ } else if (blockedCommand.size() < 3){
for (int i = 0; black.size() + i < 3; i++){ for (int i = 0; blockedCommand.size() + i < 3; i++){
black.add("0"); blockedCommand.add("0");
} }
blackList.add(black); blockList.add(blockedCommand);
} else if (black.size() == 3){ } else if (blockedCommand.size() == 3){
blackList.add(black); blockList.add(blockedCommand);
} else { } else {
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command); LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command);
} }
} }
return blackList; return blockList;
} }
public static boolean checkPlayer(CommandSourceStack source){ public static boolean checkPlayer(CommandSourceStack source){
@@ -79,14 +79,14 @@ public class CommandInterceptor {
String raw = parseResults.getReader().getString(); String raw = parseResults.getReader().getString();
String[] parts = raw.trim().split("\\s+"); String[] parts = raw.trim().split("\\s+");
for (List<String> blackCommands: blackList){ for (List<String> blockedCommand: blockList){
if (parts[0].equals(blackCommands.get(arg_blackLISTCOMMANDNAME))){ // 输入的指令在黑名单中 if (parts[0].equals(blockedCommand.get(ARG_BLOCKLIST_COMMAND_NAME))){ // 输入的指令在黑名单中
int stopIndex; int stopIndex;
try { try {
stopIndex = Integer.parseInt(blackCommands.get(arg_CHECKINDEX)); // 将blackCommands[args_STOPINDEX] 转换为为Integer stopIndex = Integer.parseInt(blockedCommand.get(ARG_CHECKINDEX)); // blockedCommand[ARG_STOPINDEX] 转换为为Integer
}catch (NumberFormatException e){ }catch (NumberFormatException e){
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.stopindex"), String.join(CMDSEPARATOR, blackCommands)); LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.stopindex"), String.join(CMDSEPARATOR, blockedCommand));
stopIndex = arg_blackLISTCOMMANDNAME; stopIndex = ARG_BLOCKLIST_COMMAND_NAME;
} }
if (stopIndex == 0){ // 禁止整个指令而不是特定参数的指令 if (stopIndex == 0){ // 禁止整个指令而不是特定参数的指令
event.setCanceled(true); event.setCanceled(true);
@@ -94,8 +94,8 @@ public class CommandInterceptor {
broadcast(cheatMsg); broadcast(cheatMsg);
} }
else { else {
List<String> blackArgs = Arrays.asList(blackCommands.get(arg_PARAMETERS).split(",")); List<String> blockedArgs = Arrays.asList(blockedCommand.get(ARG_PARAMETERS).split(","));
if (blackArgs.contains(parts[stopIndex])){ // 禁止特定参数的指令,在配置中定义 if (blockedArgs .contains(parts[stopIndex])){ // 禁止特定参数的指令,在配置中定义
event.setCanceled(true); event.setCanceled(true);
LOGGER.info(I18n_.i18nDic.get("aza.stopcheat.log.intercept"), source.getTextName(), raw); LOGGER.info(I18n_.i18nDic.get("aza.stopcheat.log.intercept"), source.getTextName(), raw);
broadcast(cheatMsg); broadcast(cheatMsg);
@@ -19,12 +19,12 @@ public class Config {
.defineInRange("version", 1, 0, Integer.MAX_VALUE); .defineInRange("version", 1, 0, Integer.MAX_VALUE);
public static final ModConfigSpec.ConfigValue<List<? extends String>> BLACKLIST = BUILDER public static final ModConfigSpec.ConfigValue<List<? extends String>> BLOCKLIST = BUILDER
.comment("禁用的指令列表") .comment("禁用的指令列表")
.comment("格式为{cmd}:{checkIndex}:{arg1[,arg2,...]}") .comment("格式为{cmd}:{checkIndex}:{arg1[,arg2,...]}")
.comment("格式为{指令}:{禁用第几个参数}:禁用的参数1[,禁用的参数2,...]}") .comment("格式为{指令}:{禁用第几个参数}:{禁用的参数1[,禁用的参数2,...]}")
.comment("其中{checkIndex}填0代表禁用整个指令") .comment("其中{checkIndex}填0代表禁用整个指令")
.defineList("blacked_commands", List.of("give:0:", "fill:0:", "gamemode:1:creative"), obj -> obj instanceof String); .defineList("blocked_commands", List.of("give:0:", "fill:0:", "gamemode:1:creative"), obj -> obj instanceof String);
public static final ModConfigSpec.ConfigValue<List<? extends String>> PASSUUID = BUILDER public static final ModConfigSpec.ConfigValue<List<? extends String>> PASSUUID = BUILDER
@@ -1,11 +1,11 @@
{ {
"aza.stopcheat.warn.config.lan": "{} configuration unavailable, length error", "aza.stopcheat.warn.config.lan": "{} configuration unavailable, length error",
"aza.stopcheat.warn.config.stopindex": "{} configuration unavailable, args_STOPINDEX error, reset to 0", "aza.stopcheat.warn.config.stopindex": "{} configuration unavailable, ARG_STOPINDEX error, reset to 0",
"aza.stopcheat.log.intercept": "{} used {} command and was intercepted", "aza.stopcheat.log.intercept": "{} used {} command and was intercepted",
"aza.stopcheat.broadcast.reload": "Configuration reloaded", "aza.stopcheat.broadcast.reload": "Configuration reloaded",
"aza.stopcheat.broadcast.cheat": "§cNo cheating allowed (>v0", "aza.stopcheat.broadcast.cheat": "§cNo cheating allowed (>v0",
"stopcheat.configuration.version": "Config Version", "stopcheat.configuration.version": "Config Version",
"stopcheat.configuration.blacked_commands": "Blacklisted Commands", "stopcheat.configuration.blocked_commands": "Blacklisted Commands",
"stopcheat.configuration.pass_users": "Bypass Users" "stopcheat.configuration.pass_users": "Bypass Users"
} }
@@ -1,11 +1,11 @@
{ {
"aza.stopcheat.warn.config.lan": "{} 配置不可用, 长度错误", "aza.stopcheat.warn.config.lan": "{} 配置不可用, 长度错误",
"aza.stopcheat.warn.config.stopindex": "{} 配置不可用, args_STOPINDEX错误,重置为0", "aza.stopcheat.warn.config.stopindex": "{} 配置不可用, ARG_STOPINDEX错误,重置为0",
"aza.stopcheat.log.intercept": "{} 使用 {} 命令被拦截", "aza.stopcheat.log.intercept": "{} 使用 {} 命令被拦截",
"aza.stopcheat.broadcast.reload": "配置重载完成", "aza.stopcheat.broadcast.reload": "配置重载完成",
"aza.stopcheat.broadcast.cheat": "§c不准作弊哦(>v0", "aza.stopcheat.broadcast.cheat": "§c不准作弊哦(>v0",
"stopcheat.configuration.version": "配置文件版本", "stopcheat.configuration.version": "配置文件版本",
"stopcheat.configuration.blacked_commands": "禁用指令列表", "stopcheat.configuration.blocked_commands": "禁用指令列表",
"stopcheat.configuration.pass_users": "白名单玩家" "stopcheat.configuration.pass_users": "白名单玩家"
} }