mirror of
https://github.com/JonasunderscoreJones/BetterConsoleMC.git
synced 2025-10-24 14:19:19 +02:00
added config toggle for console command log
This commit is contained in:
parent
d7f982af05
commit
3ea416faea
2 changed files with 18 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ public class ModConfigs {
|
|||
public static SimpleConfig MODCONFIG;
|
||||
public static boolean IS_ENABLED;
|
||||
public static boolean REUQIRE_OP;
|
||||
public static boolean LOG_CMD_OUTPUT;
|
||||
private static ModConfigProvider modconfigs;
|
||||
|
||||
public static void registerConfigs() {
|
||||
|
|
@ -22,11 +23,13 @@ public class ModConfigs {
|
|||
modconfigs.addSingleLineComment("This is the config file for BetterConsoleMC");
|
||||
modconfigs.addKeyValuePair(new Pair<>("bettercmd.enable", true), "whether or not to the mod is enabled or not.");
|
||||
modconfigs.addKeyValuePair(new Pair<>("bettercmd.requireOp", true), "whether or not operator level is required in order to run commands.");
|
||||
modconfigs.addKeyValuePair(new Pair<>("bettercmd.logCmdOutput", false), "whether or not to log the output of commands to the console.");
|
||||
}
|
||||
|
||||
private static void assignConfigs() {
|
||||
IS_ENABLED = MODCONFIG.getOrDefault("cmd.enable", true);
|
||||
REUQIRE_OP = MODCONFIG.getOrDefault("cmd.requireOp", true);
|
||||
LOG_CMD_OUTPUT = MODCONFIG.getOrDefault("cmd.logCmdOutput", false);
|
||||
|
||||
SimpleConfig.LOGGER.info("All " + modconfigs.getConfigsList().size() + " have been set properly");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package me.jonasjones.betterconsolemc.system;
|
|||
import com.mojang.brigadier.context.CommandContext;
|
||||
import me.jonasjones.betterconsolemc.BetterConsoleMC;
|
||||
import me.jonasjones.betterconsolemc.command.GameCommandHandler;
|
||||
import me.jonasjones.betterconsolemc.modconfig.ModConfigs;
|
||||
import me.jonasjones.betterconsolemc.util.CommandPreRegistry;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
|
|
@ -11,7 +12,9 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
|
||||
public class ShellCommand {
|
||||
public static int execute(CommandPreRegistry command, CommandContext<ServerCommandSource> context) {
|
||||
public static String execute(CommandPreRegistry command, CommandContext<ServerCommandSource> context) {
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
if (BetterConsoleMC.ISWINDOWS) {
|
||||
|
|
@ -29,21 +32,25 @@ public class ShellCommand {
|
|||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
GameCommandHandler.returnCommandOutput(command.getCommand(), line, context);
|
||||
if (ModConfigs.LOG_CMD_OUTPUT) {
|
||||
GameCommandHandler.returnCommandOutput(command.getCommand(), line, context);
|
||||
}
|
||||
//get the ingame command name
|
||||
|
||||
|
||||
output.append("[").append(command.getIngamecommand()).append("]").append(line).append("\n");
|
||||
}
|
||||
|
||||
// Read buffered reader line by line and append to output with prefix of command before each line
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
BetterConsoleMC.LOGGER.info("Exited with error code : " + exitCode);
|
||||
} else {
|
||||
BetterConsoleMC.LOGGER.error("Exited with error code : " + exitCode);
|
||||
}
|
||||
BetterConsoleMC.LOGGER.info("Exited with error code : " + exitCode);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 1;
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue