9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-22 00:19:17 +00:00

让事情变得更加美好

This commit is contained in:
XiaoMoMi
2025-04-30 00:28:56 +08:00
parent f875e1dee2
commit 2e871eeef3
69 changed files with 220 additions and 363 deletions

View File

@@ -160,6 +160,7 @@ warning.config.item.model.select.local_time.missing_pattern: "<yellow>Issue foun
warning.config.item.model.special.missing_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'type' argument for model 'minecraft:special'.</yellow>"
warning.config.item.model.special.invalid_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is using an invalid type '<arg:2>' for model 'minecraft:special'.</yellow>"
warning.config.item.model.special.banner.missing_color: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'color' argument for special model 'minecraft:banner'.</yellow>"
warning.config.item.model.special.bed.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:bed'.</yellow>"
warning.config.item.model.special.sign.missing_wood_type: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'wood-type' argument for special model 'minecraft:hanging_sign'/'minecraft:standing_sign'.</yellow>"
warning.config.item.model.special.sign.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:hanging_sign'/'minecraft:standing_sign'.</yellow>"
warning.config.item.model.special.chest.missing_texture: "<yellow>Issue found in file <arg:0> - The item '<arg:1>' is missing the required 'texture' argument for special model 'minecraft:chest'.</yellow>"
@@ -173,6 +174,7 @@ warning.config.block.missing_state: "<yellow>Issue found in file <arg:0> - The b
warning.config.block.state.property.missing_type: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'type' argument for property '<arg:2>'.</yellow>"
warning.config.block.state.property.invalid_type: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is using the invalid type argument '<arg:2>' for property '<arg:3>'.</yellow>"
warning.config.block.state.property.integer.invalid_range: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is using the invalid 'range' argument '<arg:2>' for integer property '<arg:3>'. Correct syntax: 1~2.</yellow>"
warning.config.block.state.property.invalid_format: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is using an invalid block state property format '<arg:2>'.</yellow>"
warning.config.block.state.missing_real_id: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'id' argument for 'state'. 'id' is the serverside block id which is unique for each type of block state. If you create a serverside side block with 'note_block' and id 30, then the real block id would be 'craftengine:note_block_30'.</yellow>"
warning.config.block.state.missing_state: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'state' argument for 'state'.</yellow>"
warning.config.block.state.missing_properties: "<yellow>Issue found in file <arg:0> - The block '<arg:1>' is missing the required 'properties' section for 'states'.</yellow>"

View File

@@ -160,6 +160,7 @@ warning.config.item.model.select.local_time.missing_pattern: "<yellow>在文件
warning.config.item.model.special.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型缺少必需的 'type' 参数</yellow>"
warning.config.item.model.special.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:special' 模型使用了无效类型 '<arg:2>'</yellow>"
warning.config.item.model.special.banner.missing_color: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:banner' 特殊模型缺少必需的 'color' 参数</yellow>"
warning.config.item.model.special.bed.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:bed' 特殊模型缺少必需的 'texture' 参数</yellow>"
warning.config.item.model.special.sign.missing_wood_type: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:hanging_sign'/'minecraft:standing_sign' 特殊模型缺少必需的 'wood-type' 参数</yellow>"
warning.config.item.model.special.sign.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:hanging_sign'/'minecraft:standing_sign' 特殊模型缺少必需的 'texture' 参数</yellow>"
warning.config.item.model.special.chest.missing_texture: "<yellow>在文件 <arg:0> 发现问题 - 物品 '<arg:1>' 的 'minecraft:chest' 特殊模型缺少必需的 'texture' 参数</yellow>"
@@ -173,6 +174,7 @@ warning.config.block.missing_state: "<yellow>在文件 <arg:0> 发现问题 -
warning.config.block.state.property.missing_type: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的属性 '<arg:2>' 缺少必需的 'type' 参数</yellow>"
warning.config.block.state.property.invalid_type: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的属性 '<arg:3>' 使用了无效的类型参数 '<arg:2>'</yellow>"
warning.config.block.state.property.integer.invalid_range: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的整数属性 '<arg:3>' 使用了无效的范围参数 '<arg:2>' 正确语法: 1~2</yellow>"
warning.config.block.state.property.invalid_format: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 使用了无效的方块状态属性格式 '<arg:2>'.</yellow>"
warning.config.block.state.missing_real_id: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'state' 缺少必需的 'id' 参数 该 ID 是服务端方块 ID 用于唯一标识每种方块状态类型</yellow>"
warning.config.block.state.missing_state: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'state' 缺少必需的 'state' 参数</yellow>"
warning.config.block.state.missing_properties: "<yellow>在文件 <arg:0> 发现问题 - 方块 '<arg:1>' 的 'states' 缺少必需的 'properties' 段落</yellow>"

View File

@@ -331,7 +331,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
// check duplicated config
if (byId.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.block.duplicate", path, id);
throw new LocalizedResourceConfigException("warning.config.block.duplicate");
}
// read block settings
BlockSettings settings = BlockSettings.fromMap(MiscUtils.castToMap(section.getOrDefault("settings", Map.of()), false));
@@ -343,13 +343,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
Map<String, Property<?>> properties;
Map<String, Integer> appearances;
Map<String, VariantState> variants;
Object stateObj = section.get("state");
if (stateObj == null) {
stateObj = section.get("states");
}
if (stateObj == null) {
throw new LocalizedResourceConfigException("warning.config.block.missing_state", path, id);
}
Object stateObj = ResourceConfigUtils.requireNonNullOrThrow(ResourceConfigUtils.get(section, "state", "states"), "warning.config.block.missing_state");
Map<String, Object> stateSection = MiscUtils.castToMap(stateObj, true);
// single state
@@ -357,7 +351,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
properties = Map.of();
int internalId = ResourceConfigUtils.getAsInt(stateSection.getOrDefault("id", -1), "id");
if (internalId < 0) {
throw new LocalizedResourceConfigException("warning.config.block.state.missing_real_id", path, id);
throw new LocalizedResourceConfigException("warning.config.block.state.missing_real_id");
}
Pair<Key, Integer> pair = parseAppearanceSection(id, stateSection);
@@ -368,7 +362,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
Key internalBlockId = Key.of(CraftEngine.NAMESPACE, internalBlock);
int internalBlockRegistryId = Optional.ofNullable(internalId2StateId.get(internalBlockId)).orElse(-1);
if (internalBlockRegistryId == -1) {
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_id", path, id,
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_id",
internalBlock,
String.valueOf(registeredRealBlockSlots.get(pair.left()) - 1));
}
@@ -377,13 +371,13 @@ public class BukkitBlockManager extends AbstractBlockManager {
// properties
Map<String, Object> propertySection = MiscUtils.castToMap(stateSection.get("properties"), true);
if (propertySection == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.missing_properties", path, id);
throw new LocalizedResourceConfigException("warning.config.block.state.missing_properties");
}
properties = parseProperties(propertySection);
// appearance
Map<String, Object> appearancesSection = MiscUtils.castToMap(stateSection.get("appearances"), true);
if (appearancesSection == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.missing_appearances", path, id);
throw new LocalizedResourceConfigException("warning.config.block.state.missing_appearances");
}
appearances = new HashMap<>();
Map<String, Key> tempTypeMap = new HashMap<>();
@@ -398,7 +392,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
// variants
Map<String, Object> variantsSection = MiscUtils.castToMap(stateSection.get("variants"), true);
if (variantsSection == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.missing_variants", path, id);
throw new LocalizedResourceConfigException("warning.config.block.state.missing_variants");
}
variants = new HashMap<>();
for (Map.Entry<String, Object> variantEntry : variantsSection.entrySet()) {
@@ -407,17 +401,17 @@ public class BukkitBlockManager extends AbstractBlockManager {
String variantName = variantEntry.getKey();
String appearance = (String) variantSection.get("appearance");
if (appearance == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.variant.missing_appearance", path, id, variantName);
throw new LocalizedResourceConfigException("warning.config.block.state.variant.missing_appearance", variantName);
}
if (!appearances.containsKey(appearance)) {
throw new LocalizedResourceConfigException("warning.config.block.state.variant.invalid_appearance", path, id, variantName, appearance);
throw new LocalizedResourceConfigException("warning.config.block.state.variant.invalid_appearance", variantName, appearance);
}
int internalId = ResourceConfigUtils.getAsInt(variantSection.getOrDefault("id", -1), "id");
Key baseBlock = tempTypeMap.get(appearance);
Key internalBlockId = Key.of(CraftEngine.NAMESPACE, baseBlock.value() + "_" + internalId);
int internalBlockRegistryId = Optional.ofNullable(internalId2StateId.get(internalBlockId)).orElse(-1);
if (internalBlockRegistryId == -1) {
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_id", path, id,
throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_id",
internalBlockId.toString(),
String.valueOf(registeredRealBlockSlots.getOrDefault(baseBlock, 1) - 1));
}

View File

@@ -13,7 +13,6 @@ import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -158,10 +157,7 @@ public class ConcretePowderBlockBehavior extends FallingBlockBehavior {
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
float hurtAmount = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("hurt-amount", -1f), "hurt-amount");
int hurtMax = ResourceConfigUtils.getAsInt(arguments.getOrDefault("max-hurt", -1), "max-hurt");
String solidBlock = (String) arguments.get("solid-block");
if (solidBlock == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.concrete.missing_solid", new NullPointerException("No `solid-block` specified for concrete powder block behavior"));
}
String solidBlock = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("solid-block"), "warning.config.block.behavior.concrete.missing_solid");
return new ConcretePowderBlockBehavior(block, hurtAmount, hurtMax, Key.of(solidBlock));
}
}

View File

@@ -16,7 +16,6 @@ import net.momirealms.craftengine.core.loot.LootContext;
import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.Tuple;
@@ -169,10 +168,7 @@ public class CropBlockBehavior extends BushBlockBehavior {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
Property<Integer> ageProperty = (Property<Integer>) block.getProperty("age");
if (ageProperty == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.crop.missing_age", new IllegalArgumentException("age property not set for crop"));
}
Property<Integer> ageProperty = (Property<Integer>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("age"), "warning.config.block.behavior.crop.missing_age");
int minGrowLight = ResourceConfigUtils.getAsInt(arguments.getOrDefault("light-requirement", 9), "light-requirement");
float growSpeed = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("grow-speed", 0.125f), "grow-speed");
boolean isBoneMealTarget = (boolean) arguments.getOrDefault("is-bone-meal-target", true);

View File

@@ -14,9 +14,9 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.world.BlockPos;
@@ -173,14 +173,8 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior {
public static class Factory implements BlockBehaviorFactory {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Property<Boolean> persistent = (Property<Boolean>) block.getProperty("persistent");
if (persistent == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.leaves.missing_persistent", new NullPointerException("persistent property not set for block " + block.id()));
}
Property<Integer> distance = (Property<Integer>) block.getProperty("distance");
if (distance == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.leaves.missing_distance", new NullPointerException("distance property not set for block " + block.id()));
}
Property<Boolean> persistent = (Property<Boolean>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("persistent"), "warning.config.block.behavior.leaves.missing_persistent");
Property<Integer> distance = (Property<Integer>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("distance"), "warning.config.block.behavior.leaves.missing_distance");
Property<Boolean> waterlogged = (Property<Boolean>) block.getProperty("waterlogged");
int actual = distance.possibleValues().get(distance.possibleValues().size() - 1);
return new LeavesBlockBehavior(block, actual, distance, persistent, waterlogged);

View File

@@ -10,7 +10,6 @@ import net.momirealms.craftengine.core.block.UpdateOption;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.RandomUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -141,14 +140,8 @@ public class SaplingBlockBehavior extends BushBlockBehavior {
@SuppressWarnings("unchecked")
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String feature = (String) arguments.get("feature");
if (feature == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.sapling.missing_feature", new IllegalArgumentException("'feature' is required for sapling block behavior"));
}
Property<Integer> stageProperty = (Property<Integer>) block.getProperty("stage");
if (stageProperty == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.sapling.missing_stage", new IllegalArgumentException("stage property not set for sapling"));
}
String feature = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("feature"), "warning.config.block.behavior.sapling.missing_feature");
Property<Integer> stageProperty = (Property<Integer>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("stage"), "warning.config.block.behavior.sapling.missing_stage");
double boneMealSuccessChance = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("bone-meal-success-chance", 0.45), "bone-meal-success-chance");
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
return new SaplingBlockBehavior(block, Key.of(feature), stageProperty, tuple.left(), tuple.mid(), tuple.right(), boneMealSuccessChance,

View File

@@ -2,8 +2,8 @@ package net.momirealms.craftengine.bukkit.block.behavior;
import net.momirealms.craftengine.core.block.CustomBlock;
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.shared.block.BlockBehavior;
import java.util.Map;
@@ -25,10 +25,7 @@ public class StrippableBlockBehavior extends BukkitBlockBehavior {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
String stripped = (String) arguments.get("stripped");
if (stripped == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.strippable.missing_stripped", new IllegalArgumentException("'stripped' is required for strippable block behavior"));
}
String stripped = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("stripped"), "warning.config.block.behavior.strippable.missing_stripped");
return new StrippableBlockBehavior(block, Key.of(stripped));
}
}

View File

@@ -14,7 +14,6 @@ import net.momirealms.craftengine.core.block.properties.IntegerProperty;
import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.world.BlockPos;
@@ -199,10 +198,7 @@ public class SugarCaneBlockBehavior extends BushBlockBehavior {
@Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
Tuple<List<Object>, Set<Object>, Set<String>> tuple = readTagsAndState(arguments, false);
Property<Integer> ageProperty = (Property<Integer>) block.getProperty("age");
if (ageProperty == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.sugar_cane.missing_age", new IllegalArgumentException("'age' property not set for sugar cane block behavior"));
}
Property<Integer> ageProperty = (Property<Integer>) ResourceConfigUtils.requireNonNullOrThrow(block.getProperty("age"), "warning.config.block.behavior.sugar_cane.missing_age");
int maxHeight = ResourceConfigUtils.getAsInt(arguments.getOrDefault("max-height", 3), "max-height");
List<String> nearbyLiquids = MiscUtils.getAsStringList(arguments.getOrDefault("required-adjacent-liquids", List.of()));
boolean nearWater = nearbyLiquids.contains("water");

View File

@@ -240,7 +240,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
@Override
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
if (customItems.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.item.duplicate", path, id);
throw new LocalizedResourceConfigException("warning.config.item.duplicate");
}
// register for recipes
@@ -249,16 +249,16 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
boolean isVanillaItem = id.namespace().equals("minecraft") && Registry.MATERIAL.get(new NamespacedKey(id.namespace(), id.value())) != null;
String materialStringId = (String) section.get("material");
if (isVanillaItem)
String materialStringId;
if (isVanillaItem) {
materialStringId = id.value();
if (materialStringId == null) {
throw new LocalizedResourceConfigException("warning.config.item.missing_material", path, id);
} else {
materialStringId = ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("material"), "warning.config.item.missing_material");
}
Material material = MaterialUtils.getMaterial(materialStringId);
if (material == null) {
throw new LocalizedResourceConfigException("warning.config.item.invalid_material", path, id);
throw new LocalizedResourceConfigException("warning.config.item.invalid_material", materialStringId);
}
Key materialId = Key.of(material.getKey().namespace(), material.getKey().value());
@@ -391,11 +391,11 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
// check conflict
Map<Integer, Key> conflict = cmdConflictChecker.computeIfAbsent(materialId, k -> new HashMap<>());
if (conflict.containsKey(customModelData)) {
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", path, id, String.valueOf(customModelData), conflict.get(customModelData).toString());
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", String.valueOf(customModelData), conflict.get(customModelData).toString());
}
if (customModelData > 16_777_216) {
throw new LocalizedResourceConfigException("warning.config.item.bad_custom_model_data", path, id, String.valueOf(customModelData));
throw new LocalizedResourceConfigException("warning.config.item.bad_custom_model_data", String.valueOf(customModelData));
}
conflict.put(customModelData, id);
@@ -439,7 +439,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
}
}
if (!hasModel) {
throw new LocalizedResourceConfigException("warning.config.item.missing_model_id", path, id);
throw new LocalizedResourceConfigException("warning.config.item.missing_model_id");
}
}
}

View File

@@ -16,10 +16,7 @@ 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.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.EnumUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.util.*;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.world.Vec3d;
import org.bukkit.Bukkit;
@@ -109,10 +106,7 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
@Override
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
String type = (String) section.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.vanilla_loot.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("type"), "warning.config.vanilla_loot.missing_type");
VanillaLoot.Type typeEnum;
try {
typeEnum = VanillaLoot.Type.valueOf(type.toUpperCase(Locale.ENGLISH));

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.block.properties.Property;
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
import net.momirealms.craftengine.core.loot.LootTable;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.shared.block.BlockBehavior;
@@ -54,13 +55,12 @@ public abstract class CustomBlock {
String nbtString = entry.getKey();
CompoundTag tag = BlockNbtParser.deserialize(this, nbtString);
if (tag == null) {
CraftEngine.instance().logger().warn("Illegal block state: " + nbtString);
continue;
throw new LocalizedResourceConfigException("warning.config.block.state.property.invalid_format", nbtString);
}
VariantState variantState = entry.getValue();
int vanillaStateRegistryId = appearances.getOrDefault(variantState.appearance(), -1);
// This should never happen
if (vanillaStateRegistryId == -1) {
CraftEngine.instance().logger().warn("Could not find appearance " + variantState.appearance() + " for block " + id);
vanillaStateRegistryId = appearances.values().iterator().next();
}
// Late init states

View File

@@ -7,6 +7,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import net.momirealms.craftengine.shared.block.BlockBehavior;
import net.momirealms.craftengine.shared.block.EmptyBlockBehavior;
@@ -25,11 +26,8 @@ public class BlockBehaviors {
public static BlockBehavior fromMap(CustomBlock block, @Nullable Map<String, Object> map) {
if (map == null || map.isEmpty()) return EmptyBlockBehavior.INSTANCE;
Object type = map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.missing_type");
}
Key key = Key.withDefaultNamespace(type.toString(), "craftengine");
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.block.behavior.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
BlockBehaviorFactory factory = BuiltInRegistries.BLOCK_BEHAVIOR_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.block.behavior.invalid_type", type.toString());

View File

@@ -5,10 +5,7 @@ import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Direction;
import net.momirealms.craftengine.core.util.HorizontalDirection;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceKey;
import net.momirealms.craftengine.core.util.*;
import java.util.Map;
@@ -35,11 +32,8 @@ public class Properties {
}
public static Property<?> fromMap(String name, Map<String, Object> map) {
Object type = map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.property.missing_type", name);
}
Key key = Key.withDefaultNamespace(type.toString(), "craftengine");
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.block.state.property.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
PropertyFactory factory = BuiltInRegistries.PROPERTY_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.block.state.property.invalid_type", key.toString(), name);

View File

@@ -24,7 +24,7 @@ public class HitBoxTypes {
}
public static HitBox fromMap(Map<String, Object> arguments) {
Key type = Optional.ofNullable((String) arguments.get("type")).map(Key::of).orElse(HitBoxTypes.INTERACTION);
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(Key::of).orElse(HitBoxTypes.INTERACTION);
HitBoxFactory factory = BuiltInRegistries.HITBOX_FACTORY.getValue(type);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", type.toString());

View File

@@ -7,7 +7,9 @@ import net.momirealms.craftengine.core.util.CharacterUtils;
import net.momirealms.craftengine.core.util.FormatUtils;
import net.momirealms.craftengine.core.util.Key;
public class BitmapImage implements FontProvider {
import java.util.function.Supplier;
public class BitmapImage implements Supplier<JsonObject> {
private final Key id;
private final Key font;
private final int height;

View File

@@ -1,8 +0,0 @@
package net.momirealms.craftengine.core.font;
import com.google.gson.JsonObject;
import java.util.function.Supplier;
public interface FontProvider extends Supplier<JsonObject> {
}

View File

@@ -7,6 +7,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.nio.file.Path;
@@ -23,11 +24,8 @@ public class ItemBehaviors {
public static ItemBehavior fromMap(Pack pack, Path path, Key id, Map<String, Object> map) {
if (map == null || map.isEmpty()) return EmptyItemBehavior.INSTANCE;
Object type = map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.behavior.missing_type");
}
Key key = Key.withDefaultNamespace(type.toString(), "craftengine");
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.item.behavior.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
ItemBehaviorFactory factory = BuiltInRegistries.ITEM_BEHAVIOR_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.item.behavior.invalid_type", type.toString());

View File

@@ -7,6 +7,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.util.EnumUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.*;
@@ -34,10 +35,7 @@ public abstract class AbstractRecipeFactory<T> implements RecipeFactory<T> {
}
protected Object getIngredientOrThrow(Map<String, Object> arguments) {
Object ingredient = arguments.get("ingredient");
if (ingredient == null) {
ingredient = arguments.get("ingredients");
}
Object ingredient = ResourceConfigUtils.get(arguments, "ingredient", "ingredients");
if (ingredient == null) {
throw new LocalizedResourceConfigException("warning.config.recipe.missing_ingredient");
}

View File

@@ -18,10 +18,7 @@ public interface RecipeFactory<T> {
if (resultMap == null) {
throw new LocalizedResourceConfigException("warning.config.recipe.missing_result");
}
String id = (String) resultMap.get("id");
if (id == null) {
throw new LocalizedResourceConfigException("warning.config.recipe.result.missing_id");
}
String id = ResourceConfigUtils.requireNonEmptyStringOrThrow(resultMap.get("id"), "warning.config.recipe.result.missing_id");
int count = ResourceConfigUtils.getAsInt(resultMap.getOrDefault("count", 1), "count");
return new CustomRecipeResult(
CraftEngine.instance().itemManager().getBuildableItem(Key.of(id)).orElseThrow(

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -40,10 +41,7 @@ public class RecipeTypes {
@SuppressWarnings("unchecked")
public static <T> Recipe<T> fromMap(Key id, Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.recipe.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.recipe.missing_type");
Key key = Key.withDefaultNamespace(type, "minecraft");
RecipeFactory<T> factory = (RecipeFactory<T>) BuiltInRegistries.RECIPE_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.world.World;
import org.jetbrains.annotations.Nullable;
@@ -40,10 +41,7 @@ public class LootTable<T> {
@SuppressWarnings("unchecked")
public static <T> LootTable<T> fromMap(Map<String, Object> map) {
if (map == null || map.isEmpty()) return null;
Object pools = map.get("pools");
if (pools == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.missing_pools");
}
Object pools = ResourceConfigUtils.requireNonNullOrThrow(map.get("pools"), "warning.config.loot_table.missing_pools");
if (!(pools instanceof List<?> list) || list.isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.loot_table.invalid_pools_type", pools.getClass().getSimpleName());
}

View File

@@ -6,8 +6,8 @@ import net.momirealms.craftengine.core.loot.condition.LootConditions;
import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Collections;
import java.util.List;
@@ -44,10 +44,7 @@ public class ExpLootEntryContainer<T> extends AbstractLootEntryContainer<T> {
@SuppressWarnings("unchecked")
@Override
public LootEntryContainer<A> create(Map<String, Object> arguments) {
Object value = arguments.get("count");
if (value == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.entry.exp.missing_count");
}
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.entry.exp.missing_count");
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.ArrayList;
@@ -40,10 +41,7 @@ public class LootEntryContainers {
@SuppressWarnings("unchecked")
public static <T> LootEntryContainer<T> fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.entry.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.entry.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
LootEntryContainerFactory<T> factory = (LootEntryContainerFactory<T>) BuiltInRegistries.LOOT_ENTRY_CONTAINER_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -8,8 +8,8 @@ import net.momirealms.craftengine.core.loot.function.LootFunction;
import net.momirealms.craftengine.core.loot.function.LootFunctions;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.*;
import java.util.function.Consumer;
@@ -43,13 +43,10 @@ public class SingleItemLootEntryContainer<T> extends AbstractSingleLootEntryCont
@SuppressWarnings("unchecked")
@Override
public LootEntryContainer<A> create(Map<String, Object> arguments) {
Object itemObj = arguments.get("item");
if (itemObj == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.entry.item.missing_item");
}
Key item = Key.from(itemObj.toString());
int weight = (int) arguments.getOrDefault("weight", 1);
int quality = (int) arguments.getOrDefault("quality", 0);
String itemObj = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), "warning.config.loot_table.entry.item.missing_item");
Key item = Key.from(itemObj);
int weight = ResourceConfigUtils.getAsInt(arguments.getOrDefault("weight", 1), "weight");
int quality = ResourceConfigUtils.getAsInt(arguments.getOrDefault("quality", 0), "quality");
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());

View File

@@ -49,10 +49,7 @@ public class ApplyBonusCountFunction<T> extends AbstractLootConditionalFunction<
@SuppressWarnings("unchecked")
@Override
public LootFunction<T> create(Map<String, Object> arguments) {
String enchantment = (String) arguments.get("enchantment");
if (enchantment == null || enchantment.isEmpty()) {
throw new LocalizedResourceConfigException("warning.config.loot_table.function.apply_bonus.missing_enchantment");
}
String enchantment = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("enchantment"), "warning.config.loot_table.function.apply_bonus.missing_enchantment");
Map<String, Object> formulaMap = MiscUtils.castToMap(arguments.get("formula"), true);
if (formulaMap == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.function.apply_bonus.missing_formula");

View File

@@ -7,8 +7,8 @@ import net.momirealms.craftengine.core.loot.condition.LootConditions;
import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Collections;
import java.util.List;
@@ -40,10 +40,7 @@ public class DropExpFunction<T> extends AbstractLootConditionalFunction<T> {
@SuppressWarnings("unchecked")
@Override
public LootFunction<T> create(Map<String, Object> arguments) {
Object value = arguments.get("count");
if (value == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.function.drop_exp.missing_count");
}
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.function.drop_exp.missing_count");
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))
.orElse(Collections.emptyList());

View File

@@ -8,6 +8,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.ArrayList;
@@ -68,10 +69,7 @@ public class LootFunctions {
@SuppressWarnings("unchecked")
public static <T> LootFunction<T> fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.function.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.function.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
LootFunctionFactory<T> factory = (LootFunctionFactory<T>) BuiltInRegistries.LOOT_FUNCTION_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -6,8 +6,8 @@ import net.momirealms.craftengine.core.loot.condition.LootCondition;
import net.momirealms.craftengine.core.loot.condition.LootConditions;
import net.momirealms.craftengine.core.loot.number.NumberProvider;
import net.momirealms.craftengine.core.loot.number.NumberProviders;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Collections;
import java.util.List;
@@ -42,10 +42,7 @@ public class SetCountFunction<T> extends AbstractLootConditionalFunction<T> {
@SuppressWarnings("unchecked")
@Override
public LootFunction<A> create(Map<String, Object> arguments) {
Object value = arguments.get("count");
if (value == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.function.set_count.missing_count");
}
Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.function.set_count.missing_count");
boolean add = (boolean) arguments.getOrDefault("add", false);
List<LootCondition> conditions = Optional.ofNullable(arguments.get("conditions"))
.map(it -> LootConditions.fromMapList((List<Map<String, Object>>) it))

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.ArrayList;
@@ -37,10 +38,7 @@ public class NumberProviders {
}
public static NumberProvider fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.loot_table.number.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.number.missing_type");
Key key = Key.withDefaultNamespace(type, "craftengine");
NumberProviderFactory factory = BuiltInRegistries.NUMBER_PROVIDER_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -1,6 +1,6 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -44,7 +44,7 @@ public class AllOfPathMatcher implements PathMatcher {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AllOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.all_of.missing_terms");
throw new LocalizedException("warning.config.conflict_matcher.all_of.missing_terms");
}
}
}

View File

@@ -1,6 +1,6 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
@@ -44,7 +44,7 @@ public class AnyOfPathMatcher implements PathMatcher {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AnyOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.any_of.missing_terms");
throw new LocalizedException("warning.config.conflict_matcher.any_of.missing_terms");
}
}
}

View File

@@ -1,7 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -29,11 +30,8 @@ public class ExactPathMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object path = arguments.get("path");
if (path == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.exact.missing_path");
}
return new ExactPathMatcher(path.toString());
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
return new ExactPathMatcher(path);
}
}
}

View File

@@ -1,7 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -29,11 +30,8 @@ public class FilenameMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object name = arguments.get("name");
if (name == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.filename.missing_name");
}
return new FilenameMatcher(name.toString());
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
return new FilenameMatcher(name);
}
}
}

View File

@@ -1,8 +1,9 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -29,10 +30,7 @@ public class InvertedPathMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object inverted = arguments.get("term");
if (inverted == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.inverted.missing_term");
}
Object inverted = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("term"), () -> new LocalizedException("warning.config.conflict_matcher.inverted.missing_term"));
Map<String, Object> term = MiscUtils.castToMap(inverted, false);
return new InvertedPathMatcher(PathMatchers.fromMap(term));
}

View File

@@ -1,7 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -31,11 +32,8 @@ public class ParentPathPrefixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object prefix = arguments.get("prefix");
if (prefix == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.parent_prefix.missing_prefix");
}
return new ParentPathPrefixMatcher(prefix.toString());
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
return new ParentPathPrefixMatcher(prefix);
}
}
}

View File

@@ -1,7 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -31,11 +32,8 @@ public class ParentPathSuffixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object suffix = arguments.get("suffix");
if (suffix == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.parent_suffix.missing_suffix");
}
return new ParentPathSuffixMatcher(suffix.toString());
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
return new ParentPathSuffixMatcher(suffix);
}
}
}

View File

@@ -1,7 +1,8 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
@@ -29,11 +30,8 @@ public class PathContainsMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object path = arguments.get("path");
if (path == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.contains.missing_path");
}
return new PathContainsMatcher(path.toString());
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
return new PathContainsMatcher(path);
}
}
}

View File

@@ -1,11 +1,12 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.ArrayList;
@@ -49,14 +50,11 @@ public class PathMatchers {
}
public static PathMatcher fromMap(Map<String, Object> map) {
String type = (String) map.getOrDefault("type", "empty");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type"));
Key key = Key.withDefaultNamespace(type, "craftengine");
PathMatcherFactory factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.invalid_type", type);
throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type);
}
return factory.create(map);
}

View File

@@ -1,23 +1,29 @@
package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
import java.util.regex.Pattern;
public class PathPatternMatcher implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String pattern;
private final Pattern pattern;
public PathPatternMatcher(String pattern) {
this.pattern = Pattern.compile(pattern);
}
public PathPatternMatcher(Pattern pattern) {
this.pattern = pattern;
}
@Override
public boolean test(Path path) {
String pathStr = path.toString().replace("\\", "/");
return pathStr.matches(pattern);
return this.pattern.matcher(pathStr).matches();
}
@Override
@@ -25,15 +31,16 @@ public class PathPatternMatcher implements PathMatcher {
return PathMatchers.PATTERN;
}
public Pattern pattern() {
return pattern;
}
public static class Factory implements PathMatcherFactory {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object pattern = arguments.get("pattern");
if (pattern == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_matcher.pattern.missing_pattern");
}
return new PathPatternMatcher(pattern.toString());
String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), () -> new LocalizedException("warning.config.conflict_matcher.pattern.missing_pattern"));
return new PathPatternMatcher(pattern);
}
}
}

View File

@@ -207,7 +207,7 @@ public class MergePackMcMetaResolution implements Resolution {
public static class Factory implements ResolutionFactory {
@Override
public Resolution create(Map<String, Object> arguments) {
String description = (String) arguments.getOrDefault("description", "<gray>CraftEngine ResourcePack");
String description = arguments.getOrDefault("description", "<gray>CraftEngine ResourcePack</gray>").toString();
return new MergePackMcMetaResolution(description);
}
}

View File

@@ -1,11 +1,12 @@
package net.momirealms.craftengine.core.pack.conflict.resolution;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -31,14 +32,11 @@ public class Resolutions {
}
public static Resolution fromMap(Map<String, Object> map) {
String type = (String) map.getOrDefault("type", "empty");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_resolution.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_resolution.missing_type"));
Key key = Key.withDefaultNamespace(type, "craftengine");
ResolutionFactory factory = BuiltInRegistries.RESOLUTION_FACTORY.getValue(key);
if (factory == null) {
throw new LocalizedResourceConfigException("warning.config.conflict_resolution.invalid_type", type);
throw new LocalizedException("warning.config.conflict_resolution.invalid_type", type);
}
return factory.create(map);
}

View File

@@ -292,10 +292,7 @@ public class AlistHost implements ResourcePackHost {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String apiUrl = Optional.ofNullable(arguments.get("api-url")).map(String::valueOf).orElse(null);
if (apiUrl == null || apiUrl.isEmpty()) {
throw new LocalizedException("warning.config.host.alist.missing_api_url");
}
String apiUrl = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("api-url"), () -> new LocalizedException("warning.config.host.alist.missing_api_url"));
String userName = useEnv ? System.getenv("CE_ALIST_USERNAME") : Optional.ofNullable(arguments.get("username")).map(String::valueOf).orElse(null);
if (userName == null || userName.isEmpty()) {
throw new LocalizedException("warning.config.host.alist.missing_username");
@@ -307,10 +304,7 @@ public class AlistHost implements ResourcePackHost {
String filePassword = useEnv ? System.getenv("CE_ALIST_FILE_PASSWORD") : arguments.getOrDefault("file-password", "").toString();
String otpCode = Optional.ofNullable(arguments.get("otp-code")).map(String::valueOf).orElse(null);
Duration jwtTokenExpiration = Duration.ofHours((int) arguments.getOrDefault("jwt-token-expiration", 48));
String uploadPath = Optional.ofNullable(arguments.get("upload-path")).map(String::valueOf).orElse(null);
if (uploadPath == null || uploadPath.isEmpty()) {
throw new LocalizedException("warning.config.host.alist.missing_upload_path");
}
String uploadPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("upload-path"), () -> new LocalizedException("warning.config.host.alist.missing_upload_path"));
boolean disableUpload = (boolean) arguments.getOrDefault("disable-upload", false);
ProxySelector proxy = getProxySelector(MiscUtils.castToMap(arguments.get("proxy"), true));
return new AlistHost(apiUrl, userName, password, filePassword, otpCode, jwtTokenExpiration, uploadPath, disableUpload, proxy);

View File

@@ -8,10 +8,7 @@ import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory;
import net.momirealms.craftengine.core.pack.host.ResourcePackHosts;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.GsonHelper;
import net.momirealms.craftengine.core.util.HashUtils;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.*;
import java.io.IOException;
import java.io.InputStream;
@@ -279,10 +276,7 @@ public class DropboxHost implements ResourcePackHost {
if (refreshToken == null || refreshToken.isEmpty()) {
throw new LocalizedException("warning.config.host.dropbox.missing_refresh_token");
}
String uploadPath = Optional.ofNullable(arguments.get("upload-path")).map(String::valueOf).orElse(null);
if (uploadPath == null || uploadPath.isEmpty()) {
throw new LocalizedException("warning.config.host.dropbox.missing_upload_path");
}
String uploadPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("upload-path"), () -> new LocalizedException("warning.config.host.dropbox.missing_upload_path"));
ProxySelector proxy = getProxySelector(MiscUtils.castToMap(arguments.get("proxy"), true));
return new DropboxHost(appKey, appSecret, refreshToken, "/" + uploadPath, proxy);
}

View File

@@ -206,18 +206,12 @@ public class S3Host implements ResourcePackHost {
Map<String, Object> proxySetting = MiscUtils.castToMap(arguments.get("proxy"), true);
if (proxySetting != null) {
String host = Optional.ofNullable(proxySetting.get("host")).map(String::valueOf).orElse(null);
if (host == null || host.isEmpty()) {
throw new LocalizedException("warning.config.host.proxy.missing_host");
}
String host = ResourceConfigUtils.requireNonEmptyStringOrThrow(proxySetting.get("host"), () -> new LocalizedException("warning.config.host.proxy.missing_host"));
int port = ResourceConfigUtils.getAsInt(proxySetting.get("port"), "port");
if (port <= 0 || port > 65535) {
throw new LocalizedException("warning.config.host.proxy.missing_port");
}
String scheme = Optional.ofNullable(proxySetting.get("scheme")).map(String::valueOf).orElse(null);
if (scheme == null || scheme.isEmpty()) {
throw new LocalizedException("warning.config.host.proxy.missing_scheme");
}
String scheme = ResourceConfigUtils.requireNonEmptyStringOrThrow(proxySetting.get("scheme"), () -> new LocalizedException("warning.config.host.proxy.missing_scheme"));
String username = Optional.ofNullable(proxySetting.get("username")).map(String::valueOf).orElse(null);
String password = Optional.ofNullable(proxySetting.get("password")).map(String::valueOf).orElse(null);
ProxyConfiguration.Builder builder = ProxyConfiguration.builder().host(host).port(port).scheme(scheme);

View File

@@ -14,7 +14,6 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -62,12 +61,9 @@ public class SelfHost implements ResourcePackHost {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
SelfHostHttpServer selfHostHttpServer = SelfHostHttpServer.instance();
String ip = Optional.ofNullable(arguments.get("ip")).map(String::valueOf).orElse(null);
if (ip == null) {
throw new LocalizedException("warning.config.host.self.missing_ip");
}
String ip = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("ip"), () -> new LocalizedException("warning.config.host.self.missing_ip"));
int port = ResourceConfigUtils.getAsInt(arguments.getOrDefault("port", 8163), "port");
if (port < 0 || port > 65535) {
if (port <= 0 || port > 65535) {
throw new LocalizedException("warning.config.host.self.invalid_port", String.valueOf(port));
}
boolean oneTimeToken = (boolean) arguments.getOrDefault("one-time-token", true);

View File

@@ -9,6 +9,7 @@ import net.momirealms.craftengine.core.pack.model.tint.Tints;
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.ResourceConfigUtils;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -69,11 +70,7 @@ public class BaseItemModel implements ItemModel {
@SuppressWarnings("unchecked")
@Override
public ItemModel create(Map<String, Object> arguments) {
Object path = arguments.get("path");
if (path == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.base.missing_path");
}
String modelPath = path.toString();
String modelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), "warning.config.item.model.base.missing_path");
if (!ResourceLocation.isValid(modelPath)) {
throw new LocalizedResourceConfigException("warning.config.item.model.base.invalid_path", modelPath);
}

View File

@@ -36,7 +36,7 @@ public class ItemModels {
}
public static ItemModel fromMap(Map<String, Object> map) {
String type = (String) map.getOrDefault("type", "minecraft:model");
String type = map.getOrDefault("type", "minecraft:model").toString();
Key key = Key.withDefaultNamespace(type, "minecraft");
ItemModelFactory factory = BuiltInRegistries.ITEM_MODEL_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -97,7 +97,6 @@ public class SelectItemModel implements ItemModel {
public ItemModel create(Map<String, Object> arguments) {
SelectProperty property = SelectProperties.fromMap(arguments);
Map<String, Object> fallback = MiscUtils.castToMap(arguments.get("fallback"), true);
Object casesObj = arguments.get("cases");
if (casesObj instanceof List<?> list) {
List<Map<String, Object>> cases = (List<Map<String, Object>>) list;

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -46,10 +47,7 @@ public class ConditionProperties {
}
public static ConditionProperty fromMap(Map<String, Object> map) {
String type = (String) map.get("property");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.condition.missing_property");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("property"), "warning.config.item.model.condition.missing_property");
Key key = Key.withDefaultNamespace(type, "minecraft");
ConditionPropertyFactory factory = BuiltInRegistries.CONDITION_PROPERTY_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.condition;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -35,12 +35,8 @@ public class HasComponentConditionProperty implements ConditionProperty {
@Override
public ConditionProperty create(Map<String, Object> arguments) {
boolean ignoreDefault = (boolean) arguments.getOrDefault("ignore-default", false);
Object componentObj = arguments.get("component");
if (componentObj == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.condition.has_component.missing_component");
}
String component = componentObj.toString();
return new HasComponentConditionProperty(component, ignoreDefault);
String componentObj = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("component"), "warning.config.item.model.condition.has_component.missing_component");
return new HasComponentConditionProperty(componentObj, ignoreDefault);
}
}
}

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.condition;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -29,12 +29,8 @@ public class KeyBindDownConditionProperty implements ConditionProperty {
@Override
public ConditionProperty create(Map<String, Object> arguments) {
Object keybindObj = arguments.get("keybind");
if (keybindObj == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.condition.keybind.missing");
}
String keybind = keybindObj.toString();
return new KeyBindDownConditionProperty(keybind);
String keybindObj = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("keybind"), "warning.config.item.model.condition.keybind.missing");
return new KeyBindDownConditionProperty(keybindObj);
}
}
}

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.rangedisptach;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -29,12 +29,8 @@ public class CompassRangeDispatchProperty implements RangeDispatchProperty {
@Override
public RangeDispatchProperty create(Map<String, Object> arguments) {
Object targetObj = arguments.get("target");
if (targetObj == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.range_dispatch.compass.missing_target");
}
String target = targetObj.toString();
return new CompassRangeDispatchProperty(target);
String targetObj = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("target"), "warning.config.item.model.range_dispatch.compass.missing_target");
return new CompassRangeDispatchProperty(targetObj);
}
}
}

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -42,10 +43,7 @@ public class RangeDispatchProperties {
}
public static RangeDispatchProperty fromMap(Map<String, Object> map) {
String type = (String) map.get("property");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.range_dispatch.missing_property");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("property"), "warning.config.item.model.range_dispatch.missing_property");
Key key = Key.withDefaultNamespace(type, "minecraft");
RangeDispatchPropertyFactory factory = BuiltInRegistries.RANGE_DISPATCH_PROPERTY_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.rangedisptach;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -34,13 +34,9 @@ public class TimeRangeDispatchProperty implements RangeDispatchProperty {
@Override
public RangeDispatchProperty create(Map<String, Object> arguments) {
Object sourceObj = arguments.get("source");
if (sourceObj == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.range_dispatch.time.missing_source");
}
String source = sourceObj.toString();
String sourceObj = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("source"), "warning.config.item.model.range_dispatch.time.missing_source");
boolean wobble = (boolean) arguments.getOrDefault("wobble", true);
return new TimeRangeDispatchProperty(source, wobble);
return new TimeRangeDispatchProperty(sourceObj, wobble);
}
}
}

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.select;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -29,12 +29,8 @@ public class BlockStateSelectProperty implements SelectProperty {
@Override
public SelectProperty create(Map<String, Object> arguments) {
Object property = arguments.get("block-state-property");
if (property == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.select.block_state.missing_property");
}
String blockStateProperty = property.toString();
return new BlockStateSelectProperty(blockStateProperty);
String property = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("block-state-property"), "warning.config.item.model.select.block_state.missing_property");
return new BlockStateSelectProperty(property);
}
}
}

View File

@@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.pack.model.select;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -42,11 +43,7 @@ public class LocalTimeSelectProperty implements SelectProperty {
@Override
public SelectProperty create(Map<String, Object> arguments) {
Object patternObj = arguments.get("pattern");
if (patternObj == null) {
throw new IllegalArgumentException("warning.config.item.model.select.local_time.missing_pattern", new NullPointerException("pattern should not be null"));
}
String pattern = patternObj.toString();
String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), "warning.config.item.model.select.local_time.missing_pattern");
String locale = (String) arguments.get("locale");
String timeZone = (String) arguments.get("time-zone");
return new LocalTimeSelectProperty(pattern, locale, timeZone);

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -40,10 +41,7 @@ public class SelectProperties {
}
public static SelectProperty fromMap(Map<String, Object> map) {
String type = (String) map.get("property");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.select.missing_property");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("property"), "warning.config.item.model.select.missing_property");
Key key = Key.withDefaultNamespace(type, "minecraft");
SelectPropertyFactory factory = BuiltInRegistries.SELECT_PROPERTY_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.special;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
@@ -31,11 +31,8 @@ public class BannerSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
Object color = arguments.get("color");
if (color == null) {
throw new LocalizedResourceConfigException("");
}
return new BannerSpecialModel(color.toString());
String color = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("color"), "warning.config.item.model.special.banner.missing_color");
return new BannerSpecialModel(color);
}
}
}

View File

@@ -2,9 +2,9 @@ package net.momirealms.craftengine.core.pack.model.special;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Objects;
public class BedSpecialModel implements SpecialModel {
public static final Factory FACTORY = new Factory();
@@ -31,7 +31,7 @@ public class BedSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
String color = Objects.requireNonNull(arguments.get("texture"), "texture").toString();
String color = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.bed.missing_texture");
return new BedSpecialModel(color);
}
}

View File

@@ -36,14 +36,11 @@ public class ChestSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
float openness = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("openness", 0), "openness");
Object texture = arguments.get("texture");
if (texture == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.chest.missing_texture");
}
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.chest.missing_texture");
if (openness > 1 || openness < 0) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.chest.invalid_openness", String.valueOf(openness));
}
return new ChestSpecialModel(texture.toString(), openness);
return new ChestSpecialModel(texture, openness);
}
}
}

View File

@@ -1,7 +1,6 @@
package net.momirealms.craftengine.core.pack.model.special;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
@@ -38,16 +37,10 @@ public class HeadSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
Object kind = arguments.get("kind");
if (kind == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.head.missing_kind");
}
Object texture = arguments.get("texture");
if (texture == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.head.missing_texture");
}
String kind = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("kind"), "warning.config.item.model.special.head.missing_kind");
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.head.missing_texture");
int animation = ResourceConfigUtils.getAsInt(arguments.getOrDefault("animation", 0), "animation");
return new HeadSpecialModel(kind.toString(), texture.toString(), animation);
return new HeadSpecialModel(kind, texture, animation);
}
}
}

View File

@@ -41,15 +41,12 @@ public class ShulkerBoxSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
float openness = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("openness", 0), "openness");
Object texture = arguments.get("texture");
if (texture == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.shulker_box.missing_texture");
}
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.shulker_box.missing_texture");
Direction orientation = Direction.valueOf(arguments.getOrDefault("orientation", "down").toString().toUpperCase(Locale.ENGLISH));
if (openness > 1 || openness < 0) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.shulker_box.invalid_openness", String.valueOf(openness));
}
return new ShulkerBoxSpecialModel(texture.toString(), openness, orientation);
return new ShulkerBoxSpecialModel(texture, openness, orientation);
}
}
}

View File

@@ -1,12 +1,10 @@
package net.momirealms.craftengine.core.pack.model.special;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
import java.util.Objects;
public class SignSpecialModel implements SpecialModel {
public static final Factory FACTORY = new Factory();
@@ -39,8 +37,8 @@ public class SignSpecialModel implements SpecialModel {
@Override
public SpecialModel create(Map<String, Object> arguments) {
Key type = Key.of(arguments.get("type").toString());
String woodType = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("wood-type"), "warning.config.item.model.special.sign.missing_wood_type").toString();
String texture = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("texture"), "warning.config.item.model.special.sign.missing_texture").toString();
String woodType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("wood-type"), "warning.config.item.model.special.sign.missing_wood_type");
String texture = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("texture"), "warning.config.item.model.special.sign.missing_texture");
return new SignSpecialModel(type, woodType, texture);
}
}

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -43,10 +44,7 @@ public class SpecialModels {
}
public static SpecialModel fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.special.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.item.model.special.missing_type");
Key key = Key.withDefaultNamespace(type, "minecraft");
SpecialModelFactory factory = BuiltInRegistries.SPECIAL_MODEL_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -1,8 +1,8 @@
package net.momirealms.craftengine.core.pack.model.tint;
import com.google.gson.JsonObject;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import org.incendo.cloud.type.Either;
import java.util.List;
@@ -33,10 +33,7 @@ public class ConstantTint implements Tint {
@Override
public Tint create(Map<String, Object> arguments) {
Object value = arguments.get("value");
if (value == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.tint.constant.missing_value");
}
Object value = ResourceConfigUtils.requireNonNullOrThrow("warning.config.item.model.special.missing_type", "warning.config.item.model.tint.constant.missing_value");
return new ConstantTint(parseTintValue(value));
}
}

View File

@@ -6,6 +6,7 @@ import net.momirealms.craftengine.core.registry.Holder;
import net.momirealms.craftengine.core.registry.Registries;
import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import java.util.Map;
@@ -38,10 +39,7 @@ public class Tints {
}
public static Tint fromMap(Map<String, Object> map) {
String type = (String) map.get("type");
if (type == null) {
throw new LocalizedResourceConfigException("warning.config.item.model.tint.missing_type");
}
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.item.model.tint.missing_type");
Key key = Key.withDefaultNamespace(type, "minecraft");
TintFactory factory = BuiltInRegistries.TINT_FACTORY.getValue(key);
if (factory == null) {

View File

@@ -75,16 +75,13 @@ public abstract class AbstractSoundManager implements SoundManager {
@Override
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
if (AbstractSoundManager.this.songs.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.jukebox_song.duplicate", path, id);
}
Object sound = section.get("sound");
if (sound == null) {
throw new LocalizedResourceConfigException("warning.config.jukebox_song.missing_sound", path, id);
throw new LocalizedResourceConfigException("warning.config.jukebox_song.duplicate");
}
String sound = ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("sound"), "warning.config.jukebox_song.missing_sound");
Component description = AdventureHelper.miniMessage().deserialize(section.getOrDefault("description", "").toString());
float length = ResourceConfigUtils.getAsFloat(section.get("length"), "length");
int comparatorOutput = ResourceConfigUtils.getAsInt(section.getOrDefault("comparator-output", 15), "comparator-output");
JukeboxSong song = new JukeboxSong(Key.of(sound.toString()), description, length, comparatorOutput, ResourceConfigUtils.getAsFloat(section.getOrDefault("range", 32f), "range"));
JukeboxSong song = new JukeboxSong(Key.of(sound), description, length, comparatorOutput, ResourceConfigUtils.getAsFloat(section.getOrDefault("range", 32f), "range"));
AbstractSoundManager.this.songs.put(id, song);
}
}
@@ -105,14 +102,11 @@ public abstract class AbstractSoundManager implements SoundManager {
@Override
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
if (AbstractSoundManager.this.byId.containsKey(id)) {
throw new LocalizedResourceConfigException("warning.config.sound.duplicate", path, id);
throw new LocalizedResourceConfigException("warning.config.sound.duplicate");
}
boolean replace = (boolean) section.getOrDefault("replace", false);
String subtitle = (String) section.get("subtitle");
List<?> soundList = (List<?>) section.get("sounds");
if (soundList == null) {
throw new LocalizedResourceConfigException("warning.config.sound.missing_sounds", path, id);
}
List<?> soundList = (List<?>) ResourceConfigUtils.requireNonNullOrThrow(section.get("sounds"), "warning.config.sound.missing_sounds");
List<Sound> sounds = new ArrayList<>();
for (Object sound : soundList) {
if (sound instanceof String soundPath) {

View File

@@ -1,7 +1,11 @@
package net.momirealms.craftengine.core.util;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
import java.util.Map;
import java.util.function.Supplier;
public final class ResourceConfigUtils {
private ResourceConfigUtils() {}
@@ -12,6 +16,36 @@ public final class ResourceConfigUtils {
return obj;
}
public static <T> T requireNonNullOrThrow(T obj, Supplier<LocalizedException> exceptionSupplier) {
if (obj == null)
throw exceptionSupplier.get();
return obj;
}
public static String requireNonEmptyStringOrThrow(Object obj, String node) {
Object o = requireNonNullOrThrow(obj, node);
String s = o.toString();
if (s.isEmpty()) throw new LocalizedResourceConfigException(node);
return s;
}
public static String requireNonEmptyStringOrThrow(Object obj, Supplier<LocalizedException> exceptionSupplier) {
Object o = requireNonNullOrThrow(obj, exceptionSupplier);
String s = o.toString();
if (s.isEmpty()) throw exceptionSupplier.get();
return s;
}
public static Object get(Map<String, Object> arguments, String... keys) {
for (String key : keys) {
Object value = arguments.get(key);
if (value != null) {
return value;
}
}
return null;
}
public static int getAsInt(Object o, String option) {
switch (o) {
case null -> {