mirror of
https://github.com/xzb23/Minecraft-Command-Permission-Control.git
synced 2026-11-22 00:34:36 +08:00
fix: 文档错误 and 修改不合适关键字
This commit is contained in:
4 files changed
+30
-30
No files matched your search
@@ -17,42 +17,42 @@ import java.util.Locale;
|
||||
public class CommandInterceptor {
|
||||
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 int arg_CHECKINDEX = 1;
|
||||
private static final int arg_PARAMETERS = 2;
|
||||
private static final int ARG_CHECKINDEX = 1;
|
||||
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 String cheatMsg;
|
||||
|
||||
public static void applyConfig() {
|
||||
blackList = initblackList(new ArrayList<>(Config.BLACKLIST.get()));
|
||||
blockList = initBlockList(new ArrayList<>(Config.BLOCKLIST.get()));
|
||||
opUUID = Config.PASSUUID.get().stream()
|
||||
.map(s -> s.toLowerCase(Locale.ROOT))
|
||||
.toList();
|
||||
cheatMsg = I18n_.i18nDic.get("aza.stopcheat.broadcast.cheat");
|
||||
}
|
||||
|
||||
public static List<List<String>> initblackList(List<String> commands){
|
||||
List<List<String>> blackList = new ArrayList<List<String>>();
|
||||
public static List<List<String>> initBlockList(List<String> commands){
|
||||
List<List<String>> blockList = new ArrayList<List<String>>();
|
||||
for (String command: commands) {
|
||||
List<String> black = new ArrayList<>(Arrays.asList(command.split(CMDSEPARATOR)));
|
||||
if (black.isEmpty()){
|
||||
List<String> blockedCommand = new ArrayList<>(Arrays.asList(command.split(CMDSEPARATOR)));
|
||||
if (blockedCommand.isEmpty()){
|
||||
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command);
|
||||
} else if (black.size() < 3){
|
||||
for (int i = 0; black.size() + i < 3; i++){
|
||||
black.add("0");
|
||||
} else if (blockedCommand.size() < 3){
|
||||
for (int i = 0; blockedCommand.size() + i < 3; i++){
|
||||
blockedCommand.add("0");
|
||||
}
|
||||
blackList.add(black);
|
||||
} else if (black.size() == 3){
|
||||
blackList.add(black);
|
||||
blockList.add(blockedCommand);
|
||||
} else if (blockedCommand.size() == 3){
|
||||
blockList.add(blockedCommand);
|
||||
} else {
|
||||
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.lan"), command);
|
||||
}
|
||||
}
|
||||
return blackList;
|
||||
return blockList;
|
||||
}
|
||||
|
||||
public static boolean checkPlayer(CommandSourceStack source){
|
||||
@@ -79,14 +79,14 @@ public class CommandInterceptor {
|
||||
String raw = parseResults.getReader().getString();
|
||||
String[] parts = raw.trim().split("\\s+");
|
||||
|
||||
for (List<String> blackCommands: blackList){
|
||||
if (parts[0].equals(blackCommands.get(arg_blackLISTCOMMANDNAME))){ // 输入的指令在黑名单中
|
||||
for (List<String> blockedCommand: blockList){
|
||||
if (parts[0].equals(blockedCommand.get(ARG_BLOCKLIST_COMMAND_NAME))){ // 输入的指令在黑名单中
|
||||
int stopIndex;
|
||||
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){
|
||||
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.stopindex"), String.join(CMDSEPARATOR, blackCommands));
|
||||
stopIndex = arg_blackLISTCOMMANDNAME;
|
||||
LOGGER.warn(I18n_.i18nDic.get("aza.stopcheat.warn.config.stopindex"), String.join(CMDSEPARATOR, blockedCommand));
|
||||
stopIndex = ARG_BLOCKLIST_COMMAND_NAME;
|
||||
}
|
||||
if (stopIndex == 0){ // 禁止整个指令而不是特定参数的指令
|
||||
event.setCanceled(true);
|
||||
@@ -94,8 +94,8 @@ public class CommandInterceptor {
|
||||
broadcast(cheatMsg);
|
||||
}
|
||||
else {
|
||||
List<String> blackArgs = Arrays.asList(blackCommands.get(arg_PARAMETERS).split(","));
|
||||
if (blackArgs.contains(parts[stopIndex])){ // 禁止特定参数的指令,在配置中定义
|
||||
List<String> blockedArgs = Arrays.asList(blockedCommand.get(ARG_PARAMETERS).split(","));
|
||||
if (blockedArgs .contains(parts[stopIndex])){ // 禁止特定参数的指令,在配置中定义
|
||||
event.setCanceled(true);
|
||||
LOGGER.info(I18n_.i18nDic.get("aza.stopcheat.log.intercept"), source.getTextName(), raw);
|
||||
broadcast(cheatMsg);
|
||||
|
||||
@@ -19,12 +19,12 @@ public class Config {
|
||||
.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("格式为{cmd}:{checkIndex}:{arg1[,arg2,...]}")
|
||||
.comment("格式为{指令}:{禁用第几个参数}:禁用的参数1[,禁用的参数2,...]}")
|
||||
.comment("格式为{指令}:{禁用第几个参数}:{禁用的参数1[,禁用的参数2,...]}")
|
||||
.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
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"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.broadcast.reload": "Configuration reloaded",
|
||||
"aza.stopcheat.broadcast.cheat": "§cNo cheating allowed (>v0",
|
||||
|
||||
"stopcheat.configuration.version": "Config Version",
|
||||
"stopcheat.configuration.blacked_commands": "Blacklisted Commands",
|
||||
"stopcheat.configuration.blocked_commands": "Blacklisted Commands",
|
||||
"stopcheat.configuration.pass_users": "Bypass Users"
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"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.broadcast.reload": "配置重载完成",
|
||||
"aza.stopcheat.broadcast.cheat": "§c不准作弊哦(>v0",
|
||||
|
||||
"stopcheat.configuration.version": "配置文件版本",
|
||||
"stopcheat.configuration.blacked_commands": "禁用指令列表",
|
||||
"stopcheat.configuration.blocked_commands": "禁用指令列表",
|
||||
"stopcheat.configuration.pass_users": "白名单玩家"
|
||||
}
|
||||
Reference in new issue
Block a user