diff --git a/common/src/main/java/dev/rdh/createunlimited/CreateUnlimited.java b/common/src/main/java/dev/rdh/createunlimited/CreateUnlimited.java index abe9bb2..b9c1d3c 100755 --- a/common/src/main/java/dev/rdh/createunlimited/CreateUnlimited.java +++ b/common/src/main/java/dev/rdh/createunlimited/CreateUnlimited.java @@ -18,17 +18,17 @@ public class CreateUnlimited { public static final String ID = "createunlimited"; public static final String NAME = "Create Unlimited"; - public static final String VERSION = "0.4.1"; + public static final String VERSION = "0.5.0"; public static final Logger LOGGER = LoggerFactory.getLogger(NAME); public static void init() { - LOGGER.info("{} initializing! Create version: {} on platform: {}", NAME, Create.VERSION, Util.platformName()); + LOGGER.info("{} v{} initializing! Create version: {} on platform: {}", NAME, VERSION, Create.VERSION, Util.platformName()); + EnumArgument.init(); Util.registerConfig(ID, ModConfig.Type.SERVER, CUConfig.SPEC, "createunlimited.toml"); CUConfig.init(Util.getConfigDirectory().resolve("createunlimited-IGNOREME.toml")); CUCommands.registerConfigCommand(); - Util.registerArgument("enumargument", EnumArgument.class, new EnumArgument.Info(), asResource("enumargument")); } public static ResourceLocation asResource(String path) { diff --git a/common/src/main/java/dev/rdh/createunlimited/config/command/CUCommands.java b/common/src/main/java/dev/rdh/createunlimited/config/command/CUCommands.java index 7455f57..4787cc4 100644 --- a/common/src/main/java/dev/rdh/createunlimited/config/command/CUCommands.java +++ b/common/src/main/java/dev/rdh/createunlimited/config/command/CUCommands.java @@ -72,7 +72,8 @@ public static void registerConfigCommand() { return Command.SINGLE_SUCCESS; }); - LiteralArgumentBuilder category = null; + LiteralArgumentBuilder category = base; + for (Field field : CUConfig.class.getDeclaredFields()) { //skip if not config value or string if (!ForgeConfigSpec.ConfigValue.class.isAssignableFrom(field.getType()) && field.getType() != String.class) continue; @@ -83,6 +84,7 @@ public static void registerConfigCommand() { category = literal(field.getName()); //add description for category + assert base != null; base.then(literal(field.getName()).executes(context -> { message(CUConfig.comments.get(field.getName()), context); return Command.SINGLE_SUCCESS; @@ -90,8 +92,6 @@ public static void registerConfigCommand() { continue; } - if(category == null) - category = base; // if no category, append everything to base // get config as ConfigValue ForgeConfigSpec.ConfigValue value; @@ -109,15 +109,15 @@ public static void registerConfigCommand() { if (value instanceof ForgeConfigSpec.BooleanValue bValue) setBoolean(category, field, bValue); - // set for enums + // set for enums else if (value.get() instanceof Enum) setEnum(category, field, (ForgeConfigSpec.EnumValue>) value); - // set for int + // set for int else if (value instanceof ForgeConfigSpec.IntValue iValue) setInt(category, field, iValue); - // set for double + // set for double else if (value instanceof ForgeConfigSpec.DoubleValue dValue) setDouble(category, field, dValue); @@ -131,6 +131,9 @@ private static boolean perms(CommandSourceStack source) { return source.hasPermission(4) || !source.getLevel().getServer().isDedicatedServer(); } + private static boolean perms(Object o) { + return o instanceof CommandSourceStack source && perms(source); + } private static void gdr(LiteralArgumentBuilder category, Field field, ForgeConfigSpec.ConfigValue value) { category.then(literal(field.getName()) @@ -195,7 +198,7 @@ private static void setDouble(LiteralArgumentBuilder categor @SuppressWarnings("unchecked") private static > void setEnum(LiteralArgumentBuilder category, Field field, ForgeConfigSpec.EnumValue value) { category.then(literal(field.getName()) - .then(argument("value", EnumArgument.enumArg(value.get().getClass(), true)) + .then(argument("value", EnumArgument.enumArg(value.get().getClass(), true)).requires(CUCommands::perms) .executes(context -> { T set = (T) context.getArgument("value", value.get().getClass()); value.set(set); diff --git a/common/src/main/java/dev/rdh/createunlimited/config/command/EnumArgument.java b/common/src/main/java/dev/rdh/createunlimited/config/command/EnumArgument.java index cf4fbce..7712185 100644 --- a/common/src/main/java/dev/rdh/createunlimited/config/command/EnumArgument.java +++ b/common/src/main/java/dev/rdh/createunlimited/config/command/EnumArgument.java @@ -13,12 +13,18 @@ import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; + +import dev.rdh.createunlimited.CreateUnlimited; +import dev.rdh.createunlimited.util.Util; + import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.commands.synchronization.ArgumentTypeInfo; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; + import java.util.Arrays; import java.util.Collection; import java.util.concurrent.CompletableFuture; @@ -36,6 +42,10 @@ public class EnumArgument> implements ArgumentType { private final Class enumClass; private final boolean lowercase; + public static void init() { + Util.registerArgument("enumargument", EnumArgument.class, new EnumArgument.Info(), CreateUnlimited.asResource("enumargument")); + } + public static > EnumArgument enumArg(Class enumClass, boolean lowercase) { return new EnumArgument<>(enumClass, lowercase); } @@ -90,7 +100,7 @@ public void serializeToJson(Template template, JsonObject json) { } @Override - public Template unpack(EnumArgument argument) { + public @NotNull Template unpack(EnumArgument argument) { return new Template(argument.enumClass, argument.lowercase); } @@ -104,12 +114,12 @@ public class Template implements ArgumentTypeInfo.Template> { } @Override - public EnumArgument instantiate(CommandBuildContext ctx) { + public @NotNull EnumArgument instantiate(@NotNull CommandBuildContext ctx) { return new EnumArgument<>(this.enumClass, this.lowercase); } @Override - public ArgumentTypeInfo, ?> type() { + public @NotNull ArgumentTypeInfo, ?> type() { return Info.this; } } diff --git a/qodana.yaml b/qodana.yaml index 06e180d..9da56b2 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -18,7 +18,7 @@ profile: # paths: # - -projectJDK: zulu-17 #(Applied in CI/CD pipeline) +projectJDK: temurin-17 #(Applied in CI/CD pipeline) #Execute shell command before Qodana execution (Applied in CI/CD pipeline) #bootstrap: sh ./prepare-qodana.sh