Add a check for duplicate config command names and fix duplicate name

This commit is contained in:
s809
2025-01-18 16:26:33 +05:00
parent 82e0cfe0b4
commit 498e958eca
@@ -9,6 +9,7 @@ import com.seibel.distanthorizons.core.config.types.ConfigEntry;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
@@ -40,6 +41,7 @@ public class ConfigCommand extends AbstractCommand
public LiteralArgumentBuilder<CommandSourceStack> buildCommand() public LiteralArgumentBuilder<CommandSourceStack> buildCommand()
{ {
LiteralArgumentBuilder<CommandSourceStack> builder = literal("config"); LiteralArgumentBuilder<CommandSourceStack> builder = literal("config");
HashSet<String> addedCommands = new HashSet<>();
for (AbstractConfigType<?, ?> type : ConfigBase.INSTANCE.entries) for (AbstractConfigType<?, ?> type : ConfigBase.INSTANCE.entries)
{ {
@@ -56,6 +58,11 @@ public class ConfigCommand extends AbstractCommand
continue; continue;
} }
if (!addedCommands.add(configEntry.getChatCommandName()))
{
throw new IllegalStateException("Duplicate command name: " + configEntry.getChatCommandName());
}
LiteralArgumentBuilder<CommandSourceStack> subcommand = literal(configEntry.getChatCommandName()) LiteralArgumentBuilder<CommandSourceStack> subcommand = literal(configEntry.getChatCommandName())
.executes(commandContext -> this.sendSuccessResponse(commandContext, .executes(commandContext -> this.sendSuccessResponse(commandContext,
"\n" + "\n" +