mirror of
https://github.com/xzb23/Minecraft-Command-Permission-Control.git
synced 2026-11-22 00:34:36 +08:00
更新玩家白名单机制,可以允许特定玩家绕过检查使用命令
This commit is contained in:
2 files changed
+28
-5
No files matched your search
@@ -14,6 +14,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandInterceptor {
|
||||
public static final org.slf4j.Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -24,12 +25,16 @@ public class CommandInterceptor {
|
||||
private static final int arg_PARAMETERS = 2;
|
||||
|
||||
// 从Mod配置获取黑名单列表
|
||||
private static List<List<String>> blackList = initblackList(new ArrayList<>(Config.BLOCKLIST.get()));
|
||||
private static List<List<String>> blackList = initblackList(new ArrayList<>(Config.BLACKLIST.get()));
|
||||
private static List<String> opUUID = Config.BLACKUUID.get().stream()
|
||||
.map(s -> s.toLowerCase(Locale.ROOT))
|
||||
.toList();
|
||||
|
||||
public static List<List<String>> initblackList(List<String> commands){
|
||||
List<List<String>> blackList = new ArrayList<List<String>>();
|
||||
for (String command: commands) {
|
||||
List<String> black = new ArrayList<>(Arrays.asList(command.split(CMDSEPARATOR)));
|
||||
if (black.size() < 1){
|
||||
if (black.isEmpty()){
|
||||
LOGGER.warn("{} 配置不可用, 长度错误", command);
|
||||
} else if (black.size() < 3){
|
||||
for (int i = 0; black.size() + i < 3; i++){
|
||||
@@ -45,6 +50,16 @@ public class CommandInterceptor {
|
||||
return blackList;
|
||||
}
|
||||
|
||||
public static boolean checkPlayer(CommandSourceStack source){
|
||||
// 不受约束返回true,否则返回false
|
||||
if (source.getEntity() instanceof ServerPlayer){
|
||||
if (opUUID.contains(source.getEntity().getStringUUID())){return true;}
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void checkCommand(CommandEvent event) {
|
||||
ParseResults<CommandSourceStack> parseResults = event.getParseResults();
|
||||
@@ -53,6 +68,9 @@ public class CommandInterceptor {
|
||||
// 获取执行指令的玩家
|
||||
CommandSourceStack source = parseResults.getContext().getSource();
|
||||
|
||||
// 检查不管理实例名单
|
||||
if(checkPlayer(source)){return;}
|
||||
|
||||
// 获取玩家输入的指令
|
||||
String raw = parseResults.getReader().getString();
|
||||
String[] parts = raw.trim().split("\\s+");
|
||||
|
||||
@@ -22,14 +22,19 @@ public class Config {
|
||||
.defineInRange("version", 1, 0, Integer.MAX_VALUE);
|
||||
|
||||
|
||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> BLOCKLIST = BUILDER
|
||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> BLACKLIST = BUILDER
|
||||
.comment("禁用的指令列表")
|
||||
.comment("格式为{cmd/指令}:{checkIndex/禁用第几个参数}:{arg1[,arg2,...]/禁用的参数1[,禁用的参数2,...]}")
|
||||
.comment("格式为{cmd}:{checkIndex}:{arg1[,arg2,...]}")
|
||||
.comment("格式为{指令}:{禁用第几个参数}:禁用的参数1[,禁用的参数2,...]}")
|
||||
.comment("其中{checkIndex}填0代表禁用整个指令")
|
||||
.defineList("blocked_commands", List.of("give:0:", "fill:0:", "gamemode:1:creative"), obj -> obj instanceof String);
|
||||
.defineList("bloaked_commands", List.of("give:0:", "fill:0:", "gamemode:1:creative"), obj -> obj instanceof String);
|
||||
|
||||
|
||||
|
||||
public static final ModConfigSpec.ConfigValue<List<? extends String>> BLACKUUID = BUILDER
|
||||
.comment("不受约束的玩家UUID列表")
|
||||
.defineList("blacked_players", List.of("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"), obj -> obj instanceof String);
|
||||
|
||||
|
||||
public static final ModConfigSpec.ConfigValue<String> BROADCASTMSG = BUILDER
|
||||
.comment("有人作弊时的广播内容")
|
||||
|
||||
Reference in new issue
Block a user