From d1d6c484b35d964c418fd89d758c2e4f2c83bf85 Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Wed, 13 Nov 2024 23:30:52 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fixed=20list=20config=20v?= =?UTF-8?q?alues=20to=20have=20proper=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../tile/ApothecaryCauldronBlockEntity.java | 5 +- .../entities/shot/ShotEntityBase.java | 7 +- .../reliquary/items/MidasTouchstoneItem.java | 15 +--- .../java/reliquary/reference/Settings.java | 75 +++++++++--------- .../textures/item/fortune_coin - Copy.png | Bin 9040 -> 0 bytes 6 files changed, 45 insertions(+), 59 deletions(-) delete mode 100644 src/main/resources/assets/reliquary/textures/item/fortune_coin - Copy.png diff --git a/gradle.properties b/gradle.properties index b2456861..b68bed0b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=reliquary mod_group_id=reliquary -mod_version=2.0.44 +mod_version=2.0.45 sonar_project_key=xreliquary:Reliquary github_package_url=https://maven.pkg.github.com/P3pp3rF1y/Reliquary diff --git a/src/main/java/reliquary/blocks/tile/ApothecaryCauldronBlockEntity.java b/src/main/java/reliquary/blocks/tile/ApothecaryCauldronBlockEntity.java index 474c56bb..c4df5505 100644 --- a/src/main/java/reliquary/blocks/tile/ApothecaryCauldronBlockEntity.java +++ b/src/main/java/reliquary/blocks/tile/ApothecaryCauldronBlockEntity.java @@ -302,9 +302,8 @@ private int getRedstoneAmpLimit() { private Set getHeatSources() { Set heatSources = new HashSet<>(); - List heatSourceBlockNames = Settings.COMMON.blocks.apothecaryCauldron.heatSources.get(); - - heatSourceBlockNames.forEach(blockName -> heatSources.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)))); + Settings.COMMON.blocks.apothecaryCauldron.heatSources.get() + .forEach(blockName -> heatSources.add(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)))); //defaults that can't be removed. heatSources.add(Blocks.LAVA); heatSources.add(Blocks.FIRE); diff --git a/src/main/java/reliquary/entities/shot/ShotEntityBase.java b/src/main/java/reliquary/entities/shot/ShotEntityBase.java index 2565c664..9d80f300 100644 --- a/src/main/java/reliquary/entities/shot/ShotEntityBase.java +++ b/src/main/java/reliquary/entities/shot/ShotEntityBase.java @@ -37,10 +37,7 @@ import reliquary.util.potions.XRPotionHelper; import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; +import java.util.*; @SuppressWarnings("squid:S2160") public abstract class ShotEntityBase extends Projectile { @@ -393,7 +390,7 @@ private void ricochet(Direction sideHit) { */ void seekTarget() { Entity closestTarget = null; - List huntableEntitiesBlacklist = Settings.COMMON.items.seekerShot.huntableEntitiesBlacklist.get(); + Set huntableEntitiesBlacklist = new HashSet<>(Settings.COMMON.items.seekerShot.huntableEntitiesBlacklist.get()); List targetsList = level().getEntities(this, new AABB(getX() - 5, getY() - 5, getZ() - 5, getX() + 5, getY() + 5, getZ() + 5), Mob.class::isInstance); diff --git a/src/main/java/reliquary/items/MidasTouchstoneItem.java b/src/main/java/reliquary/items/MidasTouchstoneItem.java index c378ec49..5949f9fe 100644 --- a/src/main/java/reliquary/items/MidasTouchstoneItem.java +++ b/src/main/java/reliquary/items/MidasTouchstoneItem.java @@ -3,16 +3,7 @@ import com.google.common.collect.ImmutableMap; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.ArmorMaterials; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.Rarity; -import net.minecraft.world.item.Tier; -import net.minecraft.world.item.TieredItem; -import net.minecraft.world.item.Tiers; +import net.minecraft.world.item.*; import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -81,8 +72,6 @@ public void inventoryTick(ItemStack stack, Level world, Entity e, int i, boolean } private void doRepairAndDamageTouchstone(ItemStack touchstone, Player player) { - List goldItems = Settings.COMMON.items.midasTouchstone.goldItems.get(); - InventoryHelper.getItemHandlerFrom(player, null).ifPresent(itemHandler -> { for (int slot = 0; slot < itemHandler.getSlots(); slot++) { ItemStack stack = itemHandler.getStackInSlot(slot); @@ -92,7 +81,7 @@ private void doRepairAndDamageTouchstone(ItemStack touchstone, Player player) { continue; } - tryRepairingItem(touchstone, player, goldItems, stack, item); + tryRepairingItem(touchstone, player, Settings.COMMON.items.midasTouchstone.getGoldItems(), stack, item); } }); } diff --git a/src/main/java/reliquary/reference/Settings.java b/src/main/java/reliquary/reference/Settings.java index c645babb..8f291af3 100644 --- a/src/main/java/reliquary/reference/Settings.java +++ b/src/main/java/reliquary/reference/Settings.java @@ -6,32 +6,26 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.item.Items; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; -import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; -import net.minecraftforge.common.ForgeConfigSpec.DoubleValue; -import net.minecraftforge.common.ForgeConfigSpec.EnumValue; -import net.minecraftforge.common.ForgeConfigSpec.IntValue; +import net.minecraftforge.common.ForgeConfigSpec.*; import net.minecraftforge.fml.event.config.ModConfigEvent; import net.minecraftforge.registries.ForgeRegistries; import org.apache.commons.lang3.tuple.Pair; import reliquary.client.gui.hud.HUDPosition; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.*; +import java.util.function.Predicate; +import java.util.regex.Pattern; import static reliquary.util.RegistryHelper.getItemRegistryName; -@SuppressWarnings("squid:S1192") //no issue repeating the same string literal as they are independent +@SuppressWarnings({"java:S4968", "squid:S1192"}) // ? extends String is the type parameter returned from defineList so it can't be just String here | no issue repeating the same string literal as they are independent public class Settings { private Settings() {} private static final int ITEM_CAP = 9999; + private static final Pattern REGISTRY_NAME_PATTERN = Pattern.compile("([a-z0-9_.-]+:[a-z0-9_/.-]+)"); + private static final Predicate REGISTRY_NAME_MATCHER = o -> o instanceof String s && REGISTRY_NAME_PATTERN.matcher(s).matches(); @SuppressWarnings("unused") // parameter needs to stay for addListener logic to recognize what this method is listening to public static void onFileChange(ModConfigEvent.Reloading configEvent) { @@ -354,7 +348,7 @@ public static class AngelHeartVialSettings { public final DestructionCatalystSettings destructionCatalyst; public static class DestructionCatalystSettings { - public final ConfigValue> mundaneBlocks; + public final ConfigValue> mundaneBlocks; public final IntValue gunpowderCost; public final IntValue gunpowderWorth; public final IntValue gunpowderLimit; @@ -367,7 +361,7 @@ public static class DestructionCatalystSettings { mundaneBlocks = builder .comment("List of mundane blocks the catalyst will break") - .define("mundaneBlocks", Lists.newArrayList( + .defineList("mundaneBlocks", Lists.newArrayList( "minecraft:dirt", "minecraft:coarse_dirt", "minecraft:podzol", @@ -384,7 +378,7 @@ public static class DestructionCatalystSettings { "minecraft:snow", "minecraft:soul_sand", "minecraft:netherrack", - "minecraft:end_stone")); + "minecraft:end_stone"), REGISTRY_NAME_MATCHER); gunpowderCost = builder .comment("Number of gunpowder it costs per catalyst use") @@ -714,7 +708,6 @@ public static class InfernalClawsSettings { public static class InfernalTearSettings { private static final String ITEM_EXPERIENCE_MATCHER = "([a-z1-9_.-]+:[a-z1-9_/.-]+)\\|\\d+"; public final BooleanValue absorbWhenCreated; - @SuppressWarnings("java:S4968") // ? extends String is the type parameter returned from defineList so it can't be just String here public final ForgeConfigSpec.ConfigValue> itemExperienceList; @Nullable private Map itemExperience = null; @@ -794,7 +787,7 @@ public static class KrakenShellSettings { public final LanternOfParanoiaSettings lanternOfParanoia; public static class LanternOfParanoiaSettings { - public final ConfigValue> torches; + public final ConfigValue> torches; public final IntValue minLightLevel; public final IntValue placementScanRadius; @@ -803,7 +796,7 @@ public static class LanternOfParanoiaSettings { torches = builder .comment("List of torches that are supported by the lantern") - .define("torches", Lists.newArrayList(getItemRegistryName(Items.TORCH))); + .defineList("torches", Lists.newArrayList(getItemRegistryName(Items.TORCH)), REGISTRY_NAME_MATCHER); minLightLevel = builder .comment("Minimum light level below which the lantern will place torches") .defineInRange("minLightLevel", 1, 0, 15); @@ -819,7 +812,7 @@ public static class LanternOfParanoiaSettings { public final MidasTouchstoneSettings midasTouchstone; public static class MidasTouchstoneSettings { - public final ConfigValue> goldItems; + public final ConfigValue> goldItems; public final IntValue glowstoneCost; public final IntValue glowstoneWorth; public final IntValue glowstoneLimit; @@ -829,7 +822,7 @@ public static class MidasTouchstoneSettings { goldItems = builder .comment("Gold items that can be repaired by the touchstone") - .define("goldItems", new ArrayList<>()); + .defineListAllowEmpty("goldItems", new ArrayList<>(), REGISTRY_NAME_MATCHER); glowstoneCost = builder .comment("Number of glowstone that the repair costs") @@ -845,6 +838,10 @@ public static class MidasTouchstoneSettings { builder.pop(); } + + public List getGoldItems() { + return getStringList(goldItems.get()); + } } public final MobCharmSettings mobCharm; @@ -1015,8 +1012,8 @@ public static class RendingGaleSettings { public final BooleanValue canPushProjectiles; public final IntValue pedestalFlightRange; public final IntValue pedestalCostPerSecond; - public final ConfigValue> pushableEntitiesBlacklist; - public final ConfigValue> pushableProjectilesBlacklist; + public final ConfigValue> pushableEntitiesBlacklist; + public final ConfigValue> pushableProjectilesBlacklist; RendingGaleSettings(ForgeConfigSpec.Builder builder) { builder.comment("Rending Gale settings").push("rendingGale"); @@ -1059,11 +1056,11 @@ public static class RendingGaleSettings { pushableEntitiesBlacklist = builder .comment("List of entities that are banned from being pushed by the Rending Gale") - .define("pushableEntitiesBlacklist", new ArrayList<>()); + .defineListAllowEmpty("pushableEntitiesBlacklist", new ArrayList<>(), REGISTRY_NAME_MATCHER); pushableProjectilesBlacklist = builder .comment("List of projectiles that are banned from being pushed by the Rending Gale") - .define("pushableProjectilesBlacklist", new ArrayList<>()); + .defineListAllowEmpty("pushableProjectilesBlacklist", new ArrayList<>(), REGISTRY_NAME_MATCHER); builder.pop(); } @@ -1079,7 +1076,6 @@ public static class RodOfLyssaSettings { public final BooleanValue failStealFromVacantSlots; public final BooleanValue angerOnStealFailure; public final BooleanValue stealFromPlayers; - private static final String ENTITY_NAME_MATCHER = "[a-z1-9_.-]+:[a-z1-9_/.-]+"; @SuppressWarnings("java:S4968") // ? extends String is the type parameter returned from defineList so it can't be just String here public final ForgeConfigSpec.ConfigValue> entityBlockList; @Nullable @@ -1117,7 +1113,7 @@ public static class RodOfLyssaSettings { .define("stealFromPlayers", true); entityBlockList = builder.comment("List of entities on which lyssa rod doesn't work - full registry name is required here") - .defineList("entityBlockList", new ArrayList<>(), mapping -> ((String) mapping).matches(ENTITY_NAME_MATCHER)); + .defineListAllowEmpty("entityBlockList", new ArrayList<>(), REGISTRY_NAME_MATCHER); builder.pop(); } @@ -1142,14 +1138,14 @@ private void initBlockedEntityTypes() { public final SeekerShotSettings seekerShot; public static class SeekerShotSettings { - public final ConfigValue> huntableEntitiesBlacklist; + public final ConfigValue> huntableEntitiesBlacklist; SeekerShotSettings(ForgeConfigSpec.Builder builder) { builder.comment("Seeker Shot settings").push("seekerShot"); huntableEntitiesBlacklist = builder .comment("Entities that are banned from being tracked by seeker shot") - .define("huntableEntitiesBlacklist", new ArrayList<>()); + .defineListAllowEmpty("huntableEntitiesBlacklist", new ArrayList<>(), REGISTRY_NAME_MATCHER); builder.pop(); } @@ -1158,7 +1154,7 @@ public static class SeekerShotSettings { public final SojournerStaffSettings sojournerStaff; public static class SojournerStaffSettings { - public final ConfigValue> torches; + public final ConfigValue> torches; public final IntValue maxCapacityPerItemType; public final IntValue maxRange; public final IntValue tilePerCostMultiplier; @@ -1168,7 +1164,7 @@ public static class SojournerStaffSettings { torches = builder .comment("List of torches that are supported by the staff") - .define("torches", getDefaultTorches()); + .defineList("torches", getDefaultTorches(), REGISTRY_NAME_MATCHER); maxCapacityPerItemType = builder .comment("Number of items the staff can store per item type") @@ -1286,7 +1282,7 @@ public static class AltarSettings { public static class ApothecaryCauldronSettings { public final IntValue redstoneLimit; public final IntValue cookTime; - public final ConfigValue> heatSources; + public final ConfigValue> heatSources; public final IntValue glowstoneLimit; ApothecaryCauldronSettings(ForgeConfigSpec.Builder builder) { @@ -1302,7 +1298,7 @@ public static class ApothecaryCauldronSettings { heatSources = builder .comment("List of acceptable heat sources") - .define("heatSources", new ArrayList<>()); + .defineListAllowEmpty("heatSources", new ArrayList<>(), REGISTRY_NAME_MATCHER); glowstoneLimit = builder .comment("Limit of glowstone that can be used in cauldron to make POTION more potent") @@ -1343,8 +1339,8 @@ public static class FertileLilypadSettings { public static class InterdictionTorchSettings { public final IntValue pushRadius; public final BooleanValue canPushProjectiles; - public final ConfigValue> pushableEntitiesBlacklist; - public final ConfigValue> pushableProjectilesBlacklist; + public final ConfigValue> pushableEntitiesBlacklist; + public final ConfigValue> pushableProjectilesBlacklist; InterdictionTorchSettings(ForgeConfigSpec.Builder builder) { builder.comment("Interdiction Torch settings").push("interdictionTorch"); @@ -1359,11 +1355,11 @@ public static class InterdictionTorchSettings { pushableEntitiesBlacklist = builder .comment("List of entities that are banned from being pushed by the torch") - .define("pushableEntitiesBlacklist", new ArrayList<>()); + .defineListAllowEmpty("pushableEntitiesBlacklist", new ArrayList<>(), REGISTRY_NAME_MATCHER); pushableProjectilesBlacklist = builder .comment("List of projectiles that are banned from being pushed by the torch") - .define("pushableProjectilesBlacklist", new ArrayList<>()); + .defineListAllowEmpty("pushableProjectilesBlacklist", new ArrayList<>(), REGISTRY_NAME_MATCHER); builder.pop(); } @@ -1435,4 +1431,9 @@ public static class PedestalSettings { COMMON_SPEC = specPair.getRight(); COMMON = specPair.getLeft(); } + + @SuppressWarnings("unchecked") + private static List getStringList(List list) { + return (List) list; + } } diff --git a/src/main/resources/assets/reliquary/textures/item/fortune_coin - Copy.png b/src/main/resources/assets/reliquary/textures/item/fortune_coin - Copy.png deleted file mode 100644 index 55a94573042e019a9c58042d2a422621c7e7bc9c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9040 zcmcIq4UnBzS-z=g=^tX1jut4l7t3FJ_MZQrJKb(~vssdqjUm~R1c%!5n_RoQce(c_ z*_P={OBs-&%wRj?P(aX9!BJ6*R-)2^{Im|Eok9spG9%6~pp>>Cc95y0KHvT|k=^7g zN;bQD_xsNGo^#&wzR&Z#@4fHbx#P7LoO|)PjYi{wZCfXI;r9!x@8|yve!lE`&v^Vg zXJPBUL8Ecr&sX1@8h5?_7aNUBo86hc!@bk5>%`vNh)=zcM;7N6FuKvWa%^$I#~bpn z8S?(_{AlaRzj>h5?55Gy9yLv;7dGbu-K{tE^X{8=%*2~+h%U9pu4-Pn*nxq$JoL@Q zx!L(aXK}Q(WVeIY)#Y}pxin;W!)R-~ny|TddS`QUub-P{gpo)oZ5lU{ljlK{E1H~g z)@JxG3F93>JCZk7{)-Z0FfLm*7wc+cUots-5Js55|gcYsqZQap> znHv{!dsiOx4)$Z-atJfNe05=i;ja9wYic}>;cE{s9Ow;ug9E({oUnHL6juzpWrGQ; zJEsiIi`@-|R(IBhE_62cvmf^QGrivIYVhn_U0aij5!QUwp6-0=9Ui>8+W5)?dD0K_ zXbXYF31x(f8D=`lbvV16vJR!oL#Gj&$q)U>gE?Us%sWbUxI1NVFLld}XB?Vhr}X-B z9tYQ*^ZRpqVSfM8Y}3=7ZS#YnpO1OlP6UCJB1evKw_Ax7Kv-L%^n$OO=xi{PEPxlghj_cKFcVHe% z^;Le2w%E$Wy;Z2r9$da?I1-<>S@m<}{=PHZfA;pZ^If=@x0+SFbe87d4eY`Kv{C{t zTe`lpyO?M9PIlq7!SX`%$#?dhdZ&W2DnmP4y931BjVoBQJHL75)oi!9l$0GGm$wkB z=*+3La=E+C0oQZovf0B2GMsgqs9hd5=#}AN-_PUw;o&o8MSG*g5B#CiFWu{4s9+8V zttD|*8scOrh*F0L@Z7L~1K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