Skip to content

Commit

Permalink
config command changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Jul 24, 2023
1 parent ad18129 commit 2f3f7f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

import net.minecraftforge.common.ForgeConfigSpec;

import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.List;

Expand Down Expand Up @@ -91,9 +89,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<CUConfig.PlacementCheck>) value);
// set for enums
else if (value.get() instanceof Enum<?>)
setEnum(category, field, (ForgeConfigSpec.EnumValue<? extends Enum<?>>) value);

// set for int
else if (value instanceof ForgeConfigSpec.IntValue iValue)
Expand Down Expand Up @@ -123,8 +121,8 @@ private static <T> void gdr(LiteralArgumentBuilder<CommandSourceStack> 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);
Expand Down Expand Up @@ -188,8 +186,6 @@ private static <T extends Enum<T>> void setEnum(LiteralArgumentBuilder<CommandSo
}))));
}



private static MutableComponent link(String link, String display, ChatFormatting color) {
return ComponentUtils.wrapInSquareBrackets(Component.nullToEmpty(display))
.withStyle(color)
Expand All @@ -202,7 +198,7 @@ private static MutableComponent link(String link, String display, ChatFormatting
private static void message(String message, CommandContext<CommandSourceStack> context) {
context.getSource().sendSuccess(() -> nullToEmpty(message), false);
}
private static void message(@NotNull String message, CommandContext<CommandSourceStack> context, ChatFormatting color) {
context.getSource().sendSuccess(() -> Component.literal(message).withStyle(color), false);
private static void error(String message, CommandContext<CommandSourceStack> context) {
context.getSource().sendFailure(nullToEmpty(message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
public static <R extends Enum<R>> EnumArgument<R> enumArg(Class<R> enumClass, boolean lowercase) {
return new EnumArgument<>(enumClass, lowercase);
}

private EnumArgument(final Class<T> enumClass, final boolean lowercase) {
this.enumClass = enumClass;
this.lowercase = lowercase;
Expand Down

0 comments on commit 2f3f7f4

Please sign in to comment.