diff --git a/gradle.properties b/gradle.properties index 4cef17b..96684ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.daemon=false mod_id=xp_tools mod_name=XP Tools mod_license=All Rights Reserved -mod_version=1.0.1 +mod_version=1.0.2 mod_group_id=dev.micle mod_authors=Micle mod_description=Minecraft Forge mod for tweaking various things about XP in Minecraft. Primarily targeted at modpack developers. diff --git a/src/main/java/dev/micle/xptools/config/Config.java b/src/main/java/dev/micle/xptools/config/Config.java index 75d9dc3..4691154 100644 --- a/src/main/java/dev/micle/xptools/config/Config.java +++ b/src/main/java/dev/micle/xptools/config/Config.java @@ -13,6 +13,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent; import org.apache.commons.lang3.tuple.Pair; import java.util.*; +import java.util.stream.Collectors; @Mod.EventBusSubscriber(modid = XpTools.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public final class Config { @@ -104,13 +105,13 @@ public final class Config { .comment("Global operations are run before any unique operations.") .comment("Examples:") .comment("'set,0,0,0' - Sets the xp of all blocks to 0.") - .define("blockBreakGlobalOperations", new ArrayList<>()); + .defineList("blockBreakGlobalOperations", List.of(), Server::isValidGlobalOperationEntry); blockBreakOperationsRaw = builder .comment("List of unique operations. Format: '[block_id/tag_id],[operation],[min],[max],[priority],[is_last]'") .comment("Examples:") .comment("'minecraft:dirt,set,2,2,0,true' - Sets the xp drop of the dirt block to 2, takes highest priority and stops any additional operations.") .comment("'#forge:ores,multiply,1,2,1,false' - Multiplies xp drop of all blocks tagged forge:ores by 1-2, allows additional operations.") - .define("blockBreakOperations", new ArrayList<>()); + .defineList("blockBreakOperations", List.of(), Server::isValidOperationEntry); builder.pop(); builder.comment("Settings for entity killing").push("entity_killing"); @@ -120,13 +121,13 @@ public final class Config { .comment("Global operations are run before any unique operations.") .comment("Examples:") .comment("'set,0,0,0' - Sets the xp of all entities to 0.") - .define("entityKillGlobalOperations", new ArrayList<>()); + .defineList("entityKillGlobalOperations", List.of(), Server::isValidGlobalOperationEntry); entityKillOperationsRaw = builder .comment("List of unique operations. Format: '[entity_id/tag_id],[operation],[min],[max],[priority],[is_last]'") .comment("Examples:") .comment("'minecraft:creeper,set,2,2,0,true' - Sets the xp drop for killing creepers to 2, takes highest priority and stops any additional operations.") .comment("'#some_mod:some_tag,multiply,1,2,1,false' - Multiplies the xp drop for killing all entities tagged some_mod:some_tag by 1-2, allows additional operations.") - .define("entityKillOperations", new ArrayList<>()); + .defineList("entityKillOperations", List.of(), Server::isValidOperationEntry); builder.pop(); } @@ -161,5 +162,23 @@ public final class Config { entityKillOperationItems.add(OperationItem.fromConfig(s)); } } + + private static boolean isValidGlobalOperationEntry(Object entry) { + return entry instanceof String && ((String) entry).matches( + String.format( + "(?i)^(%s),(\\d*\\.?\\d+),(\\d*\\.?\\d+),(\\d+)$", + Arrays.stream(OperationType.values()).map(OperationType::toString).collect(Collectors.joining("|")) + ) + ); + } + + private static boolean isValidOperationEntry(Object entry) { + return entry instanceof String && ((String) entry).matches( + String.format( + "(?i)^(\\#?\\w+:[\\w\\/]+),(%s),(\\d*\\.?\\d+),(\\d*\\.?\\d+),(\\d+),(TRUE|FALSE)$", + Arrays.stream(OperationType.values()).map(OperationType::toString).collect(Collectors.joining("|")) + ) + ); + } } }