Move commands under /dh, add /dh debug command
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.seibel.distanthorizons.common.commands;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
@@ -19,6 +20,9 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
*/
|
||||
public abstract class AbstractCommand
|
||||
{
|
||||
public abstract LiteralArgumentBuilder<CommandSourceStack> buildCommand();
|
||||
|
||||
|
||||
/**
|
||||
* Sends a success response to the player with the given text.
|
||||
*
|
||||
|
||||
+10
-2
@@ -1,9 +1,11 @@
|
||||
package com.seibel.distanthorizons.common.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import static com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_CODEC_CRASH_MESSAGE;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
/**
|
||||
* Initializes commands of the mod.
|
||||
@@ -29,12 +31,18 @@ public class CommandInitializer
|
||||
*/
|
||||
public void initCommands()
|
||||
{
|
||||
new DhConfigCommand().register(this.commandDispatcher);
|
||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("dh")
|
||||
.requires(source -> source.hasPermission(4));
|
||||
|
||||
builder.then(new ConfigCommand().buildCommand());
|
||||
builder.then(new DebugCommand().buildCommand());
|
||||
|
||||
if (DEBUG_CODEC_CRASH_MESSAGE)
|
||||
{
|
||||
new DhCrashCommand().register(this.commandDispatcher);
|
||||
builder.then(new CrashCommand().buildCommand());
|
||||
}
|
||||
|
||||
this.commandDispatcher.register(builder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-9
@@ -1,6 +1,5 @@
|
||||
package com.seibel.distanthorizons.common.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.*;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
@@ -24,7 +23,7 @@ import static net.minecraft.commands.Commands.literal;
|
||||
/**
|
||||
* Command for managing config.
|
||||
*/
|
||||
public class DhConfigCommand extends AbstractCommand
|
||||
public class ConfigCommand extends AbstractCommand
|
||||
{
|
||||
private static final List<CommandArgumentData<?>> commandArguments = Arrays.asList(
|
||||
new CommandArgumentData<>(Integer.class, configEntry -> integer(configEntry.getMin(), configEntry.getMax()), IntegerArgumentType::getInteger),
|
||||
@@ -34,15 +33,13 @@ public class DhConfigCommand extends AbstractCommand
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers the command with the given dispatcher.
|
||||
*
|
||||
* @param commandDispatcher the dispatcher to register the command with.
|
||||
* Builds a command tree.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public void register(CommandDispatcher<CommandSourceStack> commandDispatcher)
|
||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("dhconfig")
|
||||
.requires(source -> source.hasPermission(4));
|
||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("config");
|
||||
|
||||
for (AbstractConfigType<?, ?> type : ConfigBase.INSTANCE.entries)
|
||||
{
|
||||
@@ -105,7 +102,7 @@ public class DhConfigCommand extends AbstractCommand
|
||||
builder.then(subcommand);
|
||||
}
|
||||
|
||||
commandDispatcher.register(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -1,6 +1,5 @@
|
||||
package com.seibel.distanthorizons.common.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import com.seibel.distanthorizons.core.multiplayer.server.ServerPlayerState;
|
||||
@@ -9,12 +8,13 @@ import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class DhCrashCommand extends AbstractCommand
|
||||
public class CrashCommand extends AbstractCommand
|
||||
{
|
||||
public void register(CommandDispatcher<CommandSourceStack> commandDispatcher)
|
||||
@Override
|
||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> dhcrash = literal("dhcrash")
|
||||
.requires(source -> this.isPlayerSource(source) && source.hasPermission(4))
|
||||
return literal("crash")
|
||||
.requires(this::isPlayerSource)
|
||||
.then(literal("encode")
|
||||
.executes(c -> {
|
||||
assert SharedApi.getIDhServerWorld() != null;
|
||||
@@ -39,7 +39,6 @@ public class DhCrashCommand extends AbstractCommand
|
||||
}
|
||||
return 1;
|
||||
}));
|
||||
commandDispatcher.register(dhcrash);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.seibel.distanthorizons.common.commands;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class DebugCommand extends AbstractCommand
|
||||
{
|
||||
@Override
|
||||
public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
|
||||
{
|
||||
return literal("debug")
|
||||
.executes(c -> {
|
||||
List<String> lines = new ArrayList<>();
|
||||
F3Screen.addStringToDisplay(lines);
|
||||
return this.sendSuccessResponse(c, String.join("\n", lines));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user