Fix command test

This commit is contained in:
modmuss50 2020-06-04 21:32:45 +01:00
parent 346247d7d1
commit 1405d94241

View file

@ -32,7 +32,6 @@ import net.minecraft.text.LiteralText;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.server.ServerTickCallback; import net.fabricmc.fabric.api.event.server.ServerTickCallback;
import net.fabricmc.fabric.api.event.server.ServerStopCallback;
public class CommandTest implements ModInitializer { public class CommandTest implements ModInitializer {
private static final Logger LOGGER = LogManager.getLogger(CommandTest.class); private static final Logger LOGGER = LogManager.getLogger(CommandTest.class);
@ -40,17 +39,10 @@ public class CommandTest implements ModInitializer {
private static final SimpleCommandExceptionType WRONG_SIDE_SHOULD_BE_DEDICATED = new SimpleCommandExceptionType(new LiteralText("This command was registered incorrectly. Should only be present on an dedicated server but was ran on an integrated server!")); private static final SimpleCommandExceptionType WRONG_SIDE_SHOULD_BE_DEDICATED = new SimpleCommandExceptionType(new LiteralText("This command was registered incorrectly. Should only be present on an dedicated server but was ran on an integrated server!"));
private boolean hasTested = false; private boolean hasTested = false;
private boolean hasRegistered = false;
@Override @Override
public void onInitialize() { public void onInitialize() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
if (this.hasRegistered) {
throw new AssertionError("Commands should not be registered twice per server instance!");
}
this.hasRegistered = true;
// A command that exists on both types of servers // A command that exists on both types of servers
dispatcher.register(literal("fabric_common_test_command").executes(this::executeCommonCommand)); dispatcher.register(literal("fabric_common_test_command").executes(this::executeCommonCommand));
@ -109,11 +101,6 @@ public class CommandTest implements ModInitializer {
this.hasTested = true; this.hasTested = true;
CommandTest.LOGGER.info("The command tests have passed! Please make sure you execute the three commands for extra safety."); CommandTest.LOGGER.info("The command tests have passed! Please make sure you execute the three commands for extra safety.");
}); });
ServerStopCallback.EVENT.register(server -> {
// When the server shuts down, we reset the registered flag.
this.hasRegistered = false;
});
} }
private int executeCommonCommand(CommandContext<ServerCommandSource> context) { private int executeCommonCommand(CommandContext<ServerCommandSource> context) {