diff --git a/common/src/main/java/dev/rdh/createunlimited/command/CreateUnlimitedCommands.java b/common/src/main/java/dev/rdh/createunlimited/command/CreateUnlimitedCommands.java index 3a46063..293b098 100644 --- a/common/src/main/java/dev/rdh/createunlimited/command/CreateUnlimitedCommands.java +++ b/common/src/main/java/dev/rdh/createunlimited/command/CreateUnlimitedCommands.java @@ -1,6 +1,7 @@ package dev.rdh.createunlimited.command; import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -29,7 +30,9 @@ import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; +import java.util.HashMap; import java.util.List; +import java.util.function.Supplier; import static net.minecraft.commands.Commands.argument; import static net.minecraft.commands.Commands.literal; @@ -111,9 +114,9 @@ public static void registerConfigCommand() { if (value instanceof ForgeConfigSpec.BooleanValue bValue) setBoolean(category, field, bValue); - // set for PlacmentCheck enum - else if (value.get() instanceof CUConfig.PlacementCheck) - setEnum(category, field, (ForgeConfigSpec.EnumValue) value); + // set for enums + else if (value.get() instanceof Enum) + setEnum(category, field, (ForgeConfigSpec.EnumValue>) value); // set for int else if (value instanceof ForgeConfigSpec.IntValue iValue) @@ -143,8 +146,8 @@ private static void gdr(LiteralArgumentBuilder category, .then(literal("reset").requires(CreateUnlimitedCommands::perms) .executes(context -> { if(value.get().equals(value.getDefault())) { - message("Value is already default!", context, ChatFormatting.RED); - return Command.SINGLE_SUCCESS; + error("Value is already default!", context); + return 0; } value.set(value.getDefault()); message(field.getName() + " reset to: " + value.get(), context); @@ -208,8 +211,6 @@ private static > void setEnum(LiteralArgumentBuilder context) { context.getSource().sendSuccess(nullToEmpty(message), false); } - private static void message(@NotNull String message, CommandContext context, ChatFormatting color) { - context.getSource().sendSuccess(Component.literal(message).withStyle(color), false); + private static void error(String message, CommandContext context) { + context.getSource().sendFailure(nullToEmpty(message)); } } diff --git a/common/src/main/java/dev/rdh/createunlimited/command/EnumArgument.java b/common/src/main/java/dev/rdh/createunlimited/command/EnumArgument.java index d556f1f..c759812 100644 --- a/common/src/main/java/dev/rdh/createunlimited/command/EnumArgument.java +++ b/common/src/main/java/dev/rdh/createunlimited/command/EnumArgument.java @@ -39,6 +39,7 @@ public class EnumArgument> implements ArgumentType { public static > EnumArgument enumArg(Class enumClass, boolean lowercase) { return new EnumArgument<>(enumClass, lowercase); } + private EnumArgument(final Class enumClass, final boolean lowercase) { this.enumClass = enumClass; this.lowercase = lowercase;