From 261e5dcd5216f3f2103657ee68cc76cfc953b364 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 3 May 2025 21:11:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LegacySlimeWorldDataStorage.java | 13 ----- .../bukkit/api/CraftEngineBlocks.java | 10 ++-- .../bukkit/api/CraftEngineFurniture.java | 12 ++--- .../bukkit/block/BlockEventListener.java | 34 ++++++------ .../bukkit/block/BukkitBlockManager.java | 6 +-- .../block/FallingBlockRemoveListener.java | 10 ++-- .../block/behavior/BushBlockBehavior.java | 8 +-- .../block/behavior/CropBlockBehavior.java | 12 ++--- .../block/behavior/FallingBlockBehavior.java | 10 ++-- .../block/behavior/LeavesBlockBehavior.java | 8 +-- .../behavior/SugarCaneBlockBehavior.java | 8 +-- .../bukkit/item/BukkitItemManager.java | 2 +- .../item/recipe/RecipeEventListener.java | 2 +- .../bukkit/loot/BukkitVanillaLootManager.java | 13 ++--- .../plugin/user/BukkitServerPlayer.java | 4 +- .../core/block/ImmutableBlockState.java | 6 +-- .../core/block/behavior/BlockBehaviors.java | 2 +- .../core/block/properties/Properties.java | 2 +- .../core/font/AbstractFontManager.java | 4 +- .../core/font/EmojiParameters.java | 2 +- .../craftengine/core/item/BuildableItem.java | 2 +- .../craftengine/core/item/CustomItem.java | 2 +- .../core/item/ItemBuildContext.java | 4 +- .../core/item/behavior/ItemBehaviors.java | 4 +- .../recipe/CustomSmithingTransformRecipe.java | 2 +- .../craftengine/core/loot/LootContext.java | 4 +- .../craftengine/core/loot/LootPool.java | 10 ++-- .../craftengine/core/loot/LootTable.java | 10 ++-- .../core/loot/condition/LootCondition.java | 11 ---- .../loot/condition/LootConditionAllOf.java | 41 -------------- .../loot/condition/LootConditionAnyOf.java | 40 -------------- .../loot/condition/LootConditionFactory.java | 8 --- .../loot/condition/LootConditionFalling.java | 29 ---------- .../loot/condition/LootConditionInverted.java | 34 ------------ .../loot/condition/LootConditionRandom.java | 35 ------------ .../LootConditionSurvivesExplosion.java | 35 ------------ .../core/loot/condition/LootConditions.java | 54 ++++++++----------- .../AbstractCompositeLootEntryContainer.java | 4 +- .../entry/AbstractLootEntryContainer.java | 6 +-- .../AbstractSingleLootEntryContainer.java | 4 +- .../entry/AlternativesLootEntryContainer.java | 7 +-- .../loot/entry/ExpLootEntryContainer.java | 16 +++--- .../core/loot/entry/LootEntryContainers.java | 2 +- .../entry/SingleItemLootEntryContainer.java | 10 ++-- .../AbstractLootConditionalFunction.java | 6 +-- .../function/LootFunctionApplyBonusCount.java | 12 ++--- .../loot/function/LootFunctionDropExp.java | 16 +++--- .../function/LootFunctionExplosionDecay.java | 10 ++-- .../loot/function/LootFunctionSetCount.java | 10 ++-- .../core/loot/function/LootFunctions.java | 2 +- .../core/pack/conflict/PathContext.java | 4 +- .../pack/conflict/matcher/PathMatcher.java | 2 +- .../conflict/matcher/PathMatcherAllOf.java | 4 +- .../conflict/matcher/PathMatcherAnyOf.java | 4 +- .../conflict/matcher/PathMatcherInverted.java | 2 +- .../pack/conflict/matcher/PathMatchers.java | 2 +- .../pack/conflict/resolution/Resolutions.java | 2 +- .../core/pack/host/ResourcePackHosts.java | 2 +- .../craftengine/core/plugin/CraftEngine.java | 1 - .../config/template/TemplateArguments.java | 2 +- .../AbstractAdditionalCommonContext.java | 4 +- .../context/AbstractCommonContext.java | 11 ++-- .../{util => plugin}/context/Condition.java | 4 +- .../{util => plugin}/context/Context.java | 6 ++- .../context/ContextHolder.java | 2 +- .../{util => plugin}/context/ContextKey.java | 2 +- .../context/LazyContextParameterProvider.java | 2 +- .../context/PlayerBlockActionContext.java | 8 +-- .../context/PlayerOptionalContext.java | 8 +-- .../context/condition/AllOfCondition.java | 53 ++++++++++++++++++ .../context/condition/AnyOfCondition.java | 53 ++++++++++++++++++ .../context/condition/EmptyCondition.java | 29 ++++++++++ .../condition/EnchantmentCondition.java} | 28 +++++----- .../condition/FallingBlockCondition.java | 30 +++++++++++ .../context/condition/InvertedCondition.java | 42 +++++++++++++++ .../MatchBlockPropertyCondition.java} | 25 ++++----- .../condition/MatchItemCondition.java} | 26 ++++----- .../context/condition/RandomCondition.java | 37 +++++++++++++ .../context/condition/SharedConditions.java | 19 +++++++ .../condition/SurvivesExplosionCondition.java | 37 +++++++++++++ .../condition/TableBonusCondition.java} | 31 ++++++----- .../context}/number/FixedNumberProvider.java | 2 +- .../context}/number/NumberProvider.java | 2 +- .../number/NumberProviderFactory.java | 2 +- .../context}/number/NumberProviders.java | 4 +- .../number/UniformNumberProvider.java | 2 +- .../parameter/BlockParameterProvider.java | 6 +-- .../context/parameter/BlockParameters.java | 4 +- .../parameter/CommonParameterProvider.java | 6 +-- .../context/parameter/CommonParameters.java} | 11 ++-- .../parameter/PlayerParameterProvider.java | 6 +-- .../context/parameter/PlayerParameters.java | 4 +- .../core/plugin/gui/GuiParameters.java | 2 +- .../gui/category/ItemBrowserManagerImpl.java | 4 +- .../locale/MiniMessageTranslatorImpl.java | 2 +- .../plugin/locale/TranslationManagerImpl.java | 2 +- .../core/plugin/text/minimessage/I18NTag.java | 8 +-- .../minimessage/MiniMessageTagContext.java | 9 ---- .../text/minimessage/NamedArgumentTag.java | 12 ++--- .../core/registry/BuiltInRegistries.java | 8 +-- .../craftengine/core/registry/Registries.java | 8 +-- .../craftengine/core/util/Factory.java | 8 +++ .../momirealms/craftengine/core/util/Key.java | 1 - .../core/util/condition/AllOfCondition.java | 29 ---------- .../core/util/condition/AnyOfCondition.java | 29 ---------- .../core/util/condition/CommonConditions.java | 11 ---- .../util/condition/InvertedCondition.java | 22 -------- .../context/parameter/CommonParameters.java | 10 ---- .../core/util/os/Architecture.java | 49 ----------------- .../craftengine/core/util/os/Platform.java | 45 ---------------- 110 files changed, 630 insertions(+), 758 deletions(-) delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootCondition.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAllOf.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAnyOf.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFactory.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFalling.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionInverted.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionRandom.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionSurvivesExplosion.java rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/AbstractAdditionalCommonContext.java (90%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/AbstractCommonContext.java (71%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/Condition.java (59%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/Context.java (63%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/ContextHolder.java (98%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/ContextKey.java (93%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/LazyContextParameterProvider.java (91%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/PlayerBlockActionContext.java (69%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/PlayerOptionalContext.java (85%) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AllOfCondition.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AnyOfCondition.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EmptyCondition.java rename core/src/main/java/net/momirealms/craftengine/core/{loot/condition/LootConditionEnchantment.java => plugin/context/condition/EnchantmentCondition.java} (62%) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/FallingBlockCondition.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/InvertedCondition.java rename core/src/main/java/net/momirealms/craftengine/core/{loot/condition/LootConditionMatchBlockProperty.java => plugin/context/condition/MatchBlockPropertyCondition.java} (63%) rename core/src/main/java/net/momirealms/craftengine/core/{loot/condition/LootConditionMatchItem.java => plugin/context/condition/MatchItemCondition.java} (53%) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/RandomCondition.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SharedConditions.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SurvivesExplosionCondition.java rename core/src/main/java/net/momirealms/craftengine/core/{loot/condition/LootConditionTableBonus.java => plugin/context/condition/TableBonusCondition.java} (61%) rename core/src/main/java/net/momirealms/craftengine/core/{loot => plugin/context}/number/FixedNumberProvider.java (93%) rename core/src/main/java/net/momirealms/craftengine/core/{loot => plugin/context}/number/NumberProvider.java (82%) rename core/src/main/java/net/momirealms/craftengine/core/{loot => plugin/context}/number/NumberProviderFactory.java (66%) rename core/src/main/java/net/momirealms/craftengine/core/{loot => plugin/context}/number/NumberProviders.java (95%) rename core/src/main/java/net/momirealms/craftengine/core/{loot => plugin/context}/number/UniformNumberProvider.java (95%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/parameter/BlockParameterProvider.java (87%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/parameter/BlockParameters.java (87%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/parameter/CommonParameterProvider.java (83%) rename core/src/main/java/net/momirealms/craftengine/core/{loot/parameter/LootParameters.java => plugin/context/parameter/CommonParameters.java} (73%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/parameter/PlayerParameterProvider.java (88%) rename core/src/main/java/net/momirealms/craftengine/core/{util => plugin}/context/parameter/PlayerParameters.java (86%) delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTagContext.java create mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/Factory.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameters.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/os/Architecture.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/util/os/Platform.java diff --git a/bukkit/compatibility/legacy/src/main/java/net/momirealms/craftengine/bukkit/compatibility/legacy/slimeworld/LegacySlimeWorldDataStorage.java b/bukkit/compatibility/legacy/src/main/java/net/momirealms/craftengine/bukkit/compatibility/legacy/slimeworld/LegacySlimeWorldDataStorage.java index b4550330f..74acc1e05 100644 --- a/bukkit/compatibility/legacy/src/main/java/net/momirealms/craftengine/bukkit/compatibility/legacy/slimeworld/LegacySlimeWorldDataStorage.java +++ b/bukkit/compatibility/legacy/src/main/java/net/momirealms/craftengine/bukkit/compatibility/legacy/slimeworld/LegacySlimeWorldDataStorage.java @@ -1,7 +1,6 @@ package net.momirealms.craftengine.bukkit.compatibility.legacy.slimeworld; import com.flowpowered.nbt.ByteArrayTag; -import com.flowpowered.nbt.CompoundMap; import com.infernalsuite.aswm.api.world.SlimeChunk; import com.infernalsuite.aswm.api.world.SlimeWorld; import net.momirealms.craftengine.core.world.CEWorld; @@ -42,18 +41,6 @@ public class LegacySlimeWorldDataStorage implements WorldDataStorage { } } - private CompoundMap createOrGetDataMap(SlimeWorld world) { - Optional optionalCompoundTag = world.getExtraData().getAsCompoundTag("craftengine"); - CompoundMap ccDataMap; - if (optionalCompoundTag.isEmpty()) { - ccDataMap = new CompoundMap(); - world.getExtraData().getValue().put(new com.flowpowered.nbt.CompoundTag("customcrops", ccDataMap)); - } else { - ccDataMap = optionalCompoundTag.get().getValue(); - } - return ccDataMap; - } - @Override public void writeChunkAt(@NotNull ChunkPos pos, @NotNull CEChunk chunk, boolean immediately) { SlimeChunk slimeChunk = getWorld().getChunk(pos.x, pos.z); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java index 7b8467ea5..49a12d9ca 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineBlocks.java @@ -12,9 +12,9 @@ import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.block.UpdateOption; import net.momirealms.craftengine.core.entity.player.InteractionHand; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.World; import net.momirealms.craftengine.core.world.WorldEvents; @@ -172,11 +172,11 @@ public final class CraftEngineBlocks { Location location = block.getLocation(); Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); if (dropLoot) { - ContextHolder.Builder builder = new ContextHolder.Builder().withParameter(LootParameters.WORLD, world).withParameter(LootParameters.LOCATION, vec3d); + ContextHolder.Builder builder = new ContextHolder.Builder().withParameter(CommonParameters.WORLD, world).withParameter(CommonParameters.LOCATION, vec3d); BukkitServerPlayer serverPlayer = BukkitCraftEngine.instance().adapt(player); if (player != null) { - builder.withParameter(LootParameters.PLAYER, serverPlayer); - builder.withOptionalParameter(LootParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); + builder.withParameter(CommonParameters.PLAYER, serverPlayer); + builder.withOptionalParameter(CommonParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); } for (Item item : state.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineFurniture.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineFurniture.java index 4abf9bbab..96b537084 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineFurniture.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/api/CraftEngineFurniture.java @@ -12,9 +12,9 @@ import net.momirealms.craftengine.core.entity.furniture.CustomFurniture; import net.momirealms.craftengine.core.entity.player.InteractionHand; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootTable; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.World; import org.bukkit.Location; @@ -271,11 +271,11 @@ public final class CraftEngineFurniture { World world = new BukkitWorld(location.getWorld()); if (dropLoot && lootTable != null) { ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); if (player != null) { - builder.withParameter(LootParameters.PLAYER, player); - builder.withOptionalParameter(LootParameters.TOOL, player.getItemInHand(InteractionHand.MAIN_HAND)); + builder.withParameter(CommonParameters.PLAYER, player); + builder.withOptionalParameter(CommonParameters.TOOL, player.getItemInHand(InteractionHand.MAIN_HAND)); } List> items = lootTable.getRandomItems(builder.build(), world); for (Item item : items) { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java index 6b4dcd633..1209ed4b5 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java @@ -12,10 +12,10 @@ import net.momirealms.craftengine.core.block.properties.Property; import net.momirealms.craftengine.core.entity.player.InteractionHand; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootTable; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; import net.momirealms.craftengine.core.plugin.config.Config; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.VersionHelper; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.BlockPos; import net.momirealms.craftengine.core.world.Vec3d; import org.bukkit.*; @@ -151,10 +151,10 @@ public class BlockEventListener implements Listener { // drop items ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.WORLD, world); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.PLAYER, serverPlayer); - builder.withOptionalParameter(LootParameters.TOOL, itemInHand); + builder.withParameter(CommonParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.PLAYER, serverPlayer); + builder.withOptionalParameter(CommonParameters.TOOL, itemInHand); for (Item item : state.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } @@ -172,10 +172,10 @@ public class BlockEventListener implements Listener { net.momirealms.craftengine.core.world.World world = new BukkitWorld(player.getWorld()); Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.WORLD, world); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.PLAYER, serverPlayer); - builder.withOptionalParameter(LootParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); + builder.withParameter(CommonParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.PLAYER, serverPlayer); + builder.withOptionalParameter(CommonParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); ContextHolder contextHolder = builder.build(); for (LootTable lootTable : it.lootTables()) { for (Item item : lootTable.getRandomItems(contextHolder, world)) { @@ -214,8 +214,8 @@ public class BlockEventListener implements Listener { net.momirealms.craftengine.core.world.World world = new BukkitWorld(block.getWorld()); Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.WORLD, world); - builder.withParameter(LootParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); for (Item item : immutableBlockState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } @@ -232,8 +232,8 @@ public class BlockEventListener implements Listener { Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); net.momirealms.craftengine.core.world.World world = new BukkitWorld(location.getWorld()); ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.WORLD, world); - builder.withParameter(LootParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); ContextHolder contextHolder = builder.build(); for (LootTable lootTable : it.lootTables()) { for (Item item : lootTable.getRandomItems(contextHolder, world)) { @@ -329,10 +329,10 @@ public class BlockEventListener implements Listener { if (state != null && !state.isEmpty()) { ContextHolder.Builder builder = ContextHolder.builder(); Vec3d vec3d = Vec3d.atCenterOf(blockPos); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); if (yield < 1f) { - builder.withParameter(LootParameters.EXPLOSION_RADIUS, 1.0f / yield); + builder.withParameter(CommonParameters.EXPLOSION_RADIUS, 1.0f / yield); } for (Item item : state.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java index 74e9e5019..6142cbed6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java @@ -359,7 +359,7 @@ public class BukkitBlockManager extends AbstractBlockManager { appearances = Map.of("default", pair.right()); String internalBlock = pair.left().value() + "_" + internalId; - Key internalBlockId = Key.of(CraftEngine.NAMESPACE, internalBlock); + Key internalBlockId = Key.of(Key.DEFAULT_NAMESPACE, internalBlock); int internalBlockRegistryId = Optional.ofNullable(internalId2StateId.get(internalBlockId)).orElse(-1); if (internalBlockRegistryId == -1) { throw new LocalizedResourceConfigException("warning.config.block.state.invalid_real_id", @@ -408,7 +408,7 @@ public class BukkitBlockManager extends AbstractBlockManager { } int internalId = ResourceConfigUtils.getAsInt(variantSection.getOrDefault("id", -1), "id"); Key baseBlock = tempTypeMap.get(appearance); - Key internalBlockId = Key.of(CraftEngine.NAMESPACE, baseBlock.value() + "_" + internalId); + Key internalBlockId = Key.of(Key.DEFAULT_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", @@ -782,7 +782,7 @@ public class BukkitBlockManager extends AbstractBlockManager { } private Key createRealBlockKey(Key replacedBlock, int index) { - return Key.of(CraftEngine.NAMESPACE, replacedBlock.value() + "_" + index); + return Key.of(Key.DEFAULT_NAMESPACE, replacedBlock.value() + "_" + index); } private Object createBlockProperties(Key realBlockKey) throws Exception { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/FallingBlockRemoveListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/FallingBlockRemoveListener.java index f40a43172..1023e23c6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/FallingBlockRemoveListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/FallingBlockRemoveListener.java @@ -5,9 +5,9 @@ import net.momirealms.craftengine.bukkit.util.Reflections; import net.momirealms.craftengine.bukkit.world.BukkitWorld; import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; import net.momirealms.craftengine.core.plugin.CraftEngine; -import net.momirealms.craftengine.core.util.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.world.Vec3d; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; @@ -32,14 +32,14 @@ public class FallingBlockRemoveListener implements Listener { ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId); if (immutableBlockState == null || immutableBlockState.isEmpty()) return; ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.FALLING_BLOCK, true); + builder.withParameter(CommonParameters.FALLING_BLOCK, true); double x = Reflections.field$Entity$xo.getDouble(fallingBlockEntity); double y = Reflections.field$Entity$yo.getDouble(fallingBlockEntity); double z = Reflections.field$Entity$zo.getDouble(fallingBlockEntity); Vec3d vec3d = new Vec3d(x, y, z); net.momirealms.craftengine.core.world.World world = new BukkitWorld(fallingBlock.getWorld()); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); for (Item item : immutableBlockState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BushBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BushBlockBehavior.java index b19b7bdbf..beb24c5d2 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BushBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BushBlockBehavior.java @@ -11,12 +11,12 @@ import net.momirealms.craftengine.core.block.CustomBlock; import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.Tuple; import net.momirealms.craftengine.core.util.VersionHelper; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.BlockPos; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldEvents; @@ -71,8 +71,8 @@ public class BushBlockBehavior extends BukkitBlockBehavior { BlockPos pos = LocationUtils.fromBlockPos(blockPos); Vec3d vec3d = Vec3d.atCenterOf(pos); net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); for (Item item : previousState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java index 9228904eb..98b5dd75c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/CropBlockBehavior.java @@ -13,13 +13,13 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory; import net.momirealms.craftengine.core.block.properties.IntegerProperty; import net.momirealms.craftengine.core.block.properties.Property; 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.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviders; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.RandomUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import net.momirealms.craftengine.core.util.Tuple; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.Vec3i; import net.momirealms.craftengine.shared.block.BlockBehavior; @@ -149,8 +149,8 @@ public class CropBlockBehavior extends BushBlockBehavior { net.momirealms.craftengine.core.world.World wrappedWorld = new BukkitWorld(world); int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, 1, ThreadLocalRandom.current(), ContextHolder.builder() - .withParameter(LootParameters.WORLD, wrappedWorld) - .withParameter(LootParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z))) + .withParameter(CommonParameters.WORLD, wrappedWorld) + .withParameter(CommonParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z))) .build())); int maxAge = this.ageProperty.max; if (i > maxAge) { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java index 54b2d436a..e7d04e967 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/FallingBlockBehavior.java @@ -10,10 +10,10 @@ import net.momirealms.craftengine.core.block.CustomBlock; import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; 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.Vec3d; import net.momirealms.craftengine.shared.block.BlockBehavior; @@ -91,14 +91,14 @@ public class FallingBlockBehavior extends BukkitBlockBehavior { ImmutableBlockState immutableBlockState = BukkitBlockManager.instance().getImmutableBlockState(stateId); if (immutableBlockState == null || immutableBlockState.isEmpty()) return; ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.FALLING_BLOCK, true); + builder.withParameter(CommonParameters.FALLING_BLOCK, true); double x = Reflections.field$Entity$xo.getDouble(fallingBlockEntity); double y = Reflections.field$Entity$yo.getDouble(fallingBlockEntity); double z = Reflections.field$Entity$zo.getDouble(fallingBlockEntity); Vec3d vec3d = new Vec3d(x, y, z); net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)); - builder.withParameter(LootParameters.LOCATION, vec3d); - builder.withParameter(LootParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); for (Item item : immutableBlockState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java index 4686b022c..572ebf985 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java @@ -13,12 +13,12 @@ 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.item.Item; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; 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; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.shared.block.BlockBehavior; @@ -125,8 +125,8 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior { Vec3d vec3d = Vec3d.atCenterOf(pos); net.momirealms.craftengine.core.world.World world = new BukkitWorld(bukkitWorld); ContextHolder.Builder builder = ContextHolder.builder() - .withParameter(LootParameters.LOCATION, vec3d) - .withParameter(LootParameters.WORLD, world); + .withParameter(CommonParameters.LOCATION, vec3d) + .withParameter(CommonParameters.WORLD, world); for (Item item : immutableBlockState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java index cf1b77194..dc31b1b67 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java @@ -13,9 +13,9 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory; 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.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.*; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.BlockPos; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.WorldEvents; @@ -61,8 +61,8 @@ public class SugarCaneBlockBehavior extends BushBlockBehavior { Vec3d vec3d = Vec3d.atCenterOf(LocationUtils.fromBlockPos(blockPos)); net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)); ContextHolder.Builder builder = ContextHolder.builder() - .withParameter(LootParameters.LOCATION, vec3d) - .withParameter(LootParameters.WORLD, world); + .withParameter(CommonParameters.LOCATION, vec3d) + .withParameter(CommonParameters.WORLD, world); for (Item item : currentState.getDrops(builder, world)) { world.dropItemNaturally(vec3d, item); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java index 6dc5566af..9296dd4c5 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java @@ -28,12 +28,12 @@ import net.momirealms.craftengine.core.pack.model.select.ChargeTypeSelectPropert import net.momirealms.craftengine.core.pack.model.select.TrimMaterialSelectProperty; import net.momirealms.craftengine.core.plugin.config.Config; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; 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.WritableRegistry; import net.momirealms.craftengine.core.util.*; -import net.momirealms.craftengine.core.util.context.ContextHolder; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/RecipeEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/RecipeEventListener.java index 7bc3042f3..ecf349fb6 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/RecipeEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/RecipeEventListener.java @@ -19,13 +19,13 @@ import net.momirealms.craftengine.core.item.recipe.input.CraftingInput; import net.momirealms.craftengine.core.item.recipe.input.SingleItemInput; import net.momirealms.craftengine.core.item.recipe.input.SmithingInput; import net.momirealms.craftengine.core.plugin.config.Config; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; import net.momirealms.craftengine.core.util.AdventureHelper; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Pair; import net.momirealms.craftengine.core.util.VersionHelper; -import net.momirealms.craftengine.core.util.context.ContextHolder; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Campfire; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/loot/BukkitVanillaLootManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/loot/BukkitVanillaLootManager.java index 1bfb8cd09..db72d7a54 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/loot/BukkitVanillaLootManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/loot/BukkitVanillaLootManager.java @@ -11,13 +11,13 @@ import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.AbstractVanillaLootManager; import net.momirealms.craftengine.core.loot.LootTable; import net.momirealms.craftengine.core.loot.VanillaLoot; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; 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.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; 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.Vec3d; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -68,13 +68,14 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme net.momirealms.craftengine.core.world.World world = new BukkitWorld(entity.getWorld()); Vec3d vec3d = new Vec3d(location.getBlockX() + 0.5, location.getBlockY() + 0.5, location.getBlockZ() + 0.5); ContextHolder.Builder builder = ContextHolder.builder(); - builder.withParameter(LootParameters.WORLD, world); - builder.withParameter(LootParameters.LOCATION, vec3d); + builder.withParameter(CommonParameters.WORLD, world); + builder.withParameter(CommonParameters.LOCATION, vec3d); + // TODO Vanilla State Parameter if (VersionHelper.isOrAbove1_20_5()) { if (event.getDamageSource().getCausingEntity() instanceof Player player) { BukkitServerPlayer serverPlayer = this.plugin.adapt(player); - builder.withParameter(LootParameters.PLAYER, serverPlayer); - builder.withOptionalParameter(LootParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); + builder.withParameter(CommonParameters.PLAYER, serverPlayer); + builder.withOptionalParameter(CommonParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND)); } } ContextHolder contextHolder = builder.build(); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index a7c20f9c7..c5c54386d 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -427,8 +427,8 @@ public class BukkitServerPlayer extends Player { } else { if (VersionHelper.isOrAbove1_20_5()) { Object attributeModifier = VersionHelper.isOrAbove1_21() ? - Reflections.constructor$AttributeModifier.newInstance(KeyUtils.toResourceLocation("craftengine", "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) : - Reflections.constructor$AttributeModifier.newInstance(UUID.randomUUID(), "craftengine:custom_hardness", -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE); + Reflections.constructor$AttributeModifier.newInstance(KeyUtils.toResourceLocation(Key.DEFAULT_NAMESPACE, "custom_hardness"), -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE) : + Reflections.constructor$AttributeModifier.newInstance(UUID.randomUUID(), Key.DEFAULT_NAMESPACE + ":custom_hardness", -9999d, Reflections.instance$AttributeModifier$Operation$ADD_VALUE); Object attributeSnapshot = Reflections.constructor$ClientboundUpdateAttributesPacket$AttributeSnapshot.newInstance(Reflections.instance$Holder$Attribute$block_break_speed, 1d, Lists.newArrayList(attributeModifier)); Object newPacket = Reflections.constructor$ClientboundUpdateAttributesPacket1.newInstance(entityID(), Lists.newArrayList(attributeSnapshot)); sendPacket(newPacket, true); diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/ImmutableBlockState.java b/core/src/main/java/net/momirealms/craftengine/core/block/ImmutableBlockState.java index 4f6ca3a96..dad93e792 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/ImmutableBlockState.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/ImmutableBlockState.java @@ -4,9 +4,9 @@ import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap; import net.momirealms.craftengine.core.block.properties.Property; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootTable; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.registry.Holder; -import net.momirealms.craftengine.core.util.context.ContextHolder; import net.momirealms.craftengine.core.world.World; import net.momirealms.craftengine.shared.block.BlockBehavior; import net.momirealms.sparrow.nbt.CompoundTag; @@ -144,6 +144,6 @@ public class ImmutableBlockState extends BlockStateHolder { if (block == null) return List.of(); LootTable lootTable = (LootTable) block.lootTable(); if (lootTable == null) return List.of(); - return lootTable.getRandomItems(builder.withParameter(LootParameters.BLOCK_STATE, this).build(), world); + return lootTable.getRandomItems(builder.withParameter(CommonParameters.BLOCK_STATE, this).build(), world); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/behavior/BlockBehaviors.java b/core/src/main/java/net/momirealms/craftengine/core/block/behavior/BlockBehaviors.java index e67a96dc1..d75ffc494 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/behavior/BlockBehaviors.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/behavior/BlockBehaviors.java @@ -27,7 +27,7 @@ public class BlockBehaviors { public static BlockBehavior fromMap(CustomBlock block, @Nullable Map map) { if (map == null || map.isEmpty()) return EmptyBlockBehavior.INSTANCE; String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.block.behavior.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); BlockBehaviorFactory factory = BuiltInRegistries.BLOCK_BEHAVIOR_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.block.behavior.invalid_type", type.toString()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/properties/Properties.java b/core/src/main/java/net/momirealms/craftengine/core/block/properties/Properties.java index bf1b1c0a5..44194f07a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/properties/Properties.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/properties/Properties.java @@ -33,7 +33,7 @@ public class Properties { public static Property fromMap(String name, Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.block.state.property.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); PropertyFactory factory = BuiltInRegistries.PROPERTY_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.block.state.property.invalid_type", key.toString(), name); diff --git a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java index 76283a5b7..c8151079b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java @@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.pack.ResourceLocation; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.plugin.locale.TranslationManager; import net.momirealms.craftengine.core.util.*; -import net.momirealms.craftengine.core.util.context.ContextHolder; -import net.momirealms.craftengine.core.util.context.PlayerOptionalContext; import org.ahocorasick.trie.Token; import org.ahocorasick.trie.Trie; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/craftengine/core/font/EmojiParameters.java b/core/src/main/java/net/momirealms/craftengine/core/font/EmojiParameters.java index f3344e548..5cf91415a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/font/EmojiParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/font/EmojiParameters.java @@ -1,6 +1,6 @@ package net.momirealms.craftengine.core.font; -import net.momirealms.craftengine.core.util.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.ContextKey; public final class EmojiParameters { private EmojiParameters() {} diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/BuildableItem.java b/core/src/main/java/net/momirealms/craftengine/core/item/BuildableItem.java index 3f755d6b1..ed2e23317 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/BuildableItem.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/BuildableItem.java @@ -1,8 +1,8 @@ package net.momirealms.craftengine.core.item; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextHolder; public interface BuildableItem { diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/CustomItem.java b/core/src/main/java/net/momirealms/craftengine/core/item/CustomItem.java index 6d72163f1..af3b05eed 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/CustomItem.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/CustomItem.java @@ -3,8 +3,8 @@ package net.momirealms.craftengine.core.item; import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.item.behavior.ItemBehavior; import net.momirealms.craftengine.core.item.modifier.ItemDataModifier; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextHolder; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemBuildContext.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemBuildContext.java index fdc53f6e4..8ad1474df 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemBuildContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemBuildContext.java @@ -1,8 +1,8 @@ package net.momirealms.craftengine.core.item; import net.momirealms.craftengine.core.entity.player.Player; -import net.momirealms.craftengine.core.util.context.ContextHolder; -import net.momirealms.craftengine.core.util.context.PlayerOptionalContext; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/behavior/ItemBehaviors.java b/core/src/main/java/net/momirealms/craftengine/core/item/behavior/ItemBehaviors.java index c2217ec6a..af0524d2a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/behavior/ItemBehaviors.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/behavior/ItemBehaviors.java @@ -14,7 +14,7 @@ import java.nio.file.Path; import java.util.Map; public class ItemBehaviors { - public static final Key EMPTY = Key.from("craftengine:empty"); + public static final Key EMPTY = Key.withDefaultNamespace("empty", Key.DEFAULT_NAMESPACE); public static void register(Key key, ItemBehaviorFactory factory) { Holder.Reference holder = ((WritableRegistry) BuiltInRegistries.ITEM_BEHAVIOR_FACTORY) @@ -25,7 +25,7 @@ public class ItemBehaviors { public static ItemBehavior fromMap(Pack pack, Path path, Key id, Map map) { if (map == null || map.isEmpty()) return EmptyItemBehavior.INSTANCE; String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.item.behavior.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); ItemBehaviorFactory factory = BuiltInRegistries.ITEM_BEHAVIOR_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.item.behavior.invalid_type", type.toString()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java index 1742fcc19..5d83f7df0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/recipe/CustomSmithingTransformRecipe.java @@ -184,7 +184,7 @@ public class CustomSmithingTransformRecipe implements Recipe { if (type == null) { throw new LocalizedResourceConfigException("warning.config.recipe.smithing_transform.post_processor.missing_type"); } - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); ItemDataProcessor.Factory factory = BuiltInRegistries.SMITHING_RESULT_PROCESSOR_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.recipe.smithing_transform.post_processor.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java index c565134fd..5c14026b1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootContext.java @@ -1,7 +1,7 @@ package net.momirealms.craftengine.core.loot; -import net.momirealms.craftengine.core.util.context.AbstractCommonContext; -import net.momirealms.craftengine.core.util.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.AbstractCommonContext; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.world.World; import java.util.Random; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootPool.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootPool.java index 981093c85..28a012dc6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootPool.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootPool.java @@ -2,13 +2,13 @@ package net.momirealms.craftengine.core.loot; import com.google.common.collect.Lists; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.condition.LootConditions; import net.momirealms.craftengine.core.loot.entry.LootEntry; import net.momirealms.craftengine.core.loot.entry.LootEntryContainer; import net.momirealms.craftengine.core.loot.function.LootFunction; import net.momirealms.craftengine.core.loot.function.LootFunctions; -import net.momirealms.craftengine.core.loot.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; import net.momirealms.craftengine.core.util.MCUtils; import net.momirealms.craftengine.core.util.MutableInt; @@ -20,14 +20,14 @@ import java.util.function.Predicate; public class LootPool { private final List> entryContainers; - private final List conditions; + private final List> conditions; private final Predicate compositeCondition; private final List> functions; private final BiFunction, LootContext, Item> compositeFunction; private final NumberProvider rolls; private final NumberProvider bonusRolls; - public LootPool(List> entryContainers, List conditions, List> functions, NumberProvider rolls, NumberProvider bonusRolls) { + public LootPool(List> entryContainers, List> conditions, List> functions, NumberProvider rolls, NumberProvider bonusRolls) { this.entryContainers = entryContainers; this.conditions = conditions; this.functions = functions; @@ -38,7 +38,7 @@ public class LootPool { } public void addRandomItems(Consumer> lootConsumer, LootContext context) { - for (LootCondition condition : this.conditions) { + for (Condition condition : this.conditions) { if (!condition.test(context)) { return; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java index 152eec336..b404c7456 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/LootTable.java @@ -2,18 +2,18 @@ package net.momirealms.craftengine.core.loot; import com.google.common.collect.Lists; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.condition.LootConditions; import net.momirealms.craftengine.core.loot.entry.LootEntryContainer; import net.momirealms.craftengine.core.loot.entry.LootEntryContainers; import net.momirealms.craftengine.core.loot.function.LootFunction; import net.momirealms.craftengine.core.loot.function.LootFunctions; -import net.momirealms.craftengine.core.loot.number.NumberProvider; -import net.momirealms.craftengine.core.loot.number.NumberProviders; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.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; @@ -52,7 +52,7 @@ public class LootTable { Map pool = MiscUtils.castToMap(rawPoolMap, false); NumberProvider rolls = NumberProviders.fromObject(pool.getOrDefault("rolls", 1)); NumberProvider bonus_rolls = NumberProviders.fromObject(pool.getOrDefault("bonus_rolls", 0)); - List conditions = Optional.ofNullable(pool.get("conditions")) + List> conditions = Optional.ofNullable(pool.get("conditions")) .map(it -> LootConditions.fromMapList(castToMapListOrThrow(it, () -> new LocalizedResourceConfigException("warning.config.loot_table.invalid_conditions_type", it.getClass().getSimpleName())))) .orElse(Lists.newArrayList()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootCondition.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootCondition.java deleted file mode 100644 index 5a684a171..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootCondition.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.util.Key; - -import java.util.function.Predicate; - -public interface LootCondition extends Predicate { - - Key type(); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAllOf.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAllOf.java deleted file mode 100644 index 6496fa4aa..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAllOf.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.util.Key; - -import java.util.List; -import java.util.Map; - -public class LootConditionAllOf implements LootCondition { - public static final Factory FACTORY = new Factory(); - private final List conditions; - - public LootConditionAllOf(List conditions) { - this.conditions = conditions; - } - - @Override - public Key type() { - return LootConditions.ALL_OF; - } - - @Override - public boolean test(LootContext lootContext) { - for (LootCondition condition : conditions) { - if (!condition.test(lootContext)) { - return false; - } - } - return true; - } - - public static class Factory implements LootConditionFactory { - - @SuppressWarnings("unchecked") - @Override - public LootCondition create(Map arguments) { - List> terms = (List>) arguments.get("terms"); - return new LootConditionAllOf(LootConditions.fromMapList(terms)); - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAnyOf.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAnyOf.java deleted file mode 100644 index c7267bce6..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionAnyOf.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.util.Key; - -import java.util.List; -import java.util.Map; - -public class LootConditionAnyOf implements LootCondition { - public static final Factory FACTORY = new Factory(); - private final List conditions; - - public LootConditionAnyOf(List conditions) { - this.conditions = conditions; - } - - @Override - public Key type() { - return LootConditions.ANY_OF; - } - - @Override - public boolean test(LootContext lootContext) { - for (LootCondition condition : conditions) { - if (condition.test(lootContext)) { - return true; - } - } - return false; - } - - public static class Factory implements LootConditionFactory { - @SuppressWarnings("unchecked") - @Override - public LootCondition create(Map arguments) { - List> terms = (List>) arguments.get("terms"); - return new LootConditionAnyOf(LootConditions.fromMapList(terms)); - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFactory.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFactory.java deleted file mode 100644 index 6f8173511..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import java.util.Map; - -public interface LootConditionFactory { - - LootCondition create(Map arguments); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFalling.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFalling.java deleted file mode 100644 index b47cb29c0..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionFalling.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; -import net.momirealms.craftengine.core.util.Key; - -import java.util.Map; - -public class LootConditionFalling implements LootCondition { - public static final Factory FACTORY = new Factory(); - public static final LootConditionFalling INSTANCE = new LootConditionFalling(); - - @Override - public Key type() { - return LootConditions.FALLING_BLOCK; - } - - @Override - public boolean test(LootContext lootContext) { - return lootContext.getOptionalParameter(LootParameters.FALLING_BLOCK).orElse(false); - } - - public static class Factory implements LootConditionFactory { - @Override - public LootCondition create(Map arguments) { - return INSTANCE; - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionInverted.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionInverted.java deleted file mode 100644 index 01d89fa09..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionInverted.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.util.Key; - -import java.util.Map; - -public class LootConditionInverted implements LootCondition { - public static final Factory FACTORY = new Factory(); - private final LootCondition condition; - - public LootConditionInverted(LootCondition condition) { - this.condition = condition; - } - - @Override - public Key type() { - return LootConditions.INVERTED; - } - - @Override - public boolean test(LootContext lootContext) { - return !condition.test(lootContext); - } - - public static class Factory implements LootConditionFactory { - @SuppressWarnings("unchecked") - @Override - public LootCondition create(Map arguments) { - Map term = (Map) arguments.get("term"); - return new LootConditionInverted(LootConditions.fromMap(term)); - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionRandom.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionRandom.java deleted file mode 100644 index 77a99c196..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionRandom.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.RandomUtils; -import net.momirealms.craftengine.core.util.ResourceConfigUtils; - -import java.util.Map; - -public class LootConditionRandom implements LootCondition { - public static final Factory FACTORY = new Factory(); - private final float chance; - - public LootConditionRandom(float chance) { - this.chance = chance; - } - - @Override - public Key type() { - return LootConditions.RANDOM; - } - - @Override - public boolean test(LootContext lootContext) { - return RandomUtils.generateRandomFloat(0, 1) < this.chance; - } - - public static class Factory implements LootConditionFactory { - @Override - public LootCondition create(Map arguments) { - float chance = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("value", 0.5f), "value"); - return new LootConditionRandom(chance); - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionSurvivesExplosion.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionSurvivesExplosion.java deleted file mode 100644 index 68ae812da..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionSurvivesExplosion.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.momirealms.craftengine.core.loot.condition; - -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; -import net.momirealms.craftengine.core.util.Key; - -import java.util.Map; -import java.util.Optional; - -public class LootConditionSurvivesExplosion implements LootCondition { - public static final Factory FACTORY = new Factory(); - private static final LootConditionSurvivesExplosion INSTANCE = new LootConditionSurvivesExplosion(); - - @Override - public Key type() { - return LootConditions.SURVIVES_EXPLOSION; - } - - @Override - public boolean test(LootContext lootContext) { - Optional radius = lootContext.getOptionalParameter(LootParameters.EXPLOSION_RADIUS); - if (radius.isPresent()) { - float f = 1f / radius.get(); - return lootContext.randomSource().nextFloat() < f; - } - return true; - } - - public static class Factory implements LootConditionFactory { - @Override - public LootCondition create(Map arguments) { - return INSTANCE; - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java index d9ba14a51..8e98d73d2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditions.java @@ -1,11 +1,16 @@ package net.momirealms.craftengine.core.loot.condition; +import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.condition.*; 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; import net.momirealms.craftengine.core.registry.WritableRegistry; +import net.momirealms.craftengine.core.util.Factory; 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; @@ -14,32 +19,22 @@ import java.util.Map; import java.util.function.Predicate; public class LootConditions { - public static final Key MATCH_ITEM = Key.from("craftengine:match_item"); - public static final Key MATCH_BLOCK_PROPERTY = Key.from("craftengine:match_block_property"); - public static final Key TABLE_BONUS = Key.from("craftengine:table_bonus"); - public static final Key SURVIVES_EXPLOSION = Key.from("craftengine:survives_explosion"); - public static final Key RANDOM = Key.from("craftengine:random"); - public static final Key ANY_OF = Key.from("craftengine:any_of"); - public static final Key ALL_OF = Key.from("craftengine:all_of"); - public static final Key ENCHANTMENT = Key.from("craftengine:enchantment"); - public static final Key INVERTED = Key.from("craftengine:inverted"); - public static final Key FALLING_BLOCK = Key.from("craftengine:falling_block"); static { - register(MATCH_ITEM, LootConditionMatchItem.FACTORY); - register(MATCH_BLOCK_PROPERTY, LootConditionMatchBlockProperty.FACTORY); - register(TABLE_BONUS, LootConditionTableBonus.FACTORY); - register(SURVIVES_EXPLOSION, LootConditionSurvivesExplosion.FACTORY); - register(ANY_OF, LootConditionAnyOf.FACTORY); - register(ALL_OF, LootConditionAllOf.FACTORY); - register(ENCHANTMENT, LootConditionEnchantment.FACTORY); - register(INVERTED, LootConditionInverted.FACTORY); - register(FALLING_BLOCK, LootConditionFalling.FACTORY); - register(RANDOM, LootConditionRandom.FACTORY); + register(SharedConditions.MATCH_ITEM, new MatchItemCondition.FactoryImpl<>()); + register(SharedConditions.MATCH_BLOCK_PROPERTY, new MatchBlockPropertyCondition.FactoryImpl<>()); + register(SharedConditions.TABLE_BONUS, new TableBonusCondition.FactoryImpl<>()); + register(SharedConditions.SURVIVES_EXPLOSION, new SurvivesExplosionCondition.FactoryImpl<>()); + register(SharedConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(LootConditions::fromMap)); + register(SharedConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(LootConditions::fromMap)); + register(SharedConditions.ENCHANTMENT, new EnchantmentCondition.FactoryImpl<>()); + register(SharedConditions.INVERTED, new InvertedCondition.FactoryImpl<>(LootConditions::fromMap)); + register(SharedConditions.FALLING_BLOCK, new FallingBlockCondition.FactoryImpl<>()); + register(SharedConditions.RANDOM, new RandomCondition.FactoryImpl<>()); } - public static void register(Key key, LootConditionFactory factory) { - Holder.Reference holder = ((WritableRegistry) BuiltInRegistries.LOOT_CONDITION_FACTORY) + public static void register(Key key, Factory> factory) { + Holder.Reference>> holder = ((WritableRegistry>>) BuiltInRegistries.LOOT_CONDITION_FACTORY) .registerForHolder(new ResourceKey<>(Registries.LOOT_CONDITION_FACTORY.location(), key)); holder.bindValue(factory); } @@ -78,22 +73,19 @@ public class LootConditions { }; } - public static List fromMapList(List> mapList) { + public static List> fromMapList(List> mapList) { if (mapList == null || mapList.isEmpty()) return List.of(); - List functions = new ArrayList<>(); + List> functions = new ArrayList<>(); for (Map map : mapList) { functions.add(fromMap(map)); } return functions; } - public static LootCondition fromMap(Map map) { - String type = (String) map.get("type"); - if (type == null) { - throw new LocalizedResourceConfigException("warning.config.loot_table.condition.missing_type"); - } - Key key = Key.withDefaultNamespace(type, "craftengine"); - LootConditionFactory factory = BuiltInRegistries.LOOT_CONDITION_FACTORY.getValue(key); + public static Condition fromMap(Map map) { + String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.condition.missing_type"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); + Factory> factory = BuiltInRegistries.LOOT_CONDITION_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.condition.invalid_type", type); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractCompositeLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractCompositeLootEntryContainer.java index 76f4a57ea..c30f2407a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractCompositeLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractCompositeLootEntryContainer.java @@ -1,7 +1,7 @@ package net.momirealms.craftengine.core.loot.entry; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; +import net.momirealms.craftengine.core.plugin.context.Condition; import java.util.List; import java.util.function.Consumer; @@ -10,7 +10,7 @@ public abstract class AbstractCompositeLootEntryContainer extends AbstractLoo protected final List> children; private final LootEntryContainer composedChildren; - protected AbstractCompositeLootEntryContainer(List conditions, List> children) { + protected AbstractCompositeLootEntryContainer(List> conditions, List> children) { super(conditions); this.children = children; this.composedChildren = compose(children); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractLootEntryContainer.java index a71d1651d..7538d3f7f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractLootEntryContainer.java @@ -1,7 +1,7 @@ package net.momirealms.craftengine.core.loot.entry; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MCUtils; @@ -9,10 +9,10 @@ import java.util.List; import java.util.function.Predicate; public abstract class AbstractLootEntryContainer implements LootEntryContainer, Predicate { - protected final List conditions; + protected final List> conditions; private final Predicate compositeCondition; - protected AbstractLootEntryContainer(List conditions) { + protected AbstractLootEntryContainer(List> conditions) { this.conditions = conditions; this.compositeCondition = MCUtils.allOf(conditions); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractSingleLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractSingleLootEntryContainer.java index 86f866a29..0d57d6d39 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractSingleLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AbstractSingleLootEntryContainer.java @@ -2,9 +2,9 @@ package net.momirealms.craftengine.core.loot.entry; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.function.LootFunction; import net.momirealms.craftengine.core.loot.function.LootFunctions; +import net.momirealms.craftengine.core.plugin.context.Condition; import java.util.List; import java.util.function.BiFunction; @@ -24,7 +24,7 @@ public abstract class AbstractSingleLootEntryContainer extends AbstractLootEn } }; - protected AbstractSingleLootEntryContainer(List conditions, List> functions, int weight, int quality) { + protected AbstractSingleLootEntryContainer(List> conditions, List> functions, int weight, int quality) { super(conditions); this.weight = weight; this.quality = quality; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AlternativesLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AlternativesLootEntryContainer.java index 3c5e91f4e..9b22cbf89 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AlternativesLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/AlternativesLootEntryContainer.java @@ -1,7 +1,8 @@ package net.momirealms.craftengine.core.loot.entry; -import net.momirealms.craftengine.core.loot.condition.LootCondition; +import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.loot.condition.LootConditions; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.util.Key; import java.util.*; @@ -9,7 +10,7 @@ import java.util.*; public class AlternativesLootEntryContainer extends AbstractCompositeLootEntryContainer { public static final Factory FACTORY = new Factory<>(); - protected AlternativesLootEntryContainer(List conditions, List> children) { + protected AlternativesLootEntryContainer(List> conditions, List> children) { super(conditions, children); } @@ -42,7 +43,7 @@ public class AlternativesLootEntryContainer extends AbstractCompositeLootEntr List> containers = Optional.ofNullable(arguments.get("children")) .map(it -> (List>) new ArrayList>(LootEntryContainers.fromMapList((List>) it))) .orElse(Collections.emptyList()); - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new AlternativesLootEntryContainer<>(conditions, containers); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/ExpLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/ExpLootEntryContainer.java index 41d0d5de8..4c03b9873 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/ExpLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/ExpLootEntryContainer.java @@ -1,11 +1,11 @@ package net.momirealms.craftengine.core.loot.entry; import net.momirealms.craftengine.core.loot.LootContext; -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.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviders; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; @@ -19,7 +19,7 @@ public class ExpLootEntryContainer extends AbstractLootEntryContainer { public static final Factory FACTORY = new Factory<>(); private final NumberProvider value; - protected ExpLootEntryContainer(NumberProvider value, List conditions) { + protected ExpLootEntryContainer(NumberProvider value, List> conditions) { super(conditions); this.value = value; } @@ -32,8 +32,8 @@ public class ExpLootEntryContainer extends AbstractLootEntryContainer { @Override public boolean expand(LootContext context, Consumer> choiceConsumer) { if (super.test(context)) { - context.getOptionalParameter(LootParameters.WORLD) - .ifPresent(it -> context.getOptionalParameter(LootParameters.LOCATION).ifPresent(loc -> it.dropExp(loc.toCenter(), value.getInt(context)))); + context.getOptionalParameter(CommonParameters.WORLD) + .ifPresent(it -> context.getOptionalParameter(CommonParameters.LOCATION).ifPresent(loc -> it.dropExp(loc.toCenter(), value.getInt(context)))); return true; } else { return false; @@ -45,7 +45,7 @@ public class ExpLootEntryContainer extends AbstractLootEntryContainer { @Override public LootEntryContainer create(Map arguments) { Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.entry.exp.missing_count"); - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new ExpLootEntryContainer<>(NumberProviders.fromObject(value), conditions); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java index b9f9ce3e0..5d44629dc 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/LootEntryContainers.java @@ -42,7 +42,7 @@ public class LootEntryContainers { @SuppressWarnings("unchecked") public static LootEntryContainer fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.entry.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); LootEntryContainerFactory factory = (LootEntryContainerFactory) BuiltInRegistries.LOOT_ENTRY_CONTAINER_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.entry.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/SingleItemLootEntryContainer.java b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/SingleItemLootEntryContainer.java index 28830b557..a17fecb5b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/entry/SingleItemLootEntryContainer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/entry/SingleItemLootEntryContainer.java @@ -2,12 +2,12 @@ package net.momirealms.craftengine.core.loot.entry; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.condition.LootConditions; 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.context.Condition; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; @@ -18,7 +18,7 @@ public class SingleItemLootEntryContainer extends AbstractSingleLootEntryCont public static final Factory FACTORY = new Factory<>(); private final Key item; - protected SingleItemLootEntryContainer(Key item, List conditions, List> lootFunctions, int weight, int quality) { + protected SingleItemLootEntryContainer(Key item, List> conditions, List> lootFunctions, int weight, int quality) { super(conditions, lootFunctions, weight, quality); this.item = item; } @@ -31,7 +31,7 @@ public class SingleItemLootEntryContainer extends AbstractSingleLootEntryCont @SuppressWarnings("unchecked") @Override protected void createItem(Consumer> lootConsumer, LootContext context) { - Item tItem = (Item) CraftEngine.instance().itemManager().createWrappedItem(this.item, context.getOptionalParameter(LootParameters.PLAYER).orElse(null)); + Item tItem = (Item) CraftEngine.instance().itemManager().createWrappedItem(this.item, context.getOptionalParameter(CommonParameters.PLAYER).orElse(null)); if (tItem != null) { lootConsumer.accept(tItem); } else { @@ -47,7 +47,7 @@ public class SingleItemLootEntryContainer extends AbstractSingleLootEntryCont Key item = Key.from(itemObj); int weight = ResourceConfigUtils.getAsInt(arguments.getOrDefault("weight", 1), "weight"); int quality = ResourceConfigUtils.getAsInt(arguments.getOrDefault("quality", 0), "quality"); - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); List> functions = Optional.ofNullable(arguments.get("functions")) diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/AbstractLootConditionalFunction.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/AbstractLootConditionalFunction.java index c0de92238..89a918222 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/AbstractLootConditionalFunction.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/AbstractLootConditionalFunction.java @@ -2,17 +2,17 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.util.MCUtils; import java.util.List; import java.util.function.Predicate; public abstract class AbstractLootConditionalFunction implements LootFunction { - protected final List predicates; + protected final List> predicates; private final Predicate compositePredicates; - public AbstractLootConditionalFunction(List predicates) { + public AbstractLootConditionalFunction(List> predicates) { this.predicates = predicates; this.compositePredicates = MCUtils.allOf(predicates); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionApplyBonusCount.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionApplyBonusCount.java index 230b66eac..c8105921f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionApplyBonusCount.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionApplyBonusCount.java @@ -3,9 +3,9 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Enchantment; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.condition.LootConditions; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; import net.momirealms.craftengine.core.registry.Holder; @@ -24,7 +24,7 @@ public class LootFunctionApplyBonusCount extends AbstractLootConditionalFunct private final Key enchantment; private final Formula formula; - public LootFunctionApplyBonusCount(List predicates, Key enchantment, Formula formula) { + public LootFunctionApplyBonusCount(List> predicates, Key enchantment, Formula formula) { super(predicates); this.enchantment = enchantment; this.formula = formula; @@ -32,7 +32,7 @@ public class LootFunctionApplyBonusCount extends AbstractLootConditionalFunct @Override protected Item applyInternal(Item item, LootContext context) { - Optional> itemInHand = context.getOptionalParameter(LootParameters.TOOL); + Optional> itemInHand = context.getOptionalParameter(CommonParameters.TOOL); int level = itemInHand.map(value -> value.getEnchantment(this.enchantment).map(Enchantment::level).orElse(0)).orElse(0); int newCount = this.formula.apply(item.count(), level); item.count(newCount); @@ -54,7 +54,7 @@ public class LootFunctionApplyBonusCount extends AbstractLootConditionalFunct if (formulaMap == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.function.apply_bonus.missing_formula"); } - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new LootFunctionApplyBonusCount<>(conditions, Key.from(enchantment), Formulas.fromMap(formulaMap)); @@ -92,7 +92,7 @@ public class LootFunctionApplyBonusCount extends AbstractLootConditionalFunct if (type == null) { throw new NullPointerException("number type cannot be null"); } - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); FormulaFactory factory = BuiltInRegistries.FORMULA_FACTORY.getValue(key); if (factory == null) { throw new IllegalArgumentException("Unknown formula type: " + type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionDropExp.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionDropExp.java index 24c353736..0a1d791b3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionDropExp.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionDropExp.java @@ -2,11 +2,11 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -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.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviders; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; @@ -19,15 +19,15 @@ public class LootFunctionDropExp extends AbstractLootConditionalFunction { public static final Factory FACTORY = new Factory<>(); private final NumberProvider value; - public LootFunctionDropExp(NumberProvider value, List predicates) { + public LootFunctionDropExp(NumberProvider value, List> predicates) { super(predicates); this.value = value; } @Override protected Item applyInternal(Item item, LootContext context) { - context.getOptionalParameter(LootParameters.WORLD) - .ifPresent(it -> context.getOptionalParameter(LootParameters.LOCATION).ifPresent(loc -> it.dropExp(loc.toCenter(), value.getInt(context)))); + context.getOptionalParameter(CommonParameters.WORLD) + .ifPresent(it -> context.getOptionalParameter(CommonParameters.LOCATION).ifPresent(loc -> it.dropExp(loc.toCenter(), value.getInt(context)))); return item; } @@ -41,7 +41,7 @@ public class LootFunctionDropExp extends AbstractLootConditionalFunction { @Override public LootFunction create(Map arguments) { Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.function.drop_exp.missing_count"); - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new LootFunctionDropExp<>(NumberProviders.fromObject(value), conditions); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionExplosionDecay.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionExplosionDecay.java index 7a8c8ff61..7f0caa415 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionExplosionDecay.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionExplosionDecay.java @@ -2,9 +2,9 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.condition.LootCondition; import net.momirealms.craftengine.core.loot.condition.LootConditions; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.util.Key; import java.util.*; @@ -12,13 +12,13 @@ import java.util.*; public class LootFunctionExplosionDecay extends AbstractLootConditionalFunction { public static final Factory FACTORY = new Factory<>(); - public LootFunctionExplosionDecay(List predicates) { + public LootFunctionExplosionDecay(List> predicates) { super(predicates); } @Override protected Item applyInternal(Item item, LootContext context) { - Optional radius = context.getOptionalParameter(LootParameters.EXPLOSION_RADIUS); + Optional radius = context.getOptionalParameter(CommonParameters.EXPLOSION_RADIUS); if (radius.isPresent()) { Random random = context.randomSource(); float f = 1f / radius.get(); @@ -43,7 +43,7 @@ public class LootFunctionExplosionDecay extends AbstractLootConditionalFuncti @SuppressWarnings("unchecked") @Override public LootFunction create(Map arguments) { - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new LootFunctionExplosionDecay<>(conditions); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionSetCount.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionSetCount.java index 85aafdcc7..d0c8e92db 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionSetCount.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctionSetCount.java @@ -2,10 +2,10 @@ package net.momirealms.craftengine.core.loot.function; import net.momirealms.craftengine.core.item.Item; import net.momirealms.craftengine.core.loot.LootContext; -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.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProvider; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviders; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; @@ -20,7 +20,7 @@ public class LootFunctionSetCount extends AbstractLootConditionalFunction private final NumberProvider value; private final boolean add; - public LootFunctionSetCount(List conditions, NumberProvider value, boolean add) { + public LootFunctionSetCount(List> conditions, NumberProvider value, boolean add) { super(conditions); this.value = value; this.add = add; @@ -44,7 +44,7 @@ public class LootFunctionSetCount extends AbstractLootConditionalFunction public LootFunction create(Map arguments) { Object value = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.loot_table.function.set_count.missing_count"); boolean add = (boolean) arguments.getOrDefault("add", false); - List conditions = Optional.ofNullable(arguments.get("conditions")) + List> conditions = Optional.ofNullable(arguments.get("conditions")) .map(it -> LootConditions.fromMapList((List>) it)) .orElse(Collections.emptyList()); return new LootFunctionSetCount<>(conditions, NumberProviders.fromObject(value), add); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java index 24cdb87c7..04fcf0709 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/loot/function/LootFunctions.java @@ -70,7 +70,7 @@ public class LootFunctions { @SuppressWarnings("unchecked") public static LootFunction fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.function.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); LootFunctionFactory factory = (LootFunctionFactory) BuiltInRegistries.LOOT_FUNCTION_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.function.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/PathContext.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/PathContext.java index 05c66434f..55bdce4db 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/PathContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/PathContext.java @@ -1,7 +1,7 @@ package net.momirealms.craftengine.core.pack.conflict; -import net.momirealms.craftengine.core.util.context.AbstractCommonContext; -import net.momirealms.craftengine.core.util.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.AbstractCommonContext; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; import java.nio.file.Path; diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java index 1bb9a746e..b00efefef 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java @@ -1,7 +1,7 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.util.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Condition; public interface PathMatcher extends Condition { } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java index e98057453..7ed47270b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java @@ -1,10 +1,10 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.condition.AllOfCondition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; import net.momirealms.craftengine.core.util.MiscUtils; -import net.momirealms.craftengine.core.util.condition.AllOfCondition; -import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; import java.util.Map; diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java index efb1d584c..027d8f1b6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java @@ -1,10 +1,10 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.condition.AnyOfCondition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; import net.momirealms.craftengine.core.util.MiscUtils; -import net.momirealms.craftengine.core.util.condition.AnyOfCondition; -import net.momirealms.craftengine.core.util.context.Condition; import java.util.List; import java.util.Map; diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java index 1d5b88493..8a7b47e7f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java @@ -1,10 +1,10 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.condition.InvertedCondition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; import net.momirealms.craftengine.core.util.MiscUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils; -import net.momirealms.craftengine.core.util.condition.InvertedCondition; import java.util.Map; diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java index 7afc670bc..c9ae0edb8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java @@ -51,7 +51,7 @@ public class PathMatchers { public static PathMatcher fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type")); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); PathMatcherFactory factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(key); if (factory == null) { throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java index 86a3ae54d..b80302a07 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/Resolutions.java @@ -33,7 +33,7 @@ public class Resolutions { public static Resolution fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_resolution.missing_type")); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); ResolutionFactory factory = BuiltInRegistries.RESOLUTION_FACTORY.getValue(key); if (factory == null) { throw new LocalizedException("warning.config.conflict_resolution.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java index 8421c62c8..ccf56c684 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java @@ -45,7 +45,7 @@ public class ResourcePackHosts { if (type == null) { throw new LocalizedException("warning.config.host.missing_type"); } - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); ResourcePackHostFactory factory = BuiltInRegistries.RESOURCE_PACK_HOST_FACTORY.getValue(key); if (factory == null) { throw new LocalizedException("warning.config.host.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java index a0c9669e2..af0e3fed0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java @@ -42,7 +42,6 @@ import java.util.function.Supplier; public abstract class CraftEngine implements Plugin { public static final String MOD_CLASS = "net.momirealms.craftengine.mod.CraftEnginePlugin"; - public static final String NAMESPACE = "craftengine"; private static CraftEngine instance; protected PluginLogger logger; protected Consumer> debugger = (s) -> {}; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateArguments.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateArguments.java index a49348a04..f437a7493 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateArguments.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/config/template/TemplateArguments.java @@ -36,7 +36,7 @@ public class TemplateArguments { if (type == null) { return MapTemplateArgument.FACTORY.create(map); } else { - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); TemplateArgumentFactory factory = BuiltInRegistries.TEMPLATE_ARGUMENT_FACTORY.getValue(key); if (factory == null) { throw new IllegalArgumentException("Unknown argument type: " + type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractAdditionalCommonContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractAdditionalCommonContext.java similarity index 90% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractAdditionalCommonContext.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractAdditionalCommonContext.java index c16ffa97d..0011e6247 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractAdditionalCommonContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractAdditionalCommonContext.java @@ -1,6 +1,6 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; -import net.momirealms.craftengine.core.util.context.parameter.CommonParameterProvider; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameterProvider; import java.util.List; import java.util.Optional; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractCommonContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractCommonContext.java similarity index 71% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractCommonContext.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractCommonContext.java index cc7f85791..93332ab6d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/AbstractCommonContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/AbstractCommonContext.java @@ -1,12 +1,15 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.momirealms.craftengine.core.plugin.text.minimessage.*; +import net.momirealms.craftengine.core.plugin.text.minimessage.I18NTag; +import net.momirealms.craftengine.core.plugin.text.minimessage.ImageTag; +import net.momirealms.craftengine.core.plugin.text.minimessage.NamedArgumentTag; +import net.momirealms.craftengine.core.plugin.text.minimessage.ShiftTag; import org.jetbrains.annotations.NotNull; import java.util.Optional; -public abstract class AbstractCommonContext implements MiniMessageTagContext { +public abstract class AbstractCommonContext implements Context { protected final ContextHolder contexts; protected TagResolver[] tagResolvers; @@ -16,7 +19,7 @@ public abstract class AbstractCommonContext implements MiniMessageTagContext { @Override public ContextHolder contexts() { - return contexts; + return this.contexts; } @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/Condition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/Condition.java similarity index 59% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/Condition.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/Condition.java index 373fe4897..d2b05a7fa 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/Condition.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/Condition.java @@ -1,10 +1,10 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import net.momirealms.craftengine.core.util.Key; import java.util.function.Predicate; -public interface Condition extends Predicate { +public interface Condition extends Predicate { @Override default boolean test(CTX ctx) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/Context.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/Context.java similarity index 63% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/Context.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/Context.java index 56ff668c4..ac3e5d3fe 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/Context.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/Context.java @@ -1,4 +1,6 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; + +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import java.util.Optional; @@ -6,6 +8,8 @@ public interface Context { ContextHolder contexts(); + TagResolver[] tagResolvers(); + Optional getOptionalParameter(ContextKey parameter); T getParameterOrThrow(ContextKey parameter); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/ContextHolder.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextHolder.java similarity index 98% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/ContextHolder.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextHolder.java index 718dd54de..c14652f7e 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/ContextHolder.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextHolder.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import com.google.common.collect.ImmutableMap; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/ContextKey.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextKey.java similarity index 93% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/ContextKey.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextKey.java index 4c690da88..4d5529baf 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/ContextKey.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/ContextKey.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import net.momirealms.craftengine.core.util.Key; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/LazyContextParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/LazyContextParameterProvider.java similarity index 91% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/LazyContextParameterProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/LazyContextParameterProvider.java index 796df1230..0758f7770 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/LazyContextParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/LazyContextParameterProvider.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import java.util.Optional; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerBlockActionContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerBlockActionContext.java similarity index 69% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerBlockActionContext.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerBlockActionContext.java index 5adea9974..bbabeb79a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerBlockActionContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerBlockActionContext.java @@ -1,9 +1,9 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import net.momirealms.craftengine.core.entity.player.Player; -import net.momirealms.craftengine.core.util.context.parameter.BlockParameterProvider; -import net.momirealms.craftengine.core.util.context.parameter.CommonParameterProvider; -import net.momirealms.craftengine.core.util.context.parameter.PlayerParameterProvider; +import net.momirealms.craftengine.core.plugin.context.parameter.BlockParameterProvider; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameterProvider; +import net.momirealms.craftengine.core.plugin.context.parameter.PlayerParameterProvider; import net.momirealms.craftengine.core.world.BlockInWorld; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerOptionalContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerOptionalContext.java similarity index 85% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerOptionalContext.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerOptionalContext.java index fec8f3c0c..2071848ce 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/PlayerOptionalContext.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/PlayerOptionalContext.java @@ -1,16 +1,16 @@ -package net.momirealms.craftengine.core.util.context; +package net.momirealms.craftengine.core.plugin.context; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameterProvider; +import net.momirealms.craftengine.core.plugin.context.parameter.PlayerParameterProvider; import net.momirealms.craftengine.core.plugin.text.minimessage.*; -import net.momirealms.craftengine.core.util.context.parameter.CommonParameterProvider; -import net.momirealms.craftengine.core.util.context.parameter.PlayerParameterProvider; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class PlayerOptionalContext extends AbstractAdditionalCommonContext implements MiniMessageTagContext { +public class PlayerOptionalContext extends AbstractAdditionalCommonContext implements Context { public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY); private final Player player; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AllOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AllOfCondition.java new file mode 100644 index 000000000..eee327cc9 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AllOfCondition.java @@ -0,0 +1,53 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public class AllOfCondition implements Condition { + protected final List> conditions; + + public AllOfCondition(List> conditions) { + this.conditions = conditions; + } + + @Override + public boolean test(CTX ctx) { + for (Condition condition : conditions) { + if (!condition.test(ctx)) { + return false; + } + } + return true; + } + + @Override + public Key type() { + return SharedConditions.ALL_OF; + } + + public static class FactoryImpl implements Factory> { + private final Function, Condition> factory; + + public FactoryImpl(Function, Condition> factory) { + this.factory = factory; + } + + @SuppressWarnings("unchecked") + @Override + public Condition create(Map arguments) { + List> terms = (List>) arguments.get("terms"); + List> conditions = new ArrayList<>(); + for (Map term : terms) { + conditions.add(factory.apply(term)); + } + return new AllOfCondition<>(conditions); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AnyOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AnyOfCondition.java new file mode 100644 index 000000000..49a279bb7 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/AnyOfCondition.java @@ -0,0 +1,53 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +public class AnyOfCondition implements Condition { + protected final List> conditions; + + public AnyOfCondition(List> conditions) { + this.conditions = conditions; + } + + @Override + public boolean test(CTX ctx) { + for (Condition condition : conditions) { + if (condition.test(ctx)) { + return true; + } + } + return false; + } + + @Override + public Key type() { + return SharedConditions.ANY_OF; + } + + public static class FactoryImpl implements Factory> { + private final Function, Condition> factory; + + public FactoryImpl(Function, Condition> factory) { + this.factory = factory; + } + + @SuppressWarnings("unchecked") + @Override + public Condition create(Map arguments) { + List> terms = (List>) arguments.get("terms"); + List> conditions = new ArrayList<>(); + for (Map term : terms) { + conditions.add(factory.apply(term)); + } + return new AnyOfCondition<>(conditions); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EmptyCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EmptyCondition.java new file mode 100644 index 000000000..42bc2e520 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EmptyCondition.java @@ -0,0 +1,29 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; + +import java.util.Map; + +public class EmptyCondition implements Condition { + + @Override + public Key type() { + return SharedConditions.EMPTY; + } + + @Override + public boolean test(CTX ctx) { + return true; + } + + public static class FactoryImpl implements Factory> { + + @Override + public Condition create(Map arguments) { + return new EmptyCondition<>(); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionEnchantment.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EnchantmentCondition.java similarity index 62% rename from core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionEnchantment.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EnchantmentCondition.java index 16e861b4c..8df501f88 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionEnchantment.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/EnchantmentCondition.java @@ -1,42 +1,44 @@ -package net.momirealms.craftengine.core.loot.condition; +package net.momirealms.craftengine.core.plugin.context.condition; import net.momirealms.craftengine.core.item.Enchantment; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import java.util.Map; import java.util.Optional; import java.util.function.Function; -public class LootConditionEnchantment implements LootCondition { - public static final Factory FACTORY = new Factory(); +public class EnchantmentCondition implements Condition { private final Key id; private final Function expression; - public LootConditionEnchantment(Key id, Function expression) { - this.id = id; + public EnchantmentCondition(Key id, Function expression) { this.expression = expression; + this.id = id; } @Override public Key type() { - return LootConditions.ENCHANTMENT; + return SharedConditions.ENCHANTMENT; } @Override - public boolean test(LootContext lootContext) { - Optional> item = lootContext.getOptionalParameter(LootParameters.TOOL); + public boolean test(CTX ctx) { + Optional> item = ctx.getOptionalParameter(CommonParameters.TOOL); if (item.isEmpty()) return false; Optional enchantment = item.get().getEnchantment(id); int level = enchantment.map(Enchantment::level).orElse(0); return this.expression.apply(level); } - public static class Factory implements LootConditionFactory { + public static class FactoryImpl implements Factory> { + @Override - public LootCondition create(Map arguments) { + public Condition create(Map arguments) { String predicate = (String) arguments.get("predicate"); String[] split = predicate.split("(<=|>=|<|>|==|=)", 2); int level = Integer.parseInt(split[1]); @@ -50,7 +52,7 @@ public class LootConditionEnchantment implements LootCondition { case ">=" -> expression = (i -> i >= level); default -> throw new IllegalArgumentException("Unknown operator: " + operator); } - return new LootConditionEnchantment(Key.of(split[0]), expression); + return new EnchantmentCondition<>(Key.of(split[0]), expression); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/FallingBlockCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/FallingBlockCondition.java new file mode 100644 index 000000000..a4ee999f4 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/FallingBlockCondition.java @@ -0,0 +1,30 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; + +import java.util.Map; + +public class FallingBlockCondition implements Condition { + + @Override + public Key type() { + return SharedConditions.FALLING_BLOCK; + } + + @Override + public boolean test(CTX ctx) { + return ctx.getOptionalParameter(CommonParameters.FALLING_BLOCK).orElse(false); + } + + public static class FactoryImpl implements Factory> { + + @Override + public Condition create(Map arguments) { + return new FallingBlockCondition<>(); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/InvertedCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/InvertedCondition.java new file mode 100644 index 000000000..bc5c85b01 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/InvertedCondition.java @@ -0,0 +1,42 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; + +import java.util.Map; +import java.util.function.Function; + +public class InvertedCondition implements Condition { + protected final Condition condition; + + public InvertedCondition(Condition condition) { + this.condition = condition; + } + + @Override + public boolean test(CTX ctx) { + return !this.condition.test(ctx); + } + + @Override + public Key type() { + return SharedConditions.INVERTED; + } + + public static class FactoryImpl implements Factory> { + private final Function, Condition> factory; + + public FactoryImpl(Function, Condition> factory) { + this.factory = factory; + } + + @SuppressWarnings("unchecked") + @Override + public Condition create(Map arguments) { + Map term = (Map) arguments.get("term"); + return new InvertedCondition<>(this.factory.apply(term)); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchBlockProperty.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockPropertyCondition.java similarity index 63% rename from core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchBlockProperty.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockPropertyCondition.java index c3a30b8f4..e7381ae5d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchBlockProperty.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchBlockPropertyCondition.java @@ -1,9 +1,11 @@ -package net.momirealms.craftengine.core.loot.condition; +package net.momirealms.craftengine.core.plugin.context.condition; import net.momirealms.craftengine.core.block.CustomBlock; import net.momirealms.craftengine.core.block.properties.Property; -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.Pair; @@ -12,22 +14,21 @@ import java.util.List; import java.util.Locale; import java.util.Map; -public class LootConditionMatchBlockProperty implements LootCondition { - public static final Factory FACTORY = new Factory(); +public class MatchBlockPropertyCondition implements Condition { private final List> properties; - public LootConditionMatchBlockProperty(List> properties) { + public MatchBlockPropertyCondition(List> properties) { this.properties = properties; } @Override public Key type() { - return LootConditions.MATCH_BLOCK_PROPERTY; + return SharedConditions.MATCH_BLOCK_PROPERTY; } @Override - public boolean test(LootContext lootContext) { - return lootContext.getOptionalParameter(LootParameters.BLOCK_STATE).map(state -> { + public boolean test(CTX ctx) { + return ctx.getOptionalParameter(CommonParameters.BLOCK_STATE).map(state -> { CustomBlock block = state.owner().value(); for (Pair property : this.properties) { Property propertyIns = block.getProperty(property.left()); @@ -42,11 +43,11 @@ public class LootConditionMatchBlockProperty implements LootCondition { }).orElse(false); } - public static class Factory implements LootConditionFactory { + public static class FactoryImpl implements Factory> { @SuppressWarnings("unchecked") @Override - public LootCondition create(Map arguments) { + public Condition create(Map arguments) { Map properties = (Map) arguments.get("properties"); if (properties == null) { throw new IllegalArgumentException("Missing 'properties' argument for 'match_block_property'"); @@ -55,7 +56,7 @@ public class LootConditionMatchBlockProperty implements LootCondition { for (Map.Entry entry : properties.entrySet()) { propertyList.add(new Pair<>(entry.getKey(), entry.getValue().toString())); } - return new LootConditionMatchBlockProperty(propertyList); + return new MatchBlockPropertyCondition<>(propertyList); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchItem.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchItemCondition.java similarity index 53% rename from core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchItem.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchItemCondition.java index c2b4c4c2b..11e2180b8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionMatchItem.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/MatchItemCondition.java @@ -1,31 +1,32 @@ -package net.momirealms.craftengine.core.loot.condition; +package net.momirealms.craftengine.core.plugin.context.condition; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import java.util.*; -public class LootConditionMatchItem implements LootCondition { - public static final Factory FACTORY = new Factory(); +public class MatchItemCondition implements Condition { private final Set ids; private final boolean regexMatch; - public LootConditionMatchItem(Collection ids, boolean regexMatch) { + public MatchItemCondition(Collection ids, boolean regexMatch) { this.ids = new HashSet<>(ids); this.regexMatch = regexMatch; } @Override public Key type() { - return LootConditions.MATCH_ITEM; + return SharedConditions.MATCH_ITEM; } @Override - public boolean test(LootContext lootContext) { - Optional> item = lootContext.getOptionalParameter(LootParameters.TOOL); + public boolean test(CTX ctx) { + Optional> item = ctx.getOptionalParameter(CommonParameters.TOOL); if (item.isEmpty()) return false; Key key = item.get().id(); String itemId = key.toString(); @@ -41,12 +42,13 @@ public class LootConditionMatchItem implements LootCondition { return false; } - public static class Factory implements LootConditionFactory { + public static class FactoryImpl implements Factory> { + @Override - public LootCondition create(Map arguments) { + public Condition create(Map arguments) { List ids = MiscUtils.getAsStringList(arguments.get("id")); boolean regex = (boolean) arguments.getOrDefault("regex", false); - return new LootConditionMatchItem(ids, regex); + return new MatchItemCondition<>(ids, regex); } } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/RandomCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/RandomCondition.java new file mode 100644 index 000000000..21fe97429 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/RandomCondition.java @@ -0,0 +1,37 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.RandomUtils; +import net.momirealms.craftengine.core.util.ResourceConfigUtils; + +import java.util.Map; + +public class RandomCondition implements Condition { + private final float chance; + + public RandomCondition(float chance) { + this.chance = chance; + } + + @Override + public Key type() { + return SharedConditions.RANDOM; + } + + @Override + public boolean test(CTX ctx) { + return RandomUtils.generateRandomFloat(0, 1) < this.chance; + } + + public static class FactoryImpl implements Factory> { + + @Override + public Condition create(Map arguments) { + float provider = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("value", 0.5f), "value"); + return new RandomCondition<>(provider); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SharedConditions.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SharedConditions.java new file mode 100644 index 000000000..67fee2254 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SharedConditions.java @@ -0,0 +1,19 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.util.Key; + +public final class SharedConditions { + private SharedConditions() {} + + public static final Key EMPTY = Key.of("craftengine:empty"); + public static final Key ALL_OF = Key.of("craftengine:all_of"); + public static final Key ANY_OF = Key.of("craftengine:any_of"); + public static final Key INVERTED = Key.of("craftengine:inverted"); + public static final Key MATCH_ITEM = Key.of("craftengine:match_item"); + public static final Key MATCH_BLOCK_PROPERTY = Key.from("craftengine:match_block_property"); + public static final Key TABLE_BONUS = Key.from("craftengine:table_bonus"); + public static final Key SURVIVES_EXPLOSION = Key.from("craftengine:survives_explosion"); + public static final Key RANDOM = Key.from("craftengine:random"); + public static final Key ENCHANTMENT = Key.from("craftengine:enchantment"); + public static final Key FALLING_BLOCK = Key.from("craftengine:falling_block"); +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SurvivesExplosionCondition.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SurvivesExplosionCondition.java new file mode 100644 index 000000000..f7f97e135 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/SurvivesExplosionCondition.java @@ -0,0 +1,37 @@ +package net.momirealms.craftengine.core.plugin.context.condition; + +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; +import net.momirealms.craftengine.core.util.Factory; +import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.RandomUtils; + +import java.util.Map; +import java.util.Optional; + +public class SurvivesExplosionCondition implements Condition { + + @Override + public Key type() { + return SharedConditions.SURVIVES_EXPLOSION; + } + + @Override + public boolean test(CTX ctx) { + Optional radius = ctx.getOptionalParameter(CommonParameters.EXPLOSION_RADIUS); + if (radius.isPresent()) { + float f = 1f / radius.get(); + return RandomUtils.generateRandomFloat(0, 1) < f; + } + return true; + } + + public static class FactoryImpl implements Factory> { + + @Override + public Condition create(Map arguments) { + return new SurvivesExplosionCondition<>(); + } + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionTableBonus.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/TableBonusCondition.java similarity index 61% rename from core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionTableBonus.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/TableBonusCondition.java index e17179ebc..b1e44389d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/condition/LootConditionTableBonus.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/condition/TableBonusCondition.java @@ -1,11 +1,14 @@ -package net.momirealms.craftengine.core.loot.condition; +package net.momirealms.craftengine.core.plugin.context.condition; import net.momirealms.craftengine.core.item.Enchantment; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.loot.LootContext; -import net.momirealms.craftengine.core.loot.parameter.LootParameters; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.RandomUtils; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.ArrayList; @@ -13,32 +16,32 @@ import java.util.List; import java.util.Map; import java.util.Optional; -public class LootConditionTableBonus implements LootCondition { - public static final Factory FACTORY = new Factory(); +public class TableBonusCondition implements Condition { private final Key enchantmentType; private final List values; - public LootConditionTableBonus(Key enchantmentType, List values) { + public TableBonusCondition(Key enchantmentType, List values) { this.enchantmentType = enchantmentType; this.values = values; } @Override public Key type() { - return LootConditions.TABLE_BONUS; + return SharedConditions.TABLE_BONUS; } @Override - public boolean test(LootContext lootContext) { - Optional> item = lootContext.getOptionalParameter(LootParameters.TOOL); + public boolean test(CTX ctx) { + Optional> item = ctx.getOptionalParameter(CommonParameters.TOOL); int level = item.map(value -> value.getEnchantment(this.enchantmentType).map(Enchantment::level).orElse(0)).orElse(0); float f = this.values.get(Math.min(level, this.values.size() - 1)); - return lootContext.randomSource().nextFloat() < f; + return RandomUtils.generateRandomFloat(0, 1) < f; } - public static class Factory implements LootConditionFactory { + public static class FactoryImpl implements Factory> { + @Override - public LootCondition create(Map arguments) { + public Condition create(Map arguments) { Object enchantmentObj = arguments.get("enchantment"); if (enchantmentObj == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.condition.table_bonus.missing_enchantment"); @@ -47,13 +50,13 @@ public class LootConditionTableBonus implements LootCondition { Object chances = arguments.get("chances"); if (chances != null) { if (chances instanceof Number number) { - return new LootConditionTableBonus(enchantmentType, List.of(number.floatValue())); + return new TableBonusCondition<>(enchantmentType, List.of(number.floatValue())); } else if (chances instanceof List list) { List values = new ArrayList<>(list.size()); for (Object o : list) { values.add(ResourceConfigUtils.getAsFloat(o, "chances")); } - return new LootConditionTableBonus(enchantmentType, values); + return new TableBonusCondition<>(enchantmentType, values); } } throw new LocalizedResourceConfigException("warning.config.loot_table.condition.table_bonus.missing_chances"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/number/FixedNumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java similarity index 93% rename from core/src/main/java/net/momirealms/craftengine/core/loot/number/FixedNumberProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java index 653bd3825..fcf8703bd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/number/FixedNumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.loot.number; +package net.momirealms.craftengine.core.plugin.context.number; import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.util.Key; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java similarity index 82% rename from core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java index 80352d2af..3d23c3cd3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.loot.number; +package net.momirealms.craftengine.core.plugin.context.number; import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.util.Key; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviderFactory.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviderFactory.java similarity index 66% rename from core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviderFactory.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviderFactory.java index cc163082e..0093dfcde 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviderFactory.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviderFactory.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.loot.number; +package net.momirealms.craftengine.core.plugin.context.number; import java.util.Map; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviders.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java similarity index 95% rename from core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviders.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java index 32af65b44..162e25bff 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/number/NumberProviders.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.loot.number; +package net.momirealms.craftengine.core.plugin.context.number; import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException; import net.momirealms.craftengine.core.registry.BuiltInRegistries; @@ -39,7 +39,7 @@ public class NumberProviders { public static NumberProvider fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.number.missing_type"); - Key key = Key.withDefaultNamespace(type, "craftengine"); + Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); NumberProviderFactory factory = BuiltInRegistries.NUMBER_PROVIDER_FACTORY.getValue(key); if (factory == null) { throw new LocalizedResourceConfigException("warning.config.loot_table.number.invalid_type", type); diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/number/UniformNumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java similarity index 95% rename from core/src/main/java/net/momirealms/craftengine/core/loot/number/UniformNumberProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java index b294daea1..aac5be744 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/number/UniformNumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java @@ -1,4 +1,4 @@ -package net.momirealms.craftengine.core.loot.number; +package net.momirealms.craftengine.core.plugin.context.number; import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.util.Key; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameterProvider.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameterProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameterProvider.java index 8d28fd0fa..50107633d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameterProvider.java @@ -1,7 +1,7 @@ -package net.momirealms.craftengine.core.util.context.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; -import net.momirealms.craftengine.core.util.context.ContextKey; -import net.momirealms.craftengine.core.util.context.LazyContextParameterProvider; +import net.momirealms.craftengine.core.plugin.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.LazyContextParameterProvider; import net.momirealms.craftengine.core.world.BlockInWorld; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameters.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameters.java similarity index 87% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameters.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameters.java index 2e0edaeb0..68d2988b8 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/BlockParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/BlockParameters.java @@ -1,8 +1,8 @@ -package net.momirealms.craftengine.core.util.context.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; import net.momirealms.craftengine.core.block.ImmutableBlockState; +import net.momirealms.craftengine.core.plugin.context.ContextKey; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextKey; public final class BlockParameters { private BlockParameters() {} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameterProvider.java similarity index 83% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameterProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameterProvider.java index 396bbdfdd..de5df90c1 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameterProvider.java @@ -1,8 +1,8 @@ -package net.momirealms.craftengine.core.util.context.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; +import net.momirealms.craftengine.core.plugin.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.LazyContextParameterProvider; import net.momirealms.craftengine.core.util.RandomUtils; -import net.momirealms.craftengine.core.util.context.ContextKey; -import net.momirealms.craftengine.core.util.context.LazyContextParameterProvider; import java.util.HashMap; import java.util.Map; diff --git a/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameters.java similarity index 73% rename from core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameters.java index abe27d435..d9e59c0c7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/loot/parameter/LootParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/CommonParameters.java @@ -1,15 +1,18 @@ -package net.momirealms.craftengine.core.loot.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; import net.momirealms.craftengine.core.block.ImmutableBlockState; import net.momirealms.craftengine.core.entity.Entity; import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.item.Item; -import net.momirealms.craftengine.core.util.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.ContextKey; import net.momirealms.craftengine.core.world.Vec3d; import net.momirealms.craftengine.core.world.World; -public final class LootParameters { - private LootParameters() {} +public final class CommonParameters { + private CommonParameters() {} + + public static final ContextKey RANDOM = ContextKey.of("random"); + public static final ContextKey LAST_RANDOM = ContextKey.of("last_random"); public static final ContextKey LOCATION = ContextKey.of("location"); public static final ContextKey WORLD = ContextKey.of("world"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameterProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java similarity index 88% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameterProvider.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java index ca2040f86..d79f10448 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameterProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameterProvider.java @@ -1,10 +1,10 @@ -package net.momirealms.craftengine.core.util.context.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; import net.momirealms.craftengine.core.entity.Entity; import net.momirealms.craftengine.core.entity.player.Player; +import net.momirealms.craftengine.core.plugin.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.LazyContextParameterProvider; import net.momirealms.craftengine.core.util.MCUtils; -import net.momirealms.craftengine.core.util.context.ContextKey; -import net.momirealms.craftengine.core.util.context.LazyContextParameterProvider; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameters.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameters.java similarity index 86% rename from core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameters.java rename to core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameters.java index 0604f864d..68d5fe9a5 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/PlayerParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/parameter/PlayerParameters.java @@ -1,6 +1,6 @@ -package net.momirealms.craftengine.core.util.context.parameter; +package net.momirealms.craftengine.core.plugin.context.parameter; -import net.momirealms.craftengine.core.util.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.ContextKey; import java.util.UUID; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/GuiParameters.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/GuiParameters.java index 283b42f9a..946cbf505 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/GuiParameters.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/GuiParameters.java @@ -1,6 +1,6 @@ package net.momirealms.craftengine.core.plugin.gui; -import net.momirealms.craftengine.core.util.context.ContextKey; +import net.momirealms.craftengine.core.plugin.context.ContextKey; public class GuiParameters { public static final ContextKey MAX_PAGE = ContextKey.of("max_page"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java index 60dd2120f..b4669e24b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/gui/category/ItemBrowserManagerImpl.java @@ -9,6 +9,8 @@ import net.momirealms.craftengine.core.pack.LoadingSequence; import net.momirealms.craftengine.core.pack.Pack; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser; +import net.momirealms.craftengine.core.plugin.context.ContextHolder; +import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; import net.momirealms.craftengine.core.plugin.gui.*; import net.momirealms.craftengine.core.plugin.gui.Ingredient; import net.momirealms.craftengine.core.registry.Holder; @@ -16,8 +18,6 @@ import net.momirealms.craftengine.core.util.AdventureHelper; import net.momirealms.craftengine.core.util.Key; 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.util.context.PlayerOptionalContext; import java.nio.file.Path; import java.util.*; diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MiniMessageTranslatorImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MiniMessageTranslatorImpl.java index d5da280c8..d096d47ca 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MiniMessageTranslatorImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/MiniMessageTranslatorImpl.java @@ -18,7 +18,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; public class MiniMessageTranslatorImpl implements MiniMessageTranslator { - private static final Key NAME = Key.key("craftengine", "main"); + private static final Key NAME = Key.key(net.momirealms.craftengine.core.util.Key.DEFAULT_NAMESPACE, "main"); static final MiniMessageTranslatorImpl INSTANCE = new MiniMessageTranslatorImpl(); final TranslatableComponentRenderer renderer = TranslatableComponentRenderer.usingTranslationSource(this); private final Set sources = Collections.newSetFromMap(new ConcurrentHashMap<>()); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/TranslationManagerImpl.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/TranslationManagerImpl.java index 1d540278e..dbbcdd70c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/TranslationManagerImpl.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/locale/TranslationManagerImpl.java @@ -93,7 +93,7 @@ public class TranslationManagerImpl implements TranslationManager { this.plugin.saveResource("translations/" + lang + ".yml"); } - this.registry = MiniMessageTranslationRegistry.create(Key.key("craftengine", "main"), AdventureHelper.miniMessage()); + this.registry = MiniMessageTranslationRegistry.create(Key.key(net.momirealms.craftengine.core.util.Key.DEFAULT_NAMESPACE, "main"), AdventureHelper.miniMessage()); this.registry.defaultLocale(DEFAULT_LOCALE); this.loadFromFileSystem(this.translationsDirectory, false); MiniMessageTranslator.translator().addSource(this.registry); diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/I18NTag.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/I18NTag.java index 2887e7338..920796809 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/I18NTag.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/I18NTag.java @@ -1,24 +1,24 @@ package net.momirealms.craftengine.core.plugin.text.minimessage; -import net.kyori.adventure.text.minimessage.Context; import net.kyori.adventure.text.minimessage.ParsingException; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.plugin.locale.TranslationManager; import net.momirealms.craftengine.core.util.AdventureHelper; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class I18NTag implements TagResolver { - private final MiniMessageTagContext context; + private final Context context; - public I18NTag(MiniMessageTagContext context) { + public I18NTag(Context context) { this.context = context; } @Override - public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException { + public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull net.kyori.adventure.text.minimessage.Context ctx) throws ParsingException { if (!this.has(name)) { return null; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTagContext.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTagContext.java deleted file mode 100644 index 17234aae0..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/MiniMessageTagContext.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.momirealms.craftengine.core.plugin.text.minimessage; - -import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; -import net.momirealms.craftengine.core.util.context.Context; - -public interface MiniMessageTagContext extends Context { - - TagResolver[] tagResolvers(); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/NamedArgumentTag.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/NamedArgumentTag.java index 548484c28..c59067f59 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/NamedArgumentTag.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/text/minimessage/NamedArgumentTag.java @@ -1,13 +1,13 @@ package net.momirealms.craftengine.core.plugin.text.minimessage; -import net.kyori.adventure.text.minimessage.Context; import net.kyori.adventure.text.minimessage.ParsingException; import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import net.momirealms.craftengine.core.plugin.context.Context; +import net.momirealms.craftengine.core.plugin.context.ContextKey; import net.momirealms.craftengine.core.util.AdventureHelper; import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.ContextKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,19 +18,19 @@ public class NamedArgumentTag implements TagResolver { private static final String NAME_0 = "argument"; private static final String NAME_1 = "arg"; - private final MiniMessageTagContext context; + private final Context context; - public NamedArgumentTag(@NotNull MiniMessageTagContext context) { + public NamedArgumentTag(@NotNull Context context) { this.context = Objects.requireNonNull(context, "context holder"); } @Override - public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException { + public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull net.kyori.adventure.text.minimessage.Context ctx) throws ParsingException { if (!has(name)) { return null; } String argumentKey = arguments.popOr("No argument key provided").toString(); - ContextKey key = ContextKey.of(Key.withDefaultNamespace(argumentKey, "craftengine")); + ContextKey key = ContextKey.of(Key.withDefaultNamespace(argumentKey, Key.DEFAULT_NAMESPACE)); Optional optional = this.context.getOptionalParameter(key); if (optional.isEmpty()) { throw ctx.newException("Invalid argument key", arguments); diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java index e3333d608..78f295dd7 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java @@ -7,11 +7,10 @@ import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory; import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory; import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe; import net.momirealms.craftengine.core.item.recipe.RecipeFactory; -import net.momirealms.craftengine.core.loot.condition.LootConditionFactory; +import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory; import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount; import net.momirealms.craftengine.core.loot.function.LootFunctionFactory; -import net.momirealms.craftengine.core.loot.number.NumberProviderFactory; import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory; import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionFactory; import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; @@ -22,6 +21,9 @@ import net.momirealms.craftengine.core.pack.model.select.SelectPropertyFactory; import net.momirealms.craftengine.core.pack.model.special.SpecialModelFactory; import net.momirealms.craftengine.core.pack.model.tint.TintFactory; import net.momirealms.craftengine.core.plugin.config.template.TemplateArgumentFactory; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviderFactory; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceKey; @@ -31,7 +33,7 @@ public class BuiltInRegistries { public static final Registry PROPERTY_FACTORY = createRegistry(Registries.PROPERTY_FACTORY); public static final Registry BLOCK_BEHAVIOR_FACTORY = createRegistry(Registries.BLOCK_BEHAVIOR_FACTORY); public static final Registry> LOOT_FUNCTION_FACTORY = createRegistry(Registries.LOOT_FUNCTION_FACTORY); - public static final Registry LOOT_CONDITION_FACTORY = createRegistry(Registries.LOOT_CONDITION_FACTORY); + public static final Registry>> LOOT_CONDITION_FACTORY = createRegistry(Registries.LOOT_CONDITION_FACTORY); public static final Registry> LOOT_ENTRY_CONTAINER_FACTORY = createRegistry(Registries.LOOT_ENTRY_CONTAINER_FACTORY); public static final Registry NUMBER_PROVIDER_FACTORY = createRegistry(Registries.NUMBER_PROVIDER_FACTORY); public static final Registry ITEM_BEHAVIOR_FACTORY = createRegistry(Registries.ITEM_BEHAVIOR_FACTORY); diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java index 0071569c5..06225b41c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java @@ -7,11 +7,10 @@ import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory; import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory; import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe; import net.momirealms.craftengine.core.item.recipe.RecipeFactory; -import net.momirealms.craftengine.core.loot.condition.LootConditionFactory; +import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory; import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount; import net.momirealms.craftengine.core.loot.function.LootFunctionFactory; -import net.momirealms.craftengine.core.loot.number.NumberProviderFactory; import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory; import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionFactory; import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; @@ -22,6 +21,9 @@ import net.momirealms.craftengine.core.pack.model.select.SelectPropertyFactory; import net.momirealms.craftengine.core.pack.model.special.SpecialModelFactory; import net.momirealms.craftengine.core.pack.model.tint.TintFactory; import net.momirealms.craftengine.core.plugin.config.template.TemplateArgumentFactory; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.number.NumberProviderFactory; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceKey; @@ -34,7 +36,7 @@ public class Registries { public static final ResourceKey> ITEM_BEHAVIOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_behavior_factory")); public static final ResourceKey>> LOOT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_function_factory")); public static final ResourceKey>> LOOT_ENTRY_CONTAINER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_entry_container_factory")); - public static final ResourceKey> LOOT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_condition_factory")); + public static final ResourceKey>>> LOOT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_condition_factory")); public static final ResourceKey> NUMBER_PROVIDER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_factory")); public static final ResourceKey> TEMPLATE_ARGUMENT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_factory")); public static final ResourceKey> ITEM_MODEL_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_factory")); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/Factory.java b/core/src/main/java/net/momirealms/craftengine/core/util/Factory.java new file mode 100644 index 000000000..ec3e37b2f --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/util/Factory.java @@ -0,0 +1,8 @@ +package net.momirealms.craftengine.core.util; + +import java.util.Map; + +public interface Factory { + + T create(Map args); +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/Key.java b/core/src/main/java/net/momirealms/craftengine/core/util/Key.java index f536fa5ba..c769b1738 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/Key.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/Key.java @@ -1,7 +1,6 @@ package net.momirealms.craftengine.core.util; public record Key(String namespace, String value) { - public static final String DEFAULT_NAMESPACE = "craftengine"; public static Key withDefaultNamespace(String value) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java deleted file mode 100644 index 3abcf3ef1..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AllOfCondition.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.momirealms.craftengine.core.util.condition; - -import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.Condition; - -import java.util.List; - -public abstract class AllOfCondition implements Condition { - protected final List> conditions; - - public AllOfCondition(List> conditions) { - this.conditions = conditions; - } - - @Override - public boolean test(CTX ctx) { - for (Condition condition : conditions) { - if (!condition.test(ctx)) { - return false; - } - } - return true; - } - - @Override - public Key type() { - return CommonConditions.ALL_OF; - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java deleted file mode 100644 index b9803a62b..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/AnyOfCondition.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.momirealms.craftengine.core.util.condition; - -import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.Condition; - -import java.util.List; - -public abstract class AnyOfCondition implements Condition { - protected final List> conditions; - - public AnyOfCondition(List> conditions) { - this.conditions = conditions; - } - - @Override - public boolean test(CTX ctx) { - for (Condition condition : conditions) { - if (condition.test(ctx)) { - return true; - } - } - return false; - } - - @Override - public Key type() { - return CommonConditions.ANY_OF; - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java deleted file mode 100644 index 017c51d11..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/CommonConditions.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.momirealms.craftengine.core.util.condition; - -import net.momirealms.craftengine.core.util.Key; - -public final class CommonConditions { - private CommonConditions() {} - - public static final Key ALL_OF = Key.of("craftengine:all_of"); - public static final Key ANY_OF = Key.of("craftengine:any_of"); - public static final Key INVERTED = Key.of("craftengine:inverted"); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java b/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java deleted file mode 100644 index 7c2304344..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/condition/InvertedCondition.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.momirealms.craftengine.core.util.condition; - -import net.momirealms.craftengine.core.util.Key; -import net.momirealms.craftengine.core.util.context.Condition; - -public abstract class InvertedCondition implements Condition { - protected final Condition condition; - - public InvertedCondition(Condition condition) { - this.condition = condition; - } - - @Override - public boolean test(CTX ctx) { - return !this.condition.test(ctx); - } - - @Override - public Key type() { - return CommonConditions.INVERTED; - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameters.java b/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameters.java deleted file mode 100644 index 07ac2885c..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/context/parameter/CommonParameters.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.momirealms.craftengine.core.util.context.parameter; - -import net.momirealms.craftengine.core.util.context.ContextKey; - -public final class CommonParameters { - private CommonParameters() {} - - public static final ContextKey RANDOM = ContextKey.of("random"); - public static final ContextKey LAST_RANDOM = ContextKey.of("last_random"); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/os/Architecture.java b/core/src/main/java/net/momirealms/craftengine/core/util/os/Architecture.java deleted file mode 100644 index ab97a1da9..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/os/Architecture.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.momirealms.craftengine.core.util.os; - -import java.util.Locale; - -public enum Architecture { - X64(true), - X86(false), - ARM64(true), - ARM32(false), - PPC64LE(true), - RISCV64(true); - - static final Architecture current; - final boolean is64Bit; - - Architecture(boolean is64Bit) { - this.is64Bit = is64Bit; - } - - public String getNativePath() { - return name().toLowerCase(Locale.ENGLISH); - } - - public static Architecture get() { - return current; - } - - static { - String osArch = System.getProperty("os.arch"); - boolean is64Bit = osArch.contains("64") || osArch.startsWith("armv8"); - if (!osArch.startsWith("arm") && !osArch.startsWith("aarch")) { - if (osArch.startsWith("ppc")) { - if (!"ppc64le".equals(osArch)) { - throw new UnsupportedOperationException("Only PowerPC 64 LE is supported."); - } - current = PPC64LE; - } else if (osArch.startsWith("riscv")) { - if (!"riscv64".equals(osArch)) { - throw new UnsupportedOperationException("Only RISC-V 64 is supported."); - } - current = RISCV64; - } else { - current = is64Bit ? X64 : X86; - } - } else { - current = is64Bit ? ARM64 : ARM32; - } - } -} \ No newline at end of file diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/os/Platform.java b/core/src/main/java/net/momirealms/craftengine/core/util/os/Platform.java deleted file mode 100644 index fd864193d..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/util/os/Platform.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.momirealms.craftengine.core.util.os; - -public enum Platform { - FREEBSD("FreeBSD", "freebsd"), - LINUX("Linux", "linux"), - MACOS("macOS", "macos"), - WINDOWS("Windows", "windows"); - - private static final Platform current; - private final String name; - private final String nativePath; - - Platform(String name, String nativePath) { - this.name = name; - this.nativePath = nativePath; - } - - public String getName() { - return this.name; - } - - public String getNativePath() { - return nativePath; - } - - public static Platform get() { - return current; - } - - static { - String osName = System.getProperty("os.name"); - if (osName.startsWith("Windows")) { - current = WINDOWS; - } else if (osName.startsWith("FreeBSD")) { - current = FREEBSD; - } else if (!osName.startsWith("Linux") && !osName.startsWith("SunOS") && !osName.startsWith("Unix")) { - if (!osName.startsWith("Mac OS X") && !osName.startsWith("Darwin")) { - throw new LinkageError("Unknown platform: " + osName); - } - current = MACOS; - } else { - current = LINUX; - } - } -} From 25630d47759d6927431b1993a1a568ccff01c677 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 4 May 2025 02:46:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9B=B4=E5=A5=BD?= =?UTF-8?q?=E7=9A=84=E6=9D=A1=E4=BB=B6=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pack/conflict/matcher/PathMatcher.java | 7 ---- .../conflict/matcher/PathMatcherAllOf.java | 36 ----------------- .../conflict/matcher/PathMatcherAnyOf.java | 36 ----------------- .../conflict/matcher/PathMatcherContains.java | 9 +++-- .../conflict/matcher/PathMatcherExact.java | 9 +++-- .../conflict/matcher/PathMatcherFactory.java | 9 ----- .../conflict/matcher/PathMatcherFilename.java | 9 +++-- .../conflict/matcher/PathMatcherInverted.java | 27 ------------- .../matcher/PathMatcherParentPrefix.java | 9 +++-- .../matcher/PathMatcherParentSuffix.java | 9 +++-- .../pack/conflict/matcher/PathMatchers.java | 40 ++++++++++--------- .../conflict/matcher/PathPatternMatcher.java | 9 +++-- .../resolution/ResolutionConditional.java | 4 +- .../resolution/RetainMatchingResolution.java | 6 +-- .../context/number/FixedNumberProvider.java | 4 +- .../plugin/context/number/NumberProvider.java | 6 +-- .../context/number/NumberProviders.java | 19 ++++++++- .../context/number/UniformNumberProvider.java | 18 ++++++--- .../core/registry/BuiltInRegistries.java | 4 +- .../craftengine/core/registry/Registries.java | 4 +- .../DelayedDefaultRegionFileStorage.java | 1 + 21 files changed, 97 insertions(+), 178 deletions(-) delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFactory.java delete mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java deleted file mode 100644 index b00efefef..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcher.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.momirealms.craftengine.core.pack.conflict.matcher; - -import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.plugin.context.Condition; - -public interface PathMatcher extends Condition { -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java deleted file mode 100644 index 7ed47270b..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAllOf.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.momirealms.craftengine.core.pack.conflict.matcher; - -import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.plugin.context.Condition; -import net.momirealms.craftengine.core.plugin.context.condition.AllOfCondition; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.util.MiscUtils; - -import java.util.List; -import java.util.Map; - -public class PathMatcherAllOf extends AllOfCondition implements PathMatcher { - public static final Factory FACTORY = new Factory(); - - public PathMatcherAllOf(List> conditions) { - super(conditions); - } - - public static class Factory implements PathMatcherFactory { - - @SuppressWarnings("unchecked") - @Override - public PathMatcher create(Map arguments) { - Object termsObj = arguments.get("terms"); - if (termsObj instanceof List list) { - List> terms = (List>) list; - return new PathMatcherAllOf(PathMatchers.fromMapList(terms)); - } else if (termsObj instanceof Map) { - Map terms = MiscUtils.castToMap(termsObj, false); - return new PathMatcherAllOf(PathMatchers.fromMapList(List.of(terms))); - } else { - throw new LocalizedException("warning.config.conflict_matcher.all_of.missing_terms"); - } - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java deleted file mode 100644 index 027d8f1b6..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherAnyOf.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.momirealms.craftengine.core.pack.conflict.matcher; - -import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.plugin.context.Condition; -import net.momirealms.craftengine.core.plugin.context.condition.AnyOfCondition; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.util.MiscUtils; - -import java.util.List; -import java.util.Map; - -public class PathMatcherAnyOf extends AnyOfCondition implements PathMatcher { - public static final Factory FACTORY = new Factory(); - - public PathMatcherAnyOf(List> conditions) { - super(conditions); - } - - public static class Factory implements PathMatcherFactory { - - @SuppressWarnings("unchecked") - @Override - public PathMatcher create(Map arguments) { - Object termsObj = arguments.get("terms"); - if (termsObj instanceof List list) { - List> terms = (List>) list; - return new PathMatcherAnyOf(PathMatchers.fromMapList(terms)); - } else if (termsObj instanceof Map) { - Map terms = MiscUtils.castToMap(termsObj, false); - return new PathMatcherAnyOf(PathMatchers.fromMapList(List.of(terms))); - } else { - throw new LocalizedException("warning.config.conflict_matcher.any_of.missing_terms"); - } - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java index 77ee9f683..fba21b9e2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherContains.java @@ -1,14 +1,15 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class PathMatcherContains implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathMatcherContains implements Condition { private final String path; public PathMatcherContains(String path) { @@ -26,10 +27,10 @@ public class PathMatcherContains implements PathMatcher { return PathMatchers.CONTAINS; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path")); return new PathMatcherContains(path); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java index 7864822fa..e632d562a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherExact.java @@ -1,14 +1,15 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class PathMatcherExact implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathMatcherExact implements Condition { private final String path; public PathMatcherExact(String path) { @@ -26,10 +27,10 @@ public class PathMatcherExact implements PathMatcher { return PathMatchers.EXACT; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path")); return new PathMatcherExact(path); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFactory.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFactory.java deleted file mode 100644 index b4817c9ad..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFactory.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.momirealms.craftengine.core.pack.conflict.matcher; - -import java.util.Map; - -@FunctionalInterface -public interface PathMatcherFactory { - - PathMatcher create(Map arguments); -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java index 3a33b6442..a2e861d56 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherFilename.java @@ -1,14 +1,15 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; -public class PathMatcherFilename implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathMatcherFilename implements Condition { private final String name; public PathMatcherFilename(String name) { @@ -26,10 +27,10 @@ public class PathMatcherFilename implements PathMatcher { return PathMatchers.FILENAME; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name")); return new PathMatcherFilename(name); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java deleted file mode 100644 index 8a7b47e7f..000000000 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherInverted.java +++ /dev/null @@ -1,27 +0,0 @@ -package net.momirealms.craftengine.core.pack.conflict.matcher; - -import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.plugin.context.condition.InvertedCondition; -import net.momirealms.craftengine.core.plugin.locale.LocalizedException; -import net.momirealms.craftengine.core.util.MiscUtils; -import net.momirealms.craftengine.core.util.ResourceConfigUtils; - -import java.util.Map; - -public class PathMatcherInverted extends InvertedCondition implements PathMatcher { - public static final Factory FACTORY = new Factory(); - - public PathMatcherInverted(PathMatcher condition) { - super(condition); - } - - public static class Factory implements PathMatcherFactory { - - @Override - public PathMatcher create(Map arguments) { - Object inverted = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("term"), () -> new LocalizedException("warning.config.conflict_matcher.inverted.missing_term")); - Map term = MiscUtils.castToMap(inverted, false); - return new PathMatcherInverted(PathMatchers.fromMap(term)); - } - } -} diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java index fb3bbafa7..df4b639c6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentPrefix.java @@ -1,15 +1,16 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.nio.file.Path; import java.util.Map; -public class PathMatcherParentPrefix implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathMatcherParentPrefix implements Condition { private final String prefix; public PathMatcherParentPrefix(String prefix) { @@ -29,10 +30,10 @@ public class PathMatcherParentPrefix implements PathMatcher { return PathMatchers.PARENT_PATH_PREFIX; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix")); return new PathMatcherParentPrefix(prefix); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java index 971cdd82b..c53ca69b6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatcherParentSuffix.java @@ -1,15 +1,16 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.nio.file.Path; import java.util.Map; -public class PathMatcherParentSuffix implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathMatcherParentSuffix implements Condition { private final String suffix; public PathMatcherParentSuffix(String suffix) { @@ -29,10 +30,10 @@ public class PathMatcherParentSuffix implements PathMatcher { return PathMatchers.PARENT_PATH_SUFFIX; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix")); return new PathMatcherParentSuffix(suffix); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java index c9ae0edb8..90dc0a83c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathMatchers.java @@ -1,10 +1,17 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; +import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; +import net.momirealms.craftengine.core.plugin.context.condition.AllOfCondition; +import net.momirealms.craftengine.core.plugin.context.condition.AnyOfCondition; +import net.momirealms.craftengine.core.plugin.context.condition.InvertedCondition; +import net.momirealms.craftengine.core.plugin.context.condition.SharedConditions; 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.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import net.momirealms.craftengine.core.util.ResourceKey; @@ -20,39 +27,36 @@ public class PathMatchers { public static final Key PARENT_PATH_SUFFIX = Key.of("craftengine:parent_path_suffix"); public static final Key PARENT_PATH_PREFIX = Key.of("craftengine:parent_path_prefix"); public static final Key PATTERN = Key.of("craftengine:pattern"); - public static final Key ANY_OF = Key.of("craftengine:any_of"); - public static final Key ALL_OF = Key.of("craftengine:all_of"); - public static final Key INVERTED = Key.of("craftengine:inverted"); static { - register(PARENT_PATH_SUFFIX, PathMatcherParentSuffix.FACTORY); - register(PARENT_PATH_PREFIX, PathMatcherParentPrefix.FACTORY); - register(PATTERN, PathPatternMatcher.FACTORY); - register(EXACT, PathMatcherExact.FACTORY); - register(FILENAME, PathMatcherFilename.FACTORY); - register(ANY_OF, PathMatcherAnyOf.FACTORY); - register(ALL_OF, PathMatcherAllOf.FACTORY); - register(INVERTED, PathMatcherInverted.FACTORY); - register(CONTAINS, PathMatcherContains.FACTORY); + register(SharedConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(PathMatchers::fromMap)); + register(SharedConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(PathMatchers::fromMap)); + register(SharedConditions.INVERTED, new InvertedCondition.FactoryImpl<>(PathMatchers::fromMap)); + register(PARENT_PATH_SUFFIX, new PathMatcherParentSuffix.FactoryImpl()); + register(PARENT_PATH_PREFIX, new PathMatcherParentPrefix.FactoryImpl()); + register(PATTERN, new PathPatternMatcher.FactoryImpl()); + register(EXACT, new PathMatcherExact.FactoryImpl()); + register(FILENAME, new PathMatcherFilename.FactoryImpl()); + register(CONTAINS, new PathMatcherContains.FactoryImpl()); } - public static void register(Key key, PathMatcherFactory factory) { - Holder.Reference holder = ((WritableRegistry) BuiltInRegistries.PATH_MATCHER_FACTORY).registerForHolder(new ResourceKey<>(Registries.PATH_MATCHER_FACTORY.location(), key)); + public static void register(Key key, Factory> factory) { + Holder.Reference>> holder = ((WritableRegistry>>) BuiltInRegistries.PATH_MATCHER_FACTORY).registerForHolder(new ResourceKey<>(Registries.PATH_MATCHER_FACTORY.location(), key)); holder.bindValue(factory); } - public static List fromMapList(List> arguments) { - List matchers = new ArrayList<>(); + public static List> fromMapList(List> arguments) { + List> matchers = new ArrayList<>(); for (Map term : arguments) { matchers.add(PathMatchers.fromMap(term)); } return matchers; } - public static PathMatcher fromMap(Map map) { + public static Condition fromMap(Map map) { String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), () -> new LocalizedException("warning.config.conflict_matcher.missing_type")); Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE); - PathMatcherFactory factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(key); + Factory> factory = BuiltInRegistries.PATH_MATCHER_FACTORY.getValue(key); if (factory == null) { throw new LocalizedException("warning.config.conflict_matcher.invalid_type", type); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathPatternMatcher.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathPatternMatcher.java index 8d0fed1c8..9261bffc2 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathPatternMatcher.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/matcher/PathPatternMatcher.java @@ -1,15 +1,16 @@ package net.momirealms.craftengine.core.pack.conflict.matcher; import net.momirealms.craftengine.core.pack.conflict.PathContext; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.plugin.locale.LocalizedException; +import net.momirealms.craftengine.core.util.Factory; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.ResourceConfigUtils; import java.util.Map; import java.util.regex.Pattern; -public class PathPatternMatcher implements PathMatcher { - public static final Factory FACTORY = new Factory(); +public class PathPatternMatcher implements Condition { private final Pattern pattern; public PathPatternMatcher(String pattern) { @@ -35,10 +36,10 @@ public class PathPatternMatcher implements PathMatcher { return pattern; } - public static class Factory implements PathMatcherFactory { + public static class FactoryImpl implements Factory> { @Override - public PathMatcher create(Map arguments) { + public Condition create(Map arguments) { String pattern = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("pattern"), () -> new LocalizedException("warning.config.conflict_matcher.pattern.missing_pattern")); return new PathPatternMatcher(pattern); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java index 0c79d0c23..4eb182943 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/ResolutionConditional.java @@ -1,14 +1,14 @@ package net.momirealms.craftengine.core.pack.conflict.resolution; import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcher; import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatchers; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; import java.util.Map; -public record ResolutionConditional(PathMatcher matcher, Resolution resolution) implements Resolution { +public record ResolutionConditional(Condition matcher, Resolution resolution) implements Resolution { public static final Factory FACTORY = new Factory(); @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/RetainMatchingResolution.java b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/RetainMatchingResolution.java index 3b20601d0..490e46671 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/RetainMatchingResolution.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/conflict/resolution/RetainMatchingResolution.java @@ -1,9 +1,9 @@ package net.momirealms.craftengine.core.pack.conflict.resolution; import net.momirealms.craftengine.core.pack.conflict.PathContext; -import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcher; import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatchers; import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.context.Condition; import net.momirealms.craftengine.core.util.Key; import net.momirealms.craftengine.core.util.MiscUtils; @@ -14,9 +14,9 @@ import java.util.Map; public class RetainMatchingResolution implements Resolution { public static final Factory FACTORY = new Factory(); - private final PathMatcher matcher; + private final Condition matcher; - public RetainMatchingResolution(PathMatcher matcher) { + public RetainMatchingResolution(Condition matcher) { this.matcher = matcher; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java index fcf8703bd..0e71e8332 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/FixedNumberProvider.java @@ -1,6 +1,6 @@ package net.momirealms.craftengine.core.plugin.context.number; -import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.util.Key; import java.util.Map; @@ -14,7 +14,7 @@ public class FixedNumberProvider implements NumberProvider { } @Override - public float getFloat(LootContext context) { + public float getFloat(Context context) { return this.value; } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java index 3d23c3cd3..93cdd64a0 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProvider.java @@ -1,13 +1,13 @@ package net.momirealms.craftengine.core.plugin.context.number; -import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.util.Key; public interface NumberProvider { - float getFloat(LootContext context); + float getFloat(Context context); - default int getInt(LootContext context) { + default int getInt(Context context) { return Math.round(this.getFloat(context)); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java index 162e25bff..23552f78c 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/NumberProviders.java @@ -8,6 +8,7 @@ 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 software.amazon.awssdk.services.s3.endpoints.internal.Value; import java.util.ArrayList; import java.util.List; @@ -55,7 +56,23 @@ public class NumberProviders { if (object instanceof Number number) { return new FixedNumberProvider(number.floatValue()); } else if (object instanceof String string) { - return new FixedNumberProvider(Float.parseFloat(string)); + if (string.contains("~")) { + int first = string.indexOf('~'); + int second = string.indexOf('~', first + 1); + if (second == -1) { + try { + float min = Float.parseFloat(string.substring(0, first)); + float max = Float.parseFloat(string.substring(first + 1)); + return new UniformNumberProvider(min, max); + } catch (NumberFormatException e) { + throw e; + } + } else { + throw new IllegalArgumentException("Illegal number format: " + string); + } + } else { + return new FixedNumberProvider(Float.parseFloat(string)); + } } else if (object instanceof Map map) { return fromMap((Map) map); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java index aac5be744..d90880eb9 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/number/UniformNumberProvider.java @@ -1,7 +1,8 @@ package net.momirealms.craftengine.core.plugin.context.number; -import net.momirealms.craftengine.core.loot.LootContext; +import net.momirealms.craftengine.core.plugin.context.Context; import net.momirealms.craftengine.core.util.Key; +import net.momirealms.craftengine.core.util.RandomUtils; import java.util.Map; @@ -15,14 +16,19 @@ public class UniformNumberProvider implements NumberProvider { this.max = max; } - @Override - public int getInt(LootContext context) { - return context.randomSource().nextInt(this.min.getInt(context), this.max.getInt(context) + 1); + public UniformNumberProvider(float min, float max) { + this.min = new FixedNumberProvider(min); + this.max = new FixedNumberProvider(max); } @Override - public float getFloat(LootContext context) { - return context.randomSource().nextFloat(this.min.getFloat(context), this.max.getFloat(context)); + public int getInt(Context context) { + return RandomUtils.generateRandomInt(this.min.getInt(context), this.max.getInt(context)); + } + + @Override + public float getFloat(Context context) { + return RandomUtils.generateRandomFloat(this.min.getFloat(context), this.max.getFloat(context)); } @Override diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java index 78f295dd7..7a1a2a22a 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java @@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory; import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount; import net.momirealms.craftengine.core.loot.function.LootFunctionFactory; -import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory; +import net.momirealms.craftengine.core.pack.conflict.PathContext; import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionFactory; import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; import net.momirealms.craftengine.core.pack.model.ItemModelFactory; @@ -46,7 +46,7 @@ public class BuiltInRegistries { public static final Registry SELECT_PROPERTY_FACTORY = createRegistry(Registries.SELECT_PROPERTY_FACTORY); public static final Registry> RECIPE_FACTORY = createRegistry(Registries.RECIPE_FACTORY); public static final Registry FORMULA_FACTORY = createRegistry(Registries.FORMULA_FACTORY); - public static final Registry PATH_MATCHER_FACTORY = createRegistry(Registries.PATH_MATCHER_FACTORY); + public static final Registry>> PATH_MATCHER_FACTORY = createRegistry(Registries.PATH_MATCHER_FACTORY); public static final Registry RESOLUTION_FACTORY = createRegistry(Registries.RESOLUTION_FACTORY); public static final Registry SMITHING_RESULT_PROCESSOR_FACTORY = createRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY); public static final Registry HITBOX_FACTORY = createRegistry(Registries.HITBOX_FACTORY); diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java index 06225b41c..3bad798af 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java @@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.loot.LootContext; import net.momirealms.craftengine.core.loot.entry.LootEntryContainerFactory; import net.momirealms.craftengine.core.loot.function.LootFunctionApplyBonusCount; import net.momirealms.craftengine.core.loot.function.LootFunctionFactory; -import net.momirealms.craftengine.core.pack.conflict.matcher.PathMatcherFactory; +import net.momirealms.craftengine.core.pack.conflict.PathContext; import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionFactory; import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; import net.momirealms.craftengine.core.pack.model.ItemModelFactory; @@ -47,7 +47,7 @@ public class Registries { public static final ResourceKey> SELECT_PROPERTY_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("select_property_factory")); public static final ResourceKey>> RECIPE_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("recipe_factory")); public static final ResourceKey> FORMULA_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("formula_factory")); - public static final ResourceKey> PATH_MATCHER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory")); + public static final ResourceKey>>> PATH_MATCHER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory")); public static final ResourceKey> RESOLUTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory")); public static final ResourceKey> SMITHING_RESULT_PROCESSOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory")); public static final ResourceKey> HITBOX_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory")); diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java index 04dceb3a0..49f580494 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java @@ -61,6 +61,7 @@ public class DelayedDefaultRegionFileStorage extends DefaultRegionFileStorage { public synchronized void close() throws IOException { this.saveCache(); super.close(); + this.chunkCache.cleanUp(); } private void saveCache() { From 11642aa1ad15322935b0166d8ae4bad2cd9482f8 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 4 May 2025 03:17:15 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=97=B6=E6=89=8D?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=83=A8=E5=88=86=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bukkit/build.gradle.kts | 2 +- bukkit/loader/build.gradle.kts | 2 +- .../main/resources/craft-engine.properties | 3 +- core/build.gradle.kts | 7 ++- .../core/pack/host/ResourcePackHosts.java | 2 +- .../core/pack/host/impl/S3HostFactory.java | 54 +++++++++++++++++++ .../craftengine/core/plugin/CraftEngine.java | 37 +------------ .../core/plugin/dependency/Dependencies.java | 8 +++ gradle.properties | 1 + 9 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/S3HostFactory.java diff --git a/bukkit/build.gradle.kts b/bukkit/build.gradle.kts index 92915efaf..607fff3b3 100644 --- a/bukkit/build.gradle.kts +++ b/bukkit/build.gradle.kts @@ -91,10 +91,10 @@ tasks { relocate("org.apache.commons.io", "net.momirealms.craftengine.libraries.commons.io") relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats") relocate("com.github.benmanes.caffeine", "net.momirealms.craftengine.libraries.caffeine") - relocate("net.objecthunter.exp4j", "net.momirealms.craftengine.libraries.exp4j") relocate("net.bytebuddy", "net.momirealms.craftengine.libraries.bytebuddy") relocate("org.yaml.snakeyaml", "net.momirealms.craftengine.libraries.snakeyaml") relocate("org.ahocorasick", "net.momirealms.craftengine.libraries.ahocorasick") + relocate("com.ezylang.evalex", "net.momirealms.craftengine.libraries.evalex") } } diff --git a/bukkit/loader/build.gradle.kts b/bukkit/loader/build.gradle.kts index a373bbeff..dae694cd2 100644 --- a/bukkit/loader/build.gradle.kts +++ b/bukkit/loader/build.gradle.kts @@ -71,7 +71,7 @@ tasks { relocate("org.apache.commons.io", "net.momirealms.craftengine.libraries.commons.io") relocate("org.bstats", "net.momirealms.craftengine.libraries.bstats") relocate("com.github.benmanes.caffeine", "net.momirealms.craftengine.libraries.caffeine") - relocate("net.objecthunter.exp4j", "net.momirealms.craftengine.libraries.exp4j") + relocate("com.ezylang.evalex", "net.momirealms.craftengine.libraries.evalex") relocate("net.bytebuddy", "net.momirealms.craftengine.libraries.bytebuddy") relocate("org.yaml.snakeyaml", "net.momirealms.craftengine.libraries.snakeyaml") relocate("org.ahocorasick", "net.momirealms.craftengine.libraries.ahocorasick") diff --git a/bukkit/loader/src/main/resources/craft-engine.properties b/bukkit/loader/src/main/resources/craft-engine.properties index 5901f43dd..c94d83fa0 100644 --- a/bukkit/loader/src/main/resources/craft-engine.properties +++ b/bukkit/loader/src/main/resources/craft-engine.properties @@ -32,4 +32,5 @@ lz4=${lz4_version} netty-codec-http2=${netty_version} reactive-streams=${reactive_streams_version} amazon-sdk-s3=${amazon_awssdk_version} -amazon-sdk-eventstream=${amazon_awssdk_eventstream_version} \ No newline at end of file +amazon-sdk-eventstream=${amazon_awssdk_eventstream_version} +evalex=${evalex_version} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 0ba9d3b0a..83e995a17 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -52,8 +52,12 @@ dependencies { // Aho-Corasick java implementation compileOnly("org.ahocorasick:ahocorasick:${rootProject.properties["ahocorasick_version"]}") // Amazon S3 - compileOnly("software.amazon.awssdk:s3:${rootProject.properties["amazon_awssdk_version"]}") + compileOnly("software.amazon.awssdk:s3:${rootProject.properties["amazon_awssdk_version"]}") { + + } compileOnly("software.amazon.awssdk:netty-nio-client:${rootProject.properties["amazon_awssdk_version"]}") + // EvalEx + compileOnly("com.ezylang:EvalEx:${rootProject.properties["evalex_version"]}") } java { @@ -85,6 +89,7 @@ tasks { relocate("net.jpountz", "net.momirealms.craftengine.libraries.jpountz") // lz4 relocate("software.amazon.awssdk", "net.momirealms.craftengine.libraries.awssdk") // awssdk relocate("software.amazon.eventstream", "net.momirealms.craftengine.libraries.eventstream") // awssdk + relocate("com.ezylang.evalex", "net.momirealms.craftengine.libraries.evalex") } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java index ccf56c684..3c88658fd 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/ResourcePackHosts.java @@ -27,7 +27,7 @@ public class ResourcePackHosts { register(SELF, SelfHost.FACTORY); register(EXTERNAL, ExternalHost.FACTORY); register(LOBFILE, LobFileHost.FACTORY); - register(S3, S3Host.FACTORY); + register(S3, S3HostFactory.INSTANCE); register(ALIST, AlistHost.FACTORY); register(DROPBOX, DropboxHost.FACTORY); register(ONEDRIVE, OneDriveHost.FACTORY); diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/S3HostFactory.java b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/S3HostFactory.java new file mode 100644 index 000000000..5de2fa3b0 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/host/impl/S3HostFactory.java @@ -0,0 +1,54 @@ +package net.momirealms.craftengine.core.pack.host.impl; + +import net.momirealms.craftengine.core.pack.host.ResourcePackHost; +import net.momirealms.craftengine.core.pack.host.ResourcePackHostFactory; +import net.momirealms.craftengine.core.plugin.CraftEngine; +import net.momirealms.craftengine.core.plugin.dependency.Dependencies; + +import java.util.List; +import java.util.Map; + +public class S3HostFactory implements ResourcePackHostFactory { + public static final S3HostFactory INSTANCE = new S3HostFactory(); + + @Override + public ResourcePackHost create(Map arguments) { + CraftEngine.instance().dependencyManager().loadDependencies( + List.of( + Dependencies.NETTY_HTTP, + Dependencies.NETTY_HTTP2, + Dependencies.REACTIVE_STREAMS, + Dependencies.AMAZON_AWSSDK_S3, + Dependencies.AMAZON_AWSSDK_NETTY_NIO_CLIENT, + Dependencies.AMAZON_AWSSDK_SDK_CORE, + Dependencies.AMAZON_AWSSDK_AUTH, + Dependencies.AMAZON_AWSSDK_REGIONS, + Dependencies.AMAZON_AWSSDK_IDENTITY_SPI, + Dependencies.AMAZON_AWSSDK_HTTP_CLIENT_SPI, + Dependencies.AMAZON_AWSSDK_PROTOCOL_CORE, + Dependencies.AMAZON_AWSSDK_AWS_XML_PROTOCOL, + Dependencies.AMAZON_AWSSDK_JSON_UTILS, + Dependencies.AMAZON_AWSSDK_AWS_CORE, + Dependencies.AMAZON_AWSSDK_UTILS, + Dependencies.AMAZON_AWSSDK_ANNOTATIONS, + Dependencies.AMAZON_AWSSDK_CRT_CORE, + Dependencies.AMAZON_AWSSDK_CHECKSUMS, + Dependencies.AMAZON_EVENTSTREAM, + Dependencies.AMAZON_AWSSDK_PROFILES, + Dependencies.AMAZON_AWSSDK_RETRIES, + Dependencies.AMAZON_AWSSDK_ENDPOINTS_SPI, + Dependencies.AMAZON_AWSSDK_ARNS, + Dependencies.AMAZON_AWSSDK_AWS_QUERY_PROTOCOL, + Dependencies.AMAZON_AWSSDK_HTTP_AUTH_AWS, + Dependencies.AMAZON_AWSSDK_HTTP_AUTH_SPI, + Dependencies.AMAZON_AWSSDK_HTTP_AUTH, + Dependencies.AMAZON_AWSSDK_HTTP_AUTH_AWS_EVENTSTREAM, + Dependencies.AMAZON_AWSSDK_CHECKSUMS_SPI, + Dependencies.AMAZON_AWSSDK_RETRIES_SPI, + Dependencies.AMAZON_AWSSDK_METRICS_SPI, + Dependencies.AMAZON_AWSSDK_THIRD_PARTY_JACKSON_CORE + ) + ); + return S3Host.FACTORY.create(arguments); + } +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java index af0e3fed0..83feda34f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/CraftEngine.java @@ -287,49 +287,16 @@ public abstract class CraftEngine implements Plugin { Dependencies.GEANTY_REF, Dependencies.CLOUD_CORE, Dependencies.CLOUD_SERVICES, Dependencies.GSON, - Dependencies.SLF4J_API, Dependencies.SLF4J_SIMPLE, Dependencies.COMMONS_IO, Dependencies.ZSTD, Dependencies.BYTE_BUDDY, Dependencies.SNAKE_YAML, Dependencies.BOOSTED_YAML, Dependencies.MINIMESSAGE, - Dependencies.TEXT_SERIALIZER_GSON, Dependencies.TEXT_SERIALIZER_GSON_LEGACY, - Dependencies.TEXT_SERIALIZER_JSON, + Dependencies.TEXT_SERIALIZER_GSON, Dependencies.TEXT_SERIALIZER_GSON_LEGACY, Dependencies.TEXT_SERIALIZER_JSON, Dependencies.AHO_CORASICK, Dependencies.LZ4, - Dependencies.NETTY_HTTP, - Dependencies.NETTY_HTTP2, - Dependencies.REACTIVE_STREAMS, - Dependencies.AMAZON_AWSSDK_S3, - Dependencies.AMAZON_AWSSDK_NETTY_NIO_CLIENT, - Dependencies.AMAZON_AWSSDK_SDK_CORE, - Dependencies.AMAZON_AWSSDK_AUTH, - Dependencies.AMAZON_AWSSDK_REGIONS, - Dependencies.AMAZON_AWSSDK_IDENTITY_SPI, - Dependencies.AMAZON_AWSSDK_HTTP_CLIENT_SPI, - Dependencies.AMAZON_AWSSDK_PROTOCOL_CORE, - Dependencies.AMAZON_AWSSDK_AWS_XML_PROTOCOL, - Dependencies.AMAZON_AWSSDK_JSON_UTILS, - Dependencies.AMAZON_AWSSDK_AWS_CORE, - Dependencies.AMAZON_AWSSDK_UTILS, - Dependencies.AMAZON_AWSSDK_ANNOTATIONS, - Dependencies.AMAZON_AWSSDK_CRT_CORE, - Dependencies.AMAZON_AWSSDK_CHECKSUMS, - Dependencies.AMAZON_EVENTSTREAM, - Dependencies.AMAZON_AWSSDK_PROFILES, - Dependencies.AMAZON_AWSSDK_RETRIES, - Dependencies.AMAZON_AWSSDK_ENDPOINTS_SPI, - Dependencies.AMAZON_AWSSDK_ARNS, - Dependencies.AMAZON_AWSSDK_AWS_QUERY_PROTOCOL, - Dependencies.AMAZON_AWSSDK_HTTP_AUTH_AWS, - Dependencies.AMAZON_AWSSDK_HTTP_AUTH_SPI, - Dependencies.AMAZON_AWSSDK_HTTP_AUTH, - Dependencies.AMAZON_AWSSDK_HTTP_AUTH_AWS_EVENTSTREAM, - Dependencies.AMAZON_AWSSDK_CHECKSUMS_SPI, - Dependencies.AMAZON_AWSSDK_RETRIES_SPI, - Dependencies.AMAZON_AWSSDK_METRICS_SPI, - Dependencies.AMAZON_AWSSDK_THIRD_PARTY_JACKSON_CORE + Dependencies.EVALEX ); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java index 1859a2847..285430f15 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/dependency/Dependencies.java @@ -248,6 +248,14 @@ public class Dependencies { List.of(Relocation.of("jpountz", "net{}jpountz")) ); + public static final Dependency EVALEX = new Dependency( + "evalex", + "com{}ezylang", + "EvalEx", + "evalex", + List.of(Relocation.of("evalex", "com{}ezylang{}evalex")) + ); + public static final Dependency NETTY_HTTP = new Dependency( "netty-codec-http", "io{}netty", diff --git a/gradle.properties b/gradle.properties index 4783415e2..69b28ee28 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,6 +51,7 @@ ahocorasick_version=0.6.3 snake_yaml_version=2.4 anti_grief_version=0.15 nms_helper_version=0.64.5 +evalex_version=3.5.0 reactive_streams_version=1.0.4 amazon_awssdk_version=2.31.23 amazon_awssdk_eventstream_version=1.0.1 From 5e28d964be96820a60ee602356fd1d2f1bb5fd27 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sun, 4 May 2025 15:36:08 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dteam?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/plugin/network/PacketConsumers.java | 18 ++++++++++++++---- .../DelayedDefaultRegionFileStorage.java | 6 ++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index c8a427258..413ec486b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.bukkit.plugin.network; +import com.mojang.datafixers.util.Either; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.ints.IntList; @@ -331,8 +332,17 @@ public class PacketConsumers { Tag displayName = buf.readNbt(false); if (displayName == null) return; byte friendlyFlags = buf.readByte(); - String nameTagVisibility = buf.readUtf(40); - String collisionRule = buf.readUtf(40); + + Either eitherVisibility; + Either eitherCollisionRule; + + if (VersionHelper.isOrAbove1_21_5()) { + eitherVisibility = Either.right(buf.readVarInt()); + eitherCollisionRule = Either.right(buf.readVarInt()); + } else { + eitherVisibility = Either.left(buf.readUtf(40)); + eitherCollisionRule = Either.left(buf.readUtf(40)); + } int color = buf.readVarInt(); Tag prefix = buf.readNbt(false); if (prefix == null) return; @@ -368,8 +378,8 @@ public class PacketConsumers { } buf.writeByte(friendlyFlags); - buf.writeUtf(nameTagVisibility); - buf.writeUtf(collisionRule); + eitherVisibility.ifLeft(buf::writeUtf).ifRight(buf::writeVarInt); + eitherCollisionRule.ifLeft(buf::writeUtf).ifRight(buf::writeVarInt); buf.writeVarInt(color); if (!tokens2.isEmpty()) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java index 49f580494..1df369736 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java +++ b/core/src/main/java/net/momirealms/craftengine/core/world/chunk/storage/DelayedDefaultRegionFileStorage.java @@ -15,13 +15,14 @@ import java.util.concurrent.TimeUnit; public class DelayedDefaultRegionFileStorage extends DefaultRegionFileStorage { private final Cache chunkCache; + private boolean isClosed; public DelayedDefaultRegionFileStorage(Path directory, int time) { super(directory); this.chunkCache = Caffeine.newBuilder() .expireAfterWrite(time, TimeUnit.SECONDS) .removalListener((ChunkPos key, CEChunk value, RemovalCause cause) -> { - if (key == null || value == null) { + if (key == null || value == null || isClosed) { return; } if (cause == RemovalCause.EXPIRED || cause == RemovalCause.SIZE) { @@ -60,8 +61,9 @@ public class DelayedDefaultRegionFileStorage extends DefaultRegionFileStorage { @Override public synchronized void close() throws IOException { this.saveCache(); - super.close(); this.chunkCache.cleanUp(); + this.isClosed = true; + super.close(); } private void saveCache() {