diff --git a/bukkit/loader/src/main/resources/translations/en.yml b/bukkit/loader/src/main/resources/translations/en.yml index f0e1f0abc..9d4598db1 100644 --- a/bukkit/loader/src/main/resources/translations/en.yml +++ b/bukkit/loader/src/main/resources/translations/en.yml @@ -85,6 +85,8 @@ warning.config.furniture.duplicated: "Issue found in file - Dupl warning.config.furniture.lack_placement: "Issue found in file - The furniture '' is missing the required 'placement' argument." warning.config.furniture.element.lack_item: "Issue found in file - The furniture '' is missing the required 'item' argument for one of its elements." warning.config.furniture.settings.unknown: "Issue found in file - The furniture '' is using an unknown setting type ''." +warning.config.furniture.hitbox.invalid_type: "Issue found in file - The furniture '' is using an invalid hitbox type ''." +warning.config.furniture.hitbox.custom.invalid_entity: "Issue found in file - The furniture '' is using a custom hitbox with invalid entity type ''." warning.config.item.duplicated: "Issue found in file - Duplicated item ''." warning.config.item.lack_material: "Issue found in file - The item '' is missing the required 'material' argument." warning.config.item.invalid_material: "Issue found in file - The item '' is using an invalid material type ''." diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/advancement/BukkitAdvancementManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/advancement/BukkitAdvancementManager.java index 29035442a..13633211e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/advancement/BukkitAdvancementManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/advancement/BukkitAdvancementManager.java @@ -7,8 +7,7 @@ import net.momirealms.craftengine.core.advancement.AbstractAdvancementManager; import net.momirealms.craftengine.core.pack.LoadingSequence; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.plugin.locale.TranslationManager; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.util.GsonHelper; import net.momirealms.craftengine.core.util.Key; @@ -52,7 +51,7 @@ public class BukkitAdvancementManager extends AbstractAdvancementManager { @Override public void parseSection(Pack pack, Path path, Key id, Map section) { if (advancements.containsKey(id)) { - throw new LocalizedException("warning.config.advancement.duplicated", path.toString(), id.toString()); + throw new LocalizedResourceConfigException("warning.config.advancement.duplicated", path, id); } JsonElement jsonTree = GsonHelper.get().toJsonTree(section); FastNMS.INSTANCE.registerAdvancement(id.decompose(), jsonTree); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java index bcfd7fb99..753a37a89 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/BukkitFurnitureManager.java @@ -12,8 +12,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.plugin.locale.TranslationManager; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.sound.SoundData; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; @@ -107,14 +106,14 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager { @Override public void parseSection(Pack pack, Path path, Key id, Map section) { if (byId.containsKey(id)) { - throw new LocalizedException("warning.config.furniture.duplicated", path.toString(), id.toString()); + throw new LocalizedResourceConfigException("warning.config.furniture.duplicated", path, id); } Map lootMap = MiscUtils.castToMap(section.get("loot"), true); Map settingsMap = MiscUtils.castToMap(section.get("settings"), true); Map placementMap = MiscUtils.castToMap(section.get("placement"), true); if (placementMap == null) { - throw new LocalizedException("warning.config.furniture.lack_placement", path.toString(), id.toString()); + throw new LocalizedResourceConfigException("warning.config.furniture.lack_placement", path, id); } EnumMap placements = new EnumMap<>(AnchorType.class); @@ -130,7 +129,7 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager { for (Map element : elementConfigs) { String key = (String) element.get("item"); if (key == null) { - throw new LocalizedException("warning.config.furniture.element.lack_item", path.toString(), id.toString()); + throw new LocalizedResourceConfigException("warning.config.furniture.element.lack_item", path, id); } ItemDisplayContext transform = ItemDisplayContext.valueOf(element.getOrDefault("transform", "NONE").toString().toUpperCase(Locale.ENGLISH)); Billboard billboard = Billboard.valueOf(element.getOrDefault("billboard", "FIXED").toString().toUpperCase(Locale.ENGLISH)); @@ -157,8 +156,14 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager { List> hitboxConfigs = (List>) placementArguments.getOrDefault("hitboxes", List.of()); List hitboxes = new ArrayList<>(); for (Map config : hitboxConfigs) { - HitBox hitBox = HitBoxTypes.fromMap(config); - hitboxes.add(hitBox); + try { + HitBox hitBox = HitBoxTypes.fromMap(config); + hitboxes.add(hitBox); + } catch (LocalizedResourceConfigException e) { + e.setPath(path); + e.setId(id); + throw e; + } } if (hitboxes.isEmpty() && externalModel.isEmpty()) { hitboxes.add(InteractionHitBox.DEFAULT); @@ -195,9 +200,9 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager { FurnitureSettings settings; try { settings = FurnitureSettings.fromMap(settingsMap); - } catch (LocalizedException e) { - e.setArgument(0, path.toString()); - e.setArgument(1, id.toString()); + } catch (LocalizedResourceConfigException e) { + e.setPath(path); + e.setId(id); throw e; } CustomFurniture furniture = new CustomFurniture(id, settings, placements, lootMap == null ? null : LootTable.fromMap(lootMap)); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java index 9b00dc4fc..62ab6f9e6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/entity/furniture/hitbox/CustomHitBox.java @@ -4,6 +4,7 @@ import net.momirealms.craftengine.bukkit.entity.data.BaseEntityData; import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.core.entity.furniture.*; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.VersionHelper; @@ -82,9 +83,10 @@ public class CustomHitBox extends AbstractHitBox { public HitBox create(Map arguments) { Vector3f position = MiscUtils.getVector3f(arguments.getOrDefault("position", "0")); float scale = MiscUtils.getAsFloat(arguments.getOrDefault("scale", "1")); - EntityType entityType = Registry.ENTITY_TYPE.get(new NamespacedKey("minecraft", (String) arguments.getOrDefault("entity-type", "slime"))); + String type = (String) arguments.getOrDefault("entity-type", "slime"); + EntityType entityType = Registry.ENTITY_TYPE.get(new NamespacedKey("minecraft", type)); if (entityType == null) { - throw new IllegalArgumentException("EntityType not found: " + arguments.get("entity-type")); + throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.custom.invalid_entity", new IllegalArgumentException("EntityType not found: " + type), type); } boolean canBeHitByProjectile = (boolean) arguments.getOrDefault("can-be-hit-by-projectile", false); boolean blocksBuilding = (boolean) arguments.getOrDefault("blocks-building", true); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/FurnitureSettings.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/FurnitureSettings.java index 9a9ed04e9..361fc71f8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/FurnitureSettings.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/FurnitureSettings.java @@ -1,6 +1,6 @@ package net.momirealms.craftengine.core.entity.furniture; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import org.jetbrains.annotations.Nullable; @@ -39,7 +39,7 @@ public class FurnitureSettings { if (factory != null) { factory.createModifier(entry.getValue()).apply(settings); } else { - throw new LocalizedException("warning.config.furniture.settings.unknown", new RuntimeException("Unknown furniture settings: " + entry.getKey()), "null", "null", entry.getKey()); + throw new LocalizedResourceConfigException("warning.config.furniture.settings.unknown", new RuntimeException("Unknown furniture settings: " + entry.getKey()), entry.getKey()); } } return settings; @@ -73,10 +73,12 @@ public class FurnitureSettings { return this; } + @FunctionalInterface public interface Modifier { void apply(FurnitureSettings settings); + @FunctionalInterface interface Factory { FurnitureSettings.Modifier createModifier(Object value); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBoxTypes.java b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBoxTypes.java index af2246a5c..3987da6d6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBoxTypes.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/furniture/HitBoxTypes.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.core.entity.furniture; +import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.registry.Registries; @@ -26,7 +27,7 @@ public class HitBoxTypes { Key type = Optional.ofNullable((String) arguments.get("type")).map(Key::of).orElse(HitBoxTypes.INTERACTION); HitBoxFactory factory = BuiltInRegistries.HITBOX_FACTORY.getValue(type); if (factory == null) { - throw new IllegalArgumentException("Unknown hitbox type: " + type); + throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", new IllegalArgumentException("Unknown hitbox type: " + type), type.toString()); } return factory.create(arguments); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LocalizedResourceConfigException.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LocalizedResourceConfigException.java new file mode 100644 index 000000000..04f239989 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/LocalizedResourceConfigException.java @@ -0,0 +1,43 @@ +package net.momirealms.craftengine.core.plugin.locale; + +import net.momirealms.craftengine.core.util.ArrayUtils; +import net.momirealms.craftengine.core.util.Key; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; + +public class LocalizedResourceConfigException extends LocalizedException { + + public LocalizedResourceConfigException( + @NotNull String node, + @Nullable Exception cause, + @Nullable String... arguments + ) { + super(node, cause, ArrayUtils.merge(new String[] {"null", "null"}, arguments)); + } + + public LocalizedResourceConfigException( + @NotNull String node, + @Nullable String... arguments + ) { + super(node, (Exception) null, ArrayUtils.merge(new String[] {"null", "null"}, arguments)); + } + + public LocalizedResourceConfigException( + @NotNull String node, + @NotNull Path path, + @NotNull Key id, + @Nullable String... arguments + ) { + super(node, (Exception) null, ArrayUtils.merge(new String[] {path.toString(), id.toString()}, arguments)); + } + + public void setPath(Path path) { + super.setArgument(0, path.toString()); + } + + public void setId(Key id) { + super.setArgument(1, id.toString()); + } +}