Introduced new execution system and nerfed command

commands will now be executed on the shell
the cmd command can now only do one thing: run commands. changing the settings is no longer possible as it could be a security risk.
This commit is contained in:
Jonas_Jones 2022-07-26 20:03:20 +02:00
parent 700ae1c75b
commit eb961b10a0
3 changed files with 2 additions and 91 deletions

View file

@ -5,62 +5,16 @@ import com.mojang.brigadier.context.CommandContext;
import me.jonasjones.consolemc.ConsoleMC;
import me.jonasjones.consolemc.system.ShellCommand;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.command.argument.MessageArgumentType;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static me.jonasjones.consolemc.ConsoleMC.registerCommands;
public class RunCommand {
public static void register(CommandDispatcher<ServerCommandSource> serverCommandSourceCommandDispatcher, CommandRegistryAccess commandRegistryAccess, CommandManager.RegistrationEnvironment registrationEnvironment) {
serverCommandSourceCommandDispatcher.register((((((((((CommandManager.literal("cmd").requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.literal("run")
.then(CommandManager.argument("Console Command", MessageArgumentType.message())
serverCommandSourceCommandDispatcher.register((CommandManager.literal("cmd").requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.argument("Console Command", MessageArgumentType.message())
.executes((context -> run(MessageArgumentType.getMessage(context, "Console Command").getString(), context)))))
//Debug Command
).then(CommandManager.literal("debug")
.then(CommandManager.literal("reloadCommand")
.executes(context -> reloadCommands(context))))
//reload Command
).then(CommandManager.literal("reload")
.executes(context -> reload(context)))
//allow-commandBlocks Command
).then(CommandManager.literal("allow-commandBlocks")
.then(CommandManager.literal("True")
.executes(context -> enableCmdBlocks(context))))
).then(CommandManager.literal("allow-commandBlocks")
.then(CommandManager.literal("False")
.executes(context -> disableCmdBlocks(context))))
//enable command
).then(CommandManager.literal("enable")
.executes(context -> enable(context)))
//disable command
).then(CommandManager.literal("disable")
.executes(context -> disable(context)))
//help command
).then(CommandManager.literal("help")
.executes(context -> help()))
//blacklist [add/remove]
).then(CommandManager.literal("blacklist")
.then(CommandManager.literal("add")
.then(CommandManager.argument("target", EntityArgumentType.players())
.executes(context -> blacklistAdd(EntityArgumentType.getPlayer(context, "Player"), context)))))
).then(CommandManager.literal("blacklist")
.then(CommandManager.literal("remove")
.then(CommandManager.argument("targets", EntityArgumentType.players())
.executes(context -> blacklistRemove(EntityArgumentType.getPlayer(context, "Player"), context)))))
);
}
public static void broadcastToOP(String message, CommandContext<ServerCommandSource> context) {
@ -84,47 +38,4 @@ public class RunCommand {
broadcastToOP(consoleLog, context);
ConsoleMC.LOGGER.info(consoleLog);
}
public static int enableCmdBlocks(CommandContext<ServerCommandSource> context) {
broadcastToOP("Enabled ConsoleMC in Commandblocks", context);
return 1;
}
public static int disableCmdBlocks(CommandContext<ServerCommandSource> context) {
broadcastToOP("Disabled ConsoleMC in Commandblocks", context);
return 1;
}
public static int blacklistAdd(ServerPlayerEntity player, CommandContext<ServerCommandSource> context) {
broadcastToOP("Added " + player.toString() + " to the ConsoleMC blacklist", context);
return 1;
}
public static int blacklistRemove(ServerPlayerEntity player, CommandContext<ServerCommandSource> context) {
broadcastToOP("Removed " + player.toString() + " from the ConsoleMC blacklist", context);
return 1;
}
public static int reloadCommands(CommandContext<ServerCommandSource> context) {
registerCommands();
broadcastToOP("DEBUG Reregistered /cmd command", context);
return 1;
}
public static int help() {
ConsoleMC.LOGGER.info("Print help");
return 1;
}
public static int reload(CommandContext<ServerCommandSource> context) {
broadcastToOP("Reloaded ConsoleMC Config", context);
return 1;
}
public static int enable(CommandContext<ServerCommandSource> context) {
broadcastToOP("Enabled ConsoleMC commands", context);
return 1;
}
public static int disable(CommandContext<ServerCommandSource> context) {
broadcastToOP("Disabled ConsoleMC commands", context);
return 1;
}
}