mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-22 16:39:28 +00:00
增强数字参数
This commit is contained in:
@@ -70,6 +70,25 @@ warning.config.type.float: "<yellow>Issue found in file <arg:0> - Failed to load
|
||||
warning.config.type.double: "<yellow>Issue found in file <arg:0> - Failed to load '<arg:1>': Cannot cast '<arg:2>' to double type for option '<arg:3>'.</yellow>"
|
||||
warning.config.type.quaternionf: "<yellow>Issue found in file <arg:0> - Failed to load '<arg:1>': Cannot cast '<arg:2>' to Quaternionf type for option '<arg:3>'.</yellow>"
|
||||
warning.config.type.vector3f: "<yellow>Issue found in file <arg:0> - Failed to load '<arg:1>': Cannot cast '<arg:2>' to Vector3f type for option '<arg:3>'.</yellow>"
|
||||
warning.config.number.missing_argument: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the argument for 'number'.</yellow>"
|
||||
warning.config.number.invalid_format: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid number format '<arg:2>'.</yellow>"
|
||||
warning.config.number.fixed.missing_value: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'value' argument for 'constant' number.</yellow>"
|
||||
warning.config.number.fixed.invalid_value: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using the invalid 'value' argument '<arg:2>' for 'constant' number.</yellow>"
|
||||
warning.config.number.expression.missing_expression: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'expression' argument for 'expression' number.</yellow>"
|
||||
warning.config.number.uniform.missing_min: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'min' argument for 'uniform' number.</yellow>"
|
||||
warning.config.number.uniform.missing_max: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'max' argument for 'uniform' number.</yellow>"
|
||||
warning.config.condition.all_of.missing_terms: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'terms' argument for 'all_of' condition.</yellow>"
|
||||
warning.config.condition.all_of.invalid_terms_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a misconfigured 'all_of' condition, 'terms' should be a map list, current type: '<arg:2>'.</yellow>"
|
||||
warning.config.condition.any_of.missing_terms: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'terms' argument for 'any_of' condition.</yellow>"
|
||||
warning.config.condition.any_of.invalid_terms_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a misconfigured 'any_of' condition, 'terms' should be a map list, current type: '<arg:2>'.</yellow>"
|
||||
warning.config.condition.inverted.missing_term: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'term' argument for 'inverted' condition.</yellow>"
|
||||
warning.config.condition.inverted.invalid_term_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' has a misconfigured 'inverted' condition, 'term' should be a config section, current type: '<arg:2>'.</yellow>"
|
||||
warning.config.condition.enchantment.missing_predicate: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'predicate' argument for 'enchantment' condition.</yellow>"
|
||||
warning.config.condition.enchantment.invalid_predicate: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid enchantment 'predicate' argument '<arg:2>'.</yellow>"
|
||||
warning.config.condition.match_block_property.missing_properties: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'properties' argument for 'match_block_property' condition.</yellow>"
|
||||
warning.config.condition.match_item.missing_id: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'id' argument for 'match_item' condition.</yellow>"
|
||||
warning.config.condition.table_bonus.missing_enchantment: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'enchantment' argument for 'table_bonus' condition.</yellow>"
|
||||
warning.config.condition.table_bonus.missing_chances: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'chances' argument for 'table_bonus' condition.</yellow>"
|
||||
warning.config.structure.not_section: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is expected to be a config section while it's actually a(n) '<arg:2>'.</yellow>"
|
||||
warning.config.image.duplicate: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'. Please check if there is the same configuration in other files.</yellow>"
|
||||
warning.config.image.missing_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
|
||||
@@ -228,8 +247,6 @@ warning.config.loot_table.entry.exp.missing_count: "<yellow>Issue found in file
|
||||
warning.config.loot_table.entry.item.missing_item: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, entry 'item' is missing the required 'item' argument.</yellow>"
|
||||
warning.config.loot_table.condition.missing_type: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, one of the conditions is missing the required 'type' argument.</yellow>"
|
||||
warning.config.loot_table.condition.invalid_type: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, one of the conditions is using an invalid condition type '<arg:2>'.</yellow>"
|
||||
warning.config.loot_table.condition.table_bonus.missing_enchantment: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, 'table_bonus' condition is missing the required 'enchantment' argument.</yellow>"
|
||||
warning.config.loot_table.condition.table_bonus.missing_chances: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, 'table_bonus' condition is missing the required 'chances' argument.</yellow>"
|
||||
warning.config.loot_table.number.missing_type: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, one of the numbers is missing the required 'type' argument.</yellow>"
|
||||
warning.config.loot_table.number.invalid_type: "<yellow>Issue found in file <arg:0> - '<arg:1>' has a misconfigured loot table, one of the numbers is using an invalid number type '<arg:2>'.</yellow>"
|
||||
warning.config.host.missing_type: "<yellow>Issue found in config.yml at 'resource-pack.delivery.hosting' - Missing required 'type' argument for host.</yellow>"
|
||||
|
||||
@@ -40,11 +40,11 @@ argument.parse.failure.aggregate.failure: "<red>无效的组件 '<arg:0>': <arg:
|
||||
argument.parse.failure.either: "<red>无法从 '<arg:0>' 解析 <arg:1> 或 <arg:2></red>"
|
||||
argument.parse.failure.namedtextcolor: "<red>'<arg:0>' 不是颜色代码</red>"
|
||||
command.reload.config.success: "<white>重新加载配置完成. 耗时 <green><arg:0></green> 毫秒</white> <gray>(异步: <arg:1>ms | 同步: <arg:2>ms)</gray>"
|
||||
command.reload.config.failure: "<red>重新加载配置失败,请检查控制台日志</red>"
|
||||
command.reload.config.failure: "<red>重新加载配置失败, 请检查控制台日志</red>"
|
||||
command.reload.pack.success: "<white>资源包重新加载完成. 耗时 <green><arg:0></green> 毫秒</white>"
|
||||
command.reload.pack.failure: "<red>重新加载资源包失败,请检查控制台日志</red>"
|
||||
command.reload.pack.failure: "<red>重新加载资源包失败, 请检查控制台日志</red>"
|
||||
command.reload.all.success: "<white>全部重新加载完成. 耗时 <green><arg:0></green> 毫秒</white> <gray>(异步: <arg:1>ms | 同步: <arg:2>ms | 资源包: <arg:3>ms)</gray>"
|
||||
command.reload.all.failure: "<red>重新加载失败,请检查控制台日志</red>"
|
||||
command.reload.all.failure: "<red>重新加载失败, 请检查控制台日志</red>"
|
||||
command.item.get.success: "<white>获得<arg:0>个<arg:1></white>"
|
||||
command.item.get.failure.not_exist: "<red><lang:argument.item.id.invalid:'<arg:0>'></red>"
|
||||
command.item.give.success.single: "<lang:commands.give.success.single:'<arg:0>':'<arg:1>':'<arg:2>'>"
|
||||
@@ -70,6 +70,25 @@ warning.config.type.float: "<yellow>在文件 <arg:0> 发现问题 - 无法加
|
||||
warning.config.type.double: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为双精度类型 (选项 '<arg:3>')</yellow>"
|
||||
warning.config.type.quaternionf: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为四元数类型 (选项 '<arg:3>')</yellow>"
|
||||
warning.config.type.vector3f: "<yellow>在文件 <arg:0> 发现问题 - 无法加载 '<arg:1>': 无法将 '<arg:2>' 转换为三维向量类型 (选项 '<arg:3>')</yellow>"
|
||||
warning.config.number.missing_argument: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少数字参数</yellow>"
|
||||
warning.config.number.invalid_format: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的数字格式 '<arg:2>'</yellow>"
|
||||
warning.config.number.fixed.missing_value: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'constant' 数字类型所需的 'value' 参数</yellow>"
|
||||
warning.config.number.fixed.invalid_value: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的常量值参数 '<arg:2>'</yellow>"
|
||||
warning.config.number.expression.missing_expression: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'expression' 数字类型所需的 'expression' 参数</yellow>"
|
||||
warning.config.number.uniform.missing_min: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'uniform' 数字类型所需的 'min' 参数</yellow>"
|
||||
warning.config.number.uniform.missing_max: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'uniform' 数字类型所需的 'max' 参数</yellow>"
|
||||
warning.config.condition.all_of.missing_terms: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'all_of' 条件所需的 'terms' 参数</yellow>"
|
||||
warning.config.condition.all_of.invalid_terms_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 的 'all_of' 条件配置错误, 'terms' 应为映射列表, 当前类型: '<arg:2>'</yellow>"
|
||||
warning.config.condition.any_of.missing_terms: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'any_of' 条件所需的 'terms' 参数</yellow>"
|
||||
warning.config.condition.any_of.invalid_terms_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 的 'any_of' 条件配置错误, 'terms' 应为映射列表, 当前类型: '<arg:2>'</yellow>"
|
||||
warning.config.condition.inverted.missing_term: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'inverted' 条件所需的 'term' 参数</yellow>"
|
||||
warning.config.condition.inverted.invalid_term_type: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 的 'inverted' 条件配置错误, 'term' 应为配置节点, 当前类型: '<arg:2>'</yellow>"
|
||||
warning.config.condition.enchantment.missing_predicate: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'enchantment' 条件所需的 'predicate' 参数</yellow>"
|
||||
warning.config.condition.enchantment.invalid_predicate: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 使用了无效的附魔 'predicate' 参数 '<arg:2>'</yellow>"
|
||||
warning.config.condition.match_block_property.missing_properties: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'match_block_property' 条件所需的 'properties' 参数</yellow>"
|
||||
warning.config.condition.match_item.missing_id: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'match_item' 条件所需的 'id' 参数</yellow>"
|
||||
warning.config.condition.table_bonus.missing_enchantment: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'table_bonus' 条件所需的 'enchantment' 参数</yellow>"
|
||||
warning.config.condition.table_bonus.missing_chances: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 缺少 'table_bonus' 条件所需的 'chances' 参数</yellow>"
|
||||
warning.config.structure.not_section: "<yellow>在文件 <arg:0> 发现问题 - 配置项 '<arg:1>' 应为配置段落 但实际类型为 '<arg:2>'</yellow>"
|
||||
warning.config.image.duplicate: "<yellow>在文件 <arg:0> 发现问题 - 重复的图片配置 '<arg:1>' 请检查其他文件中是否存在相同配置</yellow>"
|
||||
warning.config.image.missing_height: "<yellow>在文件 <arg:0> 发现问题 - 图片 '<arg:1>' 缺少必需的 'height' 参数</yellow>"
|
||||
|
||||
@@ -150,11 +150,11 @@ public class BlockEventListener implements Listener {
|
||||
}
|
||||
|
||||
// drop items
|
||||
ContextHolder.Builder builder = ContextHolder.builder();
|
||||
builder.withParameter(CommonParameters.WORLD, world);
|
||||
builder.withParameter(CommonParameters.LOCATION, vec3d);
|
||||
builder.withParameter(CommonParameters.PLAYER, serverPlayer);
|
||||
builder.withOptionalParameter(CommonParameters.TOOL, itemInHand);
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
.withParameter(CommonParameters.WORLD, world)
|
||||
.withParameter(CommonParameters.LOCATION, vec3d)
|
||||
.withParameter(CommonParameters.PLAYER, serverPlayer)
|
||||
.withOptionalParameter(CommonParameters.TOOL, itemInHand);
|
||||
for (Item<Object> item : state.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
}
|
||||
@@ -171,11 +171,11 @@ public class BlockEventListener implements Listener {
|
||||
BukkitServerPlayer serverPlayer = this.plugin.adapt(player);
|
||||
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(CommonParameters.WORLD, world);
|
||||
builder.withParameter(CommonParameters.LOCATION, vec3d);
|
||||
builder.withParameter(CommonParameters.PLAYER, serverPlayer);
|
||||
builder.withOptionalParameter(CommonParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND));
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
.withParameter(CommonParameters.WORLD, world)
|
||||
.withParameter(CommonParameters.LOCATION, vec3d)
|
||||
.withParameter(CommonParameters.PLAYER, serverPlayer)
|
||||
.withOptionalParameter(CommonParameters.TOOL, serverPlayer.getItemInHand(InteractionHand.MAIN_HAND));
|
||||
ContextHolder contextHolder = builder.build();
|
||||
for (LootTable<?> lootTable : it.lootTables()) {
|
||||
for (Item<?> item : lootTable.getRandomItems(contextHolder, world)) {
|
||||
@@ -213,9 +213,9 @@ public class BlockEventListener implements Listener {
|
||||
Location location = block.getLocation();
|
||||
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(CommonParameters.WORLD, world);
|
||||
builder.withParameter(CommonParameters.LOCATION, vec3d);
|
||||
ContextHolder.Builder builder = ContextHolder.builder()
|
||||
.withParameter(CommonParameters.WORLD, world)
|
||||
.withParameter(CommonParameters.LOCATION, vec3d);
|
||||
for (Item<?> item : immutableBlockState.getDrops(builder, world)) {
|
||||
world.dropItemNaturally(vec3d, item);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CropBlockBehavior extends BushBlockBehavior {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
@@ -148,7 +147,7 @@ public class CropBlockBehavior extends BushBlockBehavior {
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
|
||||
|
||||
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()
|
||||
int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, 1, ContextHolder.builder()
|
||||
.withParameter(CommonParameters.WORLD, wrappedWorld)
|
||||
.withParameter(CommonParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z)))
|
||||
.build()));
|
||||
|
||||
@@ -752,7 +752,7 @@ public class RecipeEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Item<ItemStack> newItem = customItem.buildItem(ItemBuildContext.of(plugin.adapt(player), ContextHolder.EMPTY));
|
||||
Item<ItemStack> newItem = customItem.buildItem(ItemBuildContext.of(plugin.adapt(player)));
|
||||
int remainingDurability = totalMaxDamage - totalDamage;
|
||||
int newItemDamage = Math.max(0, newItem.maxDamage().get() - remainingDurability);
|
||||
newItem.damage(newItemDamage);
|
||||
|
||||
@@ -70,7 +70,6 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
|
||||
ContextHolder.Builder builder = ContextHolder.builder();
|
||||
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);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.command.feature;
|
||||
|
||||
import com.saicone.rtag.util.ChatComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -24,10 +23,9 @@ public class TestCommand extends BukkitCommandFeature<CommandSender> {
|
||||
.senderType(Player.class)
|
||||
.required("text", StringParser.greedyStringParser())
|
||||
.handler(context -> {
|
||||
plugin().senderFactory().wrap(context.sender()).sendMessage(Component.text(
|
||||
ChatComponent.toTag(ComponentUtils.adventureToMinecraft(AdventureHelper.miniMessage().deserialize(context.get("text")))).toString()
|
||||
));
|
||||
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage().deserialize(context.get("text")));
|
||||
String text = "<red><arg:1:0912012><papi:player_name></red>";
|
||||
PlayerOptionalContext context1 = PlayerOptionalContext.of(plugin().adapt(context.sender()), ContextHolder.builder());
|
||||
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.customMiniMessage().deserialize(text, context1.tagResolvers()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +199,6 @@ public class PacketConsumers {
|
||||
buf.writeInt(chunkZ);
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
buf.writeVarInt(heightmapsCount);
|
||||
assert heightmapsMap != null;
|
||||
for (Map.Entry<Integer, long[]> entry : heightmapsMap.entrySet()) {
|
||||
buf.writeVarInt(entry.getKey());
|
||||
buf.writeLongArray(entry.getValue());
|
||||
|
||||
@@ -124,7 +124,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
PlayerOptionalContext.of(player, ContextHolder.builder()
|
||||
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
|
||||
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
|
||||
.build()).tagResolvers()
|
||||
).tagResolvers()
|
||||
);
|
||||
replacements.put(fragment, AdventureHelper.componentToMiniMessage(content));
|
||||
}
|
||||
@@ -170,8 +170,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
PlayerOptionalContext.of(player, ContextHolder.builder()
|
||||
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
|
||||
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
|
||||
.build())
|
||||
.tagResolvers())
|
||||
).tagResolvers())
|
||||
);
|
||||
if (emojis.size() >= maxTimes) break;
|
||||
}
|
||||
@@ -200,11 +199,9 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
continue;
|
||||
emojis.put(fragment, AdventureHelper.miniMessage().deserialize(
|
||||
emoji.content(),
|
||||
PlayerOptionalContext.of(player,
|
||||
ContextHolder.builder()
|
||||
PlayerOptionalContext.of(player, ContextHolder.builder()
|
||||
.withOptionalParameter(EmojiParameters.EMOJI, emoji.emojiImage())
|
||||
.withParameter(EmojiParameters.KEYWORD, emoji.keywords().get(0))
|
||||
.build()
|
||||
).tagResolvers()
|
||||
));
|
||||
if (emojis.size() >= maxTimes) break;
|
||||
|
||||
@@ -3,7 +3,6 @@ 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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,7 +34,7 @@ public interface CustomItem<I> extends BuildableItem<I> {
|
||||
}
|
||||
|
||||
default Item<I> buildItem(Player player) {
|
||||
return buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY));
|
||||
return buildItem(ItemBuildContext.of(player));
|
||||
}
|
||||
|
||||
Item<I> buildItem(ItemBuildContext context);
|
||||
|
||||
@@ -3,9 +3,12 @@ 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.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemBuildContext extends PlayerOptionalContext {
|
||||
public static final ItemBuildContext EMPTY = new ItemBuildContext(null, ContextHolder.EMPTY);
|
||||
|
||||
@@ -17,4 +20,16 @@ public class ItemBuildContext extends PlayerOptionalContext {
|
||||
public static ItemBuildContext of(@Nullable Player player, @NotNull ContextHolder contexts) {
|
||||
return new ItemBuildContext(player, contexts);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ItemBuildContext of(@Nullable Player player, @NotNull ContextHolder.Builder builder) {
|
||||
if (player != null) builder.withParameter(CommonParameters.PLAYER, player);
|
||||
return new ItemBuildContext(player, builder.build());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ItemBuildContext of(@Nullable Player player) {
|
||||
if (player == null) return new ItemBuildContext(null, ContextHolder.EMPTY);
|
||||
return new ItemBuildContext(player, new ContextHolder(Map.of(CommonParameters.PLAYER, () -> player)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,20 @@
|
||||
package net.momirealms.craftengine.core.loot;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.context.AbstractCommonContext;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class LootContext extends AbstractCommonContext {
|
||||
public class LootContext extends PlayerOptionalContext {
|
||||
private final World world;
|
||||
private final Random randomSource;
|
||||
private final float luck;
|
||||
|
||||
public LootContext(World world, float luck, Random randomSource, ContextHolder contexts) {
|
||||
super(contexts);
|
||||
this.randomSource = randomSource;
|
||||
public LootContext(World world, float luck, ContextHolder contexts) {
|
||||
super(contexts.getOptional(CommonParameters.PLAYER).orElse(null), contexts);
|
||||
this.world = world;
|
||||
this.luck = luck;
|
||||
}
|
||||
|
||||
public Random randomSource() {
|
||||
return this.randomSource;
|
||||
}
|
||||
|
||||
public float luck() {
|
||||
return luck;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ 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;
|
||||
import net.momirealms.craftengine.core.util.RandomUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
@@ -62,7 +62,6 @@ public class LootPool<T> {
|
||||
}
|
||||
|
||||
private void addRandomItem(Consumer<Item<T>> lootConsumer, LootContext context) {
|
||||
Random randomSource = context.randomSource();
|
||||
List<LootEntry<T>> list = Lists.newArrayList();
|
||||
MutableInt mutableInt = new MutableInt(0);
|
||||
for (LootEntryContainer<T> lootPoolEntryContainer : this.entryContainers) {
|
||||
@@ -79,7 +78,7 @@ public class LootPool<T> {
|
||||
if (i == 1) {
|
||||
list.get(0).createItem(lootConsumer, context);
|
||||
} else {
|
||||
int j = randomSource.nextInt(mutableInt.intValue());
|
||||
int j = RandomUtils.generateRandomInt(0, mutableInt.intValue());
|
||||
for (LootEntry<T> loot : list) {
|
||||
j -= loot.getWeight(context.luck());
|
||||
if (j < 0) {
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
@@ -80,7 +79,7 @@ public class LootTable<T> {
|
||||
}
|
||||
|
||||
public ArrayList<Item<T>> getRandomItems(ContextHolder parameters, World world) {
|
||||
return this.getRandomItems(new LootContext(world, 1, ThreadLocalRandom.current(), parameters));
|
||||
return this.getRandomItems(new LootContext(world, 1, parameters));
|
||||
}
|
||||
|
||||
private ArrayList<Item<T>> getRandomItems(LootContext context) {
|
||||
|
||||
@@ -21,16 +21,16 @@ import java.util.function.Predicate;
|
||||
public class LootConditions {
|
||||
|
||||
static {
|
||||
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<>());
|
||||
register(CommonConditions.MATCH_ITEM, new MatchItemCondition.FactoryImpl<>());
|
||||
register(CommonConditions.MATCH_BLOCK_PROPERTY, new MatchBlockPropertyCondition.FactoryImpl<>());
|
||||
register(CommonConditions.TABLE_BONUS, new TableBonusCondition.FactoryImpl<>());
|
||||
register(CommonConditions.SURVIVES_EXPLOSION, new SurvivesExplosionCondition.FactoryImpl<>());
|
||||
register(CommonConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(LootConditions::fromMap));
|
||||
register(CommonConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(LootConditions::fromMap));
|
||||
register(CommonConditions.ENCHANTMENT, new EnchantmentCondition.FactoryImpl<>());
|
||||
register(CommonConditions.INVERTED, new InvertedCondition.FactoryImpl<>(LootConditions::fromMap));
|
||||
register(CommonConditions.FALLING_BLOCK, new FallingBlockCondition.FactoryImpl<>());
|
||||
register(CommonConditions.RANDOM, new RandomCondition.FactoryImpl<>());
|
||||
}
|
||||
|
||||
public static void register(Key key, Factory<Condition<LootContext>> factory) {
|
||||
|
||||
@@ -17,7 +17,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class LootFunctionApplyBonusCount<T> extends AbstractLootConditionalFunction<T> {
|
||||
public static final Factory<?> FACTORY = new Factory<>();
|
||||
@@ -108,7 +107,7 @@ public class LootFunctionApplyBonusCount<T> extends AbstractLootConditionalFunct
|
||||
@Override
|
||||
public int apply(int initialCount, int enchantmentLevel) {
|
||||
if (enchantmentLevel > 0) {
|
||||
int i = ThreadLocalRandom.current().nextInt(enchantmentLevel + 2) - 1;
|
||||
int i = RandomUtils.generateRandomInt(0, enchantmentLevel + 2) - 1;
|
||||
if (i < 0) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,12 @@ import net.momirealms.craftengine.core.loot.condition.LootConditions;
|
||||
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.RandomUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class LootFunctionExplosionDecay<T> extends AbstractLootConditionalFunction<T> {
|
||||
public static final Factory<?> FACTORY = new Factory<>();
|
||||
@@ -20,12 +24,11 @@ public class LootFunctionExplosionDecay<T> extends AbstractLootConditionalFuncti
|
||||
protected Item<T> applyInternal(Item<T> item, LootContext context) {
|
||||
Optional<Float> radius = context.getOptionalParameter(CommonParameters.EXPLOSION_RADIUS);
|
||||
if (radius.isPresent()) {
|
||||
Random random = context.randomSource();
|
||||
float f = 1f / radius.get();
|
||||
int amount = item.count();
|
||||
int survive = 0;
|
||||
for (int j = 0; j < amount; j++) {
|
||||
if (random.nextFloat() <= f) {
|
||||
if (RandomUtils.generateRandomFloat(0, 1) <= f) {
|
||||
survive++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.context.condition.CommonConditions;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
@@ -29,9 +29,9 @@ public class PathMatchers {
|
||||
public static final Key PATTERN = Key.of("craftengine:pattern");
|
||||
|
||||
static {
|
||||
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(CommonConditions.ANY_OF, new AnyOfCondition.FactoryImpl<>(PathMatchers::fromMap));
|
||||
register(CommonConditions.ALL_OF, new AllOfCondition.FactoryImpl<>(PathMatchers::fromMap));
|
||||
register(CommonConditions.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());
|
||||
|
||||
@@ -5,15 +5,15 @@ import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameterP
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class AbstractAdditionalCommonContext extends AbstractCommonContext {
|
||||
public abstract class AbstractAdditionalParameterContext extends AbstractCommonContext {
|
||||
private final List<LazyContextParameterProvider> providers;
|
||||
|
||||
public AbstractAdditionalCommonContext(ContextHolder contexts, List<LazyContextParameterProvider> providers) {
|
||||
public AbstractAdditionalParameterContext(ContextHolder contexts, List<LazyContextParameterProvider> providers) {
|
||||
super(contexts);
|
||||
this.providers = providers;
|
||||
}
|
||||
|
||||
public AbstractAdditionalCommonContext(ContextHolder contexts) {
|
||||
public AbstractAdditionalParameterContext(ContextHolder contexts) {
|
||||
super(contexts);
|
||||
this.providers = List.of(new CommonParameterProvider());
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package net.momirealms.craftengine.core.plugin.context;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
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 net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -26,7 +23,7 @@ public abstract class AbstractCommonContext implements Context {
|
||||
@NotNull
|
||||
public TagResolver[] tagResolvers() {
|
||||
if (this.tagResolvers == null) {
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new I18NTag(this), new NamedArgumentTag(this)};
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new I18NTag(this), new NamedArgumentTag(this), new PlaceholderTag(null)};
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ContextHolder {
|
||||
public static final ContextHolder EMPTY = ContextHolder.builder().immutable(true).build();
|
||||
protected final Map<ContextKey<?>, Supplier<Object>> params;
|
||||
|
||||
protected ContextHolder(Map<ContextKey<?>, Supplier<Object>> params) {
|
||||
public ContextHolder(Map<ContextKey<?>, Supplier<Object>> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
package net.momirealms.craftengine.core.plugin.context;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ContextKey<T> {
|
||||
private final Key id;
|
||||
private final String id;
|
||||
|
||||
public ContextKey(@NotNull Key id) {
|
||||
public ContextKey(@NotNull String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Key id() {
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ContextKey<T> of(@NotNull Key id) {
|
||||
return new ContextKey<>(id);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ContextKey<T> of(@NotNull String id) {
|
||||
return new ContextKey<>(Key.withDefaultNamespace(id, "craftengine"));
|
||||
return new ContextKey<>(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,14 +3,16 @@ 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.CommonParameters;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.PlayerParameterProvider;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerOptionalContext extends AbstractAdditionalCommonContext implements Context {
|
||||
public class PlayerOptionalContext extends AbstractAdditionalParameterContext implements Context {
|
||||
public static final PlayerOptionalContext EMPTY = new PlayerOptionalContext(null, ContextHolder.EMPTY);
|
||||
private final Player player;
|
||||
|
||||
@@ -29,6 +31,18 @@ public class PlayerOptionalContext extends AbstractAdditionalCommonContext imple
|
||||
return new PlayerOptionalContext(player, contexts);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlayerOptionalContext of(@Nullable Player player, @NotNull ContextHolder.Builder contexts) {
|
||||
if (player != null) contexts.withParameter(CommonParameters.PLAYER, player);
|
||||
return new PlayerOptionalContext(player, contexts.build());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlayerOptionalContext of(@Nullable Player player) {
|
||||
if (player == null) return EMPTY;
|
||||
return new PlayerOptionalContext(player, new ContextHolder(Map.of(CommonParameters.PLAYER, () -> player)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Player player() {
|
||||
return this.player;
|
||||
|
||||
@@ -2,8 +2,11 @@ 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.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Factory;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,7 +32,7 @@ public class AllOfCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.ALL_OF;
|
||||
return CommonConditions.ALL_OF;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements Factory<Condition<CTX>> {
|
||||
@@ -42,12 +45,21 @@ public class AllOfCondition<CTX extends Context> implements Condition<CTX> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
List<Map<String, Object>> terms = (List<Map<String, Object>>) arguments.get("terms");
|
||||
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
||||
ResourceConfigUtils.get(arguments, "terms", "term"),
|
||||
"warning.config.condition.all_of.missing_terms"
|
||||
);
|
||||
if (termsArg instanceof Map<?, ?> map) {
|
||||
return new AllOfCondition<>(List.of(factory.apply(MiscUtils.castToMap(map, false))));
|
||||
} else if (termsArg instanceof List<?> list) {
|
||||
List<Condition<CTX>> conditions = new ArrayList<>();
|
||||
for (Map<String, Object> term : terms) {
|
||||
for (Map<String, Object> term : (List<Map<String, Object>>) list) {
|
||||
conditions.add(factory.apply(term));
|
||||
}
|
||||
return new AllOfCondition<>(conditions);
|
||||
} else {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.all_of.invalid_terms_type", termsArg.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ 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.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Factory;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -29,7 +32,7 @@ public class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.ANY_OF;
|
||||
return CommonConditions.ANY_OF;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements Factory<Condition<CTX>> {
|
||||
@@ -42,12 +45,21 @@ public class AnyOfCondition<CTX extends Context> implements Condition<CTX> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
List<Map<String, Object>> terms = (List<Map<String, Object>>) arguments.get("terms");
|
||||
Object termsArg = ResourceConfigUtils.requireNonNullOrThrow(
|
||||
ResourceConfigUtils.get(arguments, "terms", "term"),
|
||||
"warning.config.condition.any_of.missing_terms"
|
||||
);
|
||||
if (termsArg instanceof Map<?, ?> map) {
|
||||
return new AnyOfCondition<>(List.of(factory.apply(MiscUtils.castToMap(map, false))));
|
||||
} else if (termsArg instanceof List<?> list) {
|
||||
List<Condition<CTX>> conditions = new ArrayList<>();
|
||||
for (Map<String, Object> term : terms) {
|
||||
for (Map<String, Object> term : (List<Map<String, Object>>) list) {
|
||||
conditions.add(factory.apply(term));
|
||||
}
|
||||
return new AnyOfCondition<>(conditions);
|
||||
} else {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.any_of.invalid_terms_type", termsArg.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package net.momirealms.craftengine.core.plugin.context.condition;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public final class SharedConditions {
|
||||
private SharedConditions() {}
|
||||
public final class CommonConditions {
|
||||
private CommonConditions() {}
|
||||
|
||||
public static final Key EMPTY = Key.of("craftengine:empty");
|
||||
public static final Key ALL_OF = Key.of("craftengine:all_of");
|
||||
@@ -11,7 +11,7 @@ public class EmptyCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.EMPTY;
|
||||
return CommonConditions.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,8 +5,10 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
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.ResourceConfigUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -23,7 +25,7 @@ public class EnchantmentCondition<CTX extends Context> implements Condition<CTX>
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.ENCHANTMENT;
|
||||
return CommonConditions.ENCHANTMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,9 +41,14 @@ public class EnchantmentCondition<CTX extends Context> implements Condition<CTX>
|
||||
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
String predicate = (String) arguments.get("predicate");
|
||||
String predicate = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("predicate"), "warning.config.condition.enchantment.missing_predicate");
|
||||
String[] split = predicate.split("(<=|>=|<|>|==|=)", 2);
|
||||
int level = Integer.parseInt(split[1]);
|
||||
int level;
|
||||
try {
|
||||
level = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.enchantment.invalid_predicate", e, predicate);
|
||||
}
|
||||
String operator = predicate.substring(split[0].length(), predicate.length() - split[1].length());
|
||||
Function<Integer, Boolean> expression;
|
||||
switch (operator) {
|
||||
@@ -50,7 +57,7 @@ public class EnchantmentCondition<CTX extends Context> implements Condition<CTX>
|
||||
case "==", "=" -> expression = (i -> i == level);
|
||||
case "<=" -> expression = (i -> i <= level);
|
||||
case ">=" -> expression = (i -> i >= level);
|
||||
default -> throw new IllegalArgumentException("Unknown operator: " + operator);
|
||||
default -> throw new LocalizedResourceConfigException("warning.config.condition.enchantment.invalid_predicate", predicate);
|
||||
}
|
||||
return new EnchantmentCondition<>(Key.of(split[0]), expression);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class FallingBlockCondition<CTX extends Context> implements Condition<CTX
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.FALLING_BLOCK;
|
||||
return CommonConditions.FALLING_BLOCK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,9 +2,14 @@ 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.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Factory;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -22,7 +27,7 @@ public class InvertedCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.INVERTED;
|
||||
return CommonConditions.INVERTED;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements Factory<Condition<CTX>> {
|
||||
@@ -35,8 +40,21 @@ public class InvertedCondition<CTX extends Context> implements Condition<CTX> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
Map<String, Object> term = (Map<String, Object>) arguments.get("term");
|
||||
return new InvertedCondition<>(this.factory.apply(term));
|
||||
Object termObj = ResourceConfigUtils.requireNonNullOrThrow(
|
||||
ResourceConfigUtils.get(arguments, "term", "terms"),
|
||||
"warning.config.condition.inverted.missing_term"
|
||||
);
|
||||
if (termObj instanceof Map<?,?> map) {
|
||||
return new InvertedCondition<>(this.factory.apply(MiscUtils.castToMap(map, false)));
|
||||
} else if (termObj instanceof List<?> list) {
|
||||
List<Condition<CTX>> conditions = new ArrayList<>();
|
||||
for (Map<String, Object> term : (List<Map<String, Object>>) list) {
|
||||
conditions.add(factory.apply(term));
|
||||
}
|
||||
return new InvertedCondition<>(new AllOfCondition<>(conditions));
|
||||
} else {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.inverted.invalid_term_type", termObj.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import net.momirealms.craftengine.core.block.properties.Property;
|
||||
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;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,7 +21,7 @@ public class MatchBlockPropertyCondition<CTX extends Context> implements Conditi
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.MATCH_BLOCK_PROPERTY;
|
||||
return CommonConditions.MATCH_BLOCK_PROPERTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,15 +43,11 @@ public class MatchBlockPropertyCondition<CTX extends Context> implements Conditi
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements Factory<Condition<CTX>> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
Map<String, Object> properties = (Map<String, Object>) arguments.get("properties");
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("Missing 'properties' argument for 'match_block_property'");
|
||||
}
|
||||
Object propertyObj = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("properties"), "warning.config.condition.match_block_property.missing_properties");
|
||||
List<Pair<String, String>> propertyList = new ArrayList<>();
|
||||
for (Map.Entry<String, Object> entry : properties.entrySet()) {
|
||||
for (Map.Entry<String, Object> entry : MiscUtils.castToMap(propertyObj, false).entrySet()) {
|
||||
propertyList.add(new Pair<>(entry.getKey(), entry.getValue().toString()));
|
||||
}
|
||||
return new MatchBlockPropertyCondition<>(propertyList);
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
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.MiscUtils;
|
||||
@@ -21,7 +22,7 @@ public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.MATCH_ITEM;
|
||||
return CommonConditions.MATCH_ITEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +48,9 @@ public class MatchItemCondition<CTX extends Context> implements Condition<CTX> {
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
List<String> ids = MiscUtils.getAsStringList(arguments.get("id"));
|
||||
if (ids.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.match_item.missing_id");
|
||||
}
|
||||
boolean regex = (boolean) arguments.getOrDefault("regex", false);
|
||||
return new MatchItemCondition<>(ids, regex);
|
||||
}
|
||||
|
||||
@@ -2,35 +2,36 @@ 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.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
|
||||
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<CTX extends Context> implements Condition<CTX> {
|
||||
private final float chance;
|
||||
private final NumberProvider chance;
|
||||
|
||||
public RandomCondition(float chance) {
|
||||
public RandomCondition(NumberProvider chance) {
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.RANDOM;
|
||||
return CommonConditions.RANDOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CTX ctx) {
|
||||
return RandomUtils.generateRandomFloat(0, 1) < this.chance;
|
||||
return RandomUtils.generateRandomFloat(0, 1) < this.chance.getFloat(ctx);
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> implements Factory<Condition<CTX>> {
|
||||
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
float provider = ResourceConfigUtils.getAsFloat(arguments.getOrDefault("value", 0.5f), "value");
|
||||
NumberProvider provider = NumberProviders.fromObject(arguments.getOrDefault("value", 0.5f));
|
||||
return new RandomCondition<>(provider);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SurvivesExplosionCondition<CTX extends Context> implements Conditio
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.SURVIVES_EXPLOSION;
|
||||
return CommonConditions.SURVIVES_EXPLOSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TableBonusCondition<CTX extends Context> implements Condition<CTX>
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return SharedConditions.TABLE_BONUS;
|
||||
return CommonConditions.TABLE_BONUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +44,7 @@ public class TableBonusCondition<CTX extends Context> implements Condition<CTX>
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
Object enchantmentObj = arguments.get("enchantment");
|
||||
if (enchantmentObj == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.loot_table.condition.table_bonus.missing_enchantment");
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_enchantment");
|
||||
}
|
||||
Key enchantmentType = Key.of(enchantmentObj.toString());
|
||||
Object chances = arguments.get("chances");
|
||||
@@ -59,7 +59,7 @@ public class TableBonusCondition<CTX extends Context> implements Condition<CTX>
|
||||
return new TableBonusCondition<>(enchantmentType, values);
|
||||
}
|
||||
}
|
||||
throw new LocalizedResourceConfigException("warning.config.loot_table.condition.table_bonus.missing_chances");
|
||||
throw new LocalizedResourceConfigException("warning.config.condition.table_bonus.missing_chances");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.number;
|
||||
|
||||
import com.ezylang.evalex.EvaluationException;
|
||||
import com.ezylang.evalex.Expression;
|
||||
import com.ezylang.evalex.parser.ParseException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
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 ExpressionNumberProvider implements NumberProvider {
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
private final String expr;
|
||||
|
||||
public ExpressionNumberProvider(String expr) {
|
||||
this.expr = expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(Context context) {
|
||||
Component resultComponent = AdventureHelper.customMiniMessage().deserialize(this.expr, context.tagResolvers());
|
||||
String resultString = AdventureHelper.plainTextContent(resultComponent);
|
||||
Expression expression = new Expression(resultString);
|
||||
try {
|
||||
return expression.evaluate().getNumberValue().floatValue();
|
||||
} catch (EvaluationException | ParseException e) {
|
||||
throw new RuntimeException("Invalid expression: " + this.expr + " -> " + resultString + " -> Cannot parse", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return NumberProviders.EXPRESSION;
|
||||
}
|
||||
|
||||
public String expression() {
|
||||
return this.expr;
|
||||
}
|
||||
|
||||
public static class FactoryImpl implements Factory<NumberProvider> {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
String value = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("expression"), "warning.config.number.expression.missing_expression");
|
||||
return new ExpressionNumberProvider(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.number;
|
||||
|
||||
import com.ezylang.evalex.Expression;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
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.ResourceConfigUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FixedNumberProvider implements NumberProvider {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
private final float value;
|
||||
|
||||
public FixedNumberProvider(float value) {
|
||||
@@ -23,11 +27,22 @@ public class FixedNumberProvider implements NumberProvider {
|
||||
return NumberProviders.FIXED;
|
||||
}
|
||||
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
public static class FactoryImpl implements Factory<NumberProvider> {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
Number value = (Number) arguments.get("value");
|
||||
return new FixedNumberProvider(value.floatValue());
|
||||
String plainOrExpression = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value"), "warning.config.number.fixed.missing_value");
|
||||
try {
|
||||
float value = Float.parseFloat(plainOrExpression);
|
||||
return new FixedNumberProvider(value);
|
||||
} catch (NumberFormatException e) {
|
||||
Expression expression = new Expression(plainOrExpression);
|
||||
try {
|
||||
return new FixedNumberProvider(expression.evaluate().getNumberValue().floatValue());
|
||||
} catch (Exception e1) {
|
||||
throw new LocalizedResourceConfigException("warning.config.number.fixed.invalid_value", e1, plainOrExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.number;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface NumberProviderFactory {
|
||||
|
||||
NumberProvider create(Map<String, Object> arguments);
|
||||
}
|
||||
@@ -5,26 +5,30 @@ 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 software.amazon.awssdk.services.s3.endpoints.internal.Value;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NumberProviders {
|
||||
public static final Key FIXED = Key.of("craftengine:constant");
|
||||
public static final Key FIXED = Key.of("craftengine:fixed");
|
||||
public static final Key CONSTANT = Key.of("craftengine:constant");
|
||||
public static final Key UNIFORM = Key.of("craftengine:uniform");
|
||||
public static final Key EXPRESSION = Key.of("craftengine:expression");
|
||||
|
||||
static {
|
||||
register(FIXED, FixedNumberProvider.FACTORY);
|
||||
register(CONSTANT, FixedNumberProvider.FACTORY);
|
||||
register(UNIFORM, UniformNumberProvider.FACTORY);
|
||||
register(EXPRESSION, ExpressionNumberProvider.FACTORY);
|
||||
}
|
||||
|
||||
public static void register(Key key, NumberProviderFactory factory) {
|
||||
Holder.Reference<NumberProviderFactory> holder = ((WritableRegistry<NumberProviderFactory>) BuiltInRegistries.NUMBER_PROVIDER_FACTORY)
|
||||
public static void register(Key key, Factory<NumberProvider> factory) {
|
||||
Holder.Reference<Factory<NumberProvider>> holder = ((WritableRegistry<Factory<NumberProvider>>) BuiltInRegistries.NUMBER_PROVIDER_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.NUMBER_PROVIDER_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
}
|
||||
@@ -41,7 +45,7 @@ public class NumberProviders {
|
||||
public static NumberProvider fromMap(Map<String, Object> map) {
|
||||
String type = ResourceConfigUtils.requireNonEmptyStringOrThrow(map.get("type"), "warning.config.loot_table.number.missing_type");
|
||||
Key key = Key.withDefaultNamespace(type, Key.DEFAULT_NAMESPACE);
|
||||
NumberProviderFactory factory = BuiltInRegistries.NUMBER_PROVIDER_FACTORY.getValue(key);
|
||||
Factory<NumberProvider> factory = BuiltInRegistries.NUMBER_PROVIDER_FACTORY.getValue(key);
|
||||
if (factory == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.loot_table.number.invalid_type", type);
|
||||
}
|
||||
@@ -51,31 +55,33 @@ public class NumberProviders {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static NumberProvider fromObject(Object object) {
|
||||
if (object == null) {
|
||||
throw new NullPointerException("number argument is null");
|
||||
throw new LocalizedResourceConfigException("warning.config.number.missing_argument");
|
||||
}
|
||||
if (object instanceof Number number) {
|
||||
return new FixedNumberProvider(number.floatValue());
|
||||
} else if (object instanceof String string) {
|
||||
} else if (object instanceof Map<?,?> map) {
|
||||
return fromMap((Map<String, Object>) map);
|
||||
} else {
|
||||
String string = object.toString();
|
||||
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));
|
||||
NumberProvider min = fromObject(string.substring(0, first));
|
||||
NumberProvider max = fromObject(string.substring(first + 1));
|
||||
return new UniformNumberProvider(min, max);
|
||||
} catch (NumberFormatException e) {
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Illegal number format: " + string);
|
||||
throw new LocalizedResourceConfigException("warning.config.number.invalid_format", string);
|
||||
}
|
||||
} else if (string.contains("<") && string.contains(">") && string.contains(":")) {
|
||||
return new ExpressionNumberProvider(string);
|
||||
} else {
|
||||
try {
|
||||
return new FixedNumberProvider(Float.parseFloat(string));
|
||||
}
|
||||
} else if (object instanceof Map<?,?> map) {
|
||||
return fromMap((Map<String, Object>) map);
|
||||
}
|
||||
throw new IllegalArgumentException("Can't convert " + object + " to " + NumberProvider.class.getSimpleName());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new LocalizedResourceConfigException("warning.config.number.invalid_format", e, string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.number;
|
||||
|
||||
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 UniformNumberProvider implements NumberProvider {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
private final NumberProvider min;
|
||||
private final NumberProvider max;
|
||||
|
||||
@@ -16,14 +18,17 @@ public class UniformNumberProvider implements NumberProvider {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public UniformNumberProvider(float min, float max) {
|
||||
this.min = new FixedNumberProvider(min);
|
||||
this.max = new FixedNumberProvider(max);
|
||||
public NumberProvider max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public NumberProvider min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(Context context) {
|
||||
return RandomUtils.generateRandomInt(this.min.getInt(context), this.max.getInt(context));
|
||||
return RandomUtils.generateRandomInt(this.min.getInt(context), this.max.getInt(context) + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,11 +41,12 @@ public class UniformNumberProvider implements NumberProvider {
|
||||
return NumberProviders.UNIFORM;
|
||||
}
|
||||
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
public static class FactoryImpl implements Factory<NumberProvider> {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
Object min = arguments.getOrDefault("min", 1);
|
||||
Object max = arguments.getOrDefault("max", 1);
|
||||
Object min = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("min"), "warning.config.number.uniform.missing_min");
|
||||
Object max = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("max"), "warning.config.number.uniform.missing_max");
|
||||
return new UniformNumberProvider(NumberProviders.fromObject(min), NumberProviders.fromObject(max));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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.plugin.context.ContextKey;
|
||||
@@ -13,10 +12,8 @@ public final class CommonParameters {
|
||||
|
||||
public static final ContextKey<Double> RANDOM = ContextKey.of("random");
|
||||
public static final ContextKey<Double> LAST_RANDOM = ContextKey.of("last_random");
|
||||
|
||||
public static final ContextKey<Vec3d> LOCATION = ContextKey.of("location");
|
||||
public static final ContextKey<World> WORLD = ContextKey.of("world");
|
||||
public static final ContextKey<Entity> ENTITY = ContextKey.of("entity");
|
||||
public static final ContextKey<Boolean> FALLING_BLOCK = ContextKey.of("falling_block");
|
||||
public static final ContextKey<Float> EXPLOSION_RADIUS = ContextKey.of("explosion_radius");
|
||||
public static final ContextKey<Player> PLAYER = ContextKey.of("player");
|
||||
|
||||
@@ -137,7 +137,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(element.gui().currentPage()))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(element.gui().maxPages()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next));
|
||||
}, true)
|
||||
)
|
||||
@@ -147,7 +147,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(element.gui().currentPage()))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(element.gui().maxPages()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous));
|
||||
}, false)
|
||||
);
|
||||
@@ -177,7 +177,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.BROWSER_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.BROWSER_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
)
|
||||
.addIngredient('A', Ingredient.paged())
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.CATEGORY_BACK : Constants.CATEGORY_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.CATEGORY_BACK : Constants.CATEGORY_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -211,7 +211,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(element.gui().currentPage()))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(element.gui().maxPages()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next));
|
||||
}, true)
|
||||
)
|
||||
@@ -221,7 +221,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(element.gui().currentPage()))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(element.gui().maxPages()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous));
|
||||
}, false)
|
||||
);
|
||||
@@ -292,7 +292,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.CATEGORY_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.CATEGORY_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -332,7 +332,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}) : GuiElement.EMPTY)
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -353,7 +353,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_NONE_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_NONE_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -431,7 +431,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}) : GuiElement.EMPTY)
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -448,7 +448,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
@@ -461,7 +461,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
@@ -578,7 +578,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_SMITHING_TRANSFORM_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_SMITHING_TRANSFORM_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -664,7 +664,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}))
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -681,7 +681,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
@@ -694,7 +694,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
@@ -711,7 +711,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_STONECUTTING_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_STONECUTTING_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -764,7 +764,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.COOKING_TIME, String.valueOf(recipe.cookingTime()))
|
||||
.withParameter(GuiParameters.COOKING_EXPERIENCE, String.valueOf(recipe.experience()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + Constants.RECIPE_COOKING_INFO)), (e, c) -> c.cancel()))
|
||||
.addIngredient('^', player.hasPermission(GET_ITEM_PERMISSION) ? GuiElement.constant(this.plugin.itemManager().createWrappedItem(Constants.RECIPE_GET_ITEM, player), (e, c) -> {
|
||||
c.cancel();
|
||||
@@ -803,7 +803,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}))
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -820,7 +820,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
@@ -833,7 +833,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
@@ -861,7 +861,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(title, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(title, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
@@ -916,7 +916,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
}) : GuiElement.EMPTY)
|
||||
.addIngredient('=', GuiElement.constant(this.plugin.itemManager().getCustomItem(parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT)
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.EMPTY)))
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + (parentGui != null ? Constants.RECIPE_BACK : Constants.RECIPE_EXIT))),
|
||||
((element, click) -> {
|
||||
click.cancel();
|
||||
@@ -933,7 +933,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + next)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index + 1 < recipes.size()) {
|
||||
@@ -946,7 +946,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
.map(it -> it.buildItem(ItemBuildContext.of(player, ContextHolder.builder()
|
||||
.withParameter(GuiParameters.CURRENT_PAGE, String.valueOf(index + 1))
|
||||
.withParameter(GuiParameters.MAX_PAGE, String.valueOf(recipes.size()))
|
||||
.build())))
|
||||
)))
|
||||
.orElseThrow(() -> new GuiElementMissingException("Can't find gui element " + previous)), (e, c) -> {
|
||||
c.cancel();
|
||||
if (index > 0) {
|
||||
@@ -1056,7 +1056,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
})
|
||||
.build()
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_CRAFTING_TITLE, PlayerOptionalContext.of(player, ContextHolder.EMPTY).tagResolvers()))
|
||||
.title(AdventureHelper.miniMessage().deserialize(Constants.RECIPE_CRAFTING_TITLE, PlayerOptionalContext.of(player).tagResolvers()))
|
||||
.refresh()
|
||||
.open(player);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ 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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -29,13 +28,13 @@ public class NamedArgumentTag implements TagResolver {
|
||||
if (!has(name)) {
|
||||
return null;
|
||||
}
|
||||
String argumentKey = arguments.popOr("No argument key provided").toString();
|
||||
ContextKey<?> key = ContextKey.of(Key.withDefaultNamespace(argumentKey, Key.DEFAULT_NAMESPACE));
|
||||
ContextKey<?> key = ContextKey.of(arguments.popOr("No argument key provided").toString());
|
||||
Optional<?> optional = this.context.getOptionalParameter(key);
|
||||
if (optional.isEmpty()) {
|
||||
throw ctx.newException("Invalid argument key", arguments);
|
||||
Object value = optional.orElse(null);
|
||||
if (value == null) {
|
||||
value = arguments.popOr("No default value provided").toString();
|
||||
}
|
||||
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(String.valueOf(optional.get()), this.context.tagResolvers()));
|
||||
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(String.valueOf(value), this.context.tagResolvers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,11 @@ public class PlaceholderTag implements TagResolver {
|
||||
if (!this.has(name) || !CraftEngine.instance().compatibilityManager().hasPlaceholderAPI()) {
|
||||
return null;
|
||||
}
|
||||
String placeholder = arguments.popOr("No argument placeholder provided").toString();
|
||||
String parsed = CraftEngine.instance().compatibilityManager().parse(player, "%" + placeholder + "%");
|
||||
String placeholder = "%" + arguments.popOr("No argument placeholder provided") + "%";
|
||||
String parsed = CraftEngine.instance().compatibilityManager().parse(player, placeholder);
|
||||
if (parsed.equals(placeholder)) {
|
||||
parsed = arguments.popOr("No default papi value provided").toString();
|
||||
}
|
||||
return Tag.inserting(AdventureHelper.miniMessage().deserialize(parsed));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ 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.plugin.context.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.util.Factory;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
@@ -35,7 +35,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<LootFunctionFactory<?>> LOOT_FUNCTION_FACTORY = createRegistry(Registries.LOOT_FUNCTION_FACTORY);
|
||||
public static final Registry<Factory<Condition<LootContext>>> LOOT_CONDITION_FACTORY = createRegistry(Registries.LOOT_CONDITION_FACTORY);
|
||||
public static final Registry<LootEntryContainerFactory<?>> LOOT_ENTRY_CONTAINER_FACTORY = createRegistry(Registries.LOOT_ENTRY_CONTAINER_FACTORY);
|
||||
public static final Registry<NumberProviderFactory> NUMBER_PROVIDER_FACTORY = createRegistry(Registries.NUMBER_PROVIDER_FACTORY);
|
||||
public static final Registry<Factory<NumberProvider>> NUMBER_PROVIDER_FACTORY = createRegistry(Registries.NUMBER_PROVIDER_FACTORY);
|
||||
public static final Registry<ItemBehaviorFactory> ITEM_BEHAVIOR_FACTORY = createRegistry(Registries.ITEM_BEHAVIOR_FACTORY);
|
||||
public static final Registry<TemplateArgumentFactory> TEMPLATE_ARGUMENT_FACTORY = createRegistry(Registries.TEMPLATE_ARGUMENT_FACTORY);
|
||||
public static final Registry<ItemModelFactory> ITEM_MODEL_FACTORY = createRegistry(Registries.ITEM_MODEL_FACTORY);
|
||||
|
||||
@@ -22,7 +22,7 @@ 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.plugin.context.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.util.Factory;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
@@ -37,7 +37,7 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<LootFunctionFactory<?>>> LOOT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_function_factory"));
|
||||
public static final ResourceKey<Registry<LootEntryContainerFactory<?>>> LOOT_ENTRY_CONTAINER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_entry_container_factory"));
|
||||
public static final ResourceKey<Registry<Factory<Condition<LootContext>>>> LOOT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("loot_condition_factory"));
|
||||
public static final ResourceKey<Registry<NumberProviderFactory>> NUMBER_PROVIDER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_factory"));
|
||||
public static final ResourceKey<Registry<Factory<NumberProvider>>> NUMBER_PROVIDER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("number_provider_factory"));
|
||||
public static final ResourceKey<Registry<TemplateArgumentFactory>> TEMPLATE_ARGUMENT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("template_argument_factory"));
|
||||
public static final ResourceKey<Registry<ItemModelFactory>> ITEM_MODEL_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("item_model_factory"));
|
||||
public static final ResourceKey<Registry<TintFactory>> TINT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("tint_factory"));
|
||||
|
||||
@@ -1,37 +1,25 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RandomUtils {
|
||||
private final Random random;
|
||||
public final class RandomUtils {
|
||||
|
||||
private RandomUtils() {
|
||||
random = ThreadLocalRandom.current();
|
||||
}
|
||||
|
||||
private static class SingletonHolder {
|
||||
private static final RandomUtils INSTANCE = new RandomUtils();
|
||||
}
|
||||
|
||||
private static RandomUtils getInstance() {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
private RandomUtils() {}
|
||||
|
||||
public static double generateRandomDouble(double min, double max) {
|
||||
return min + (max - min) * getInstance().random.nextDouble();
|
||||
return min + (max - min) * ThreadLocalRandom.current().nextDouble();
|
||||
}
|
||||
|
||||
public static float generateRandomFloat(float min, float max) {
|
||||
return min + (max - min) * getInstance().random.nextFloat();
|
||||
return min + (max - min) * ThreadLocalRandom.current().nextFloat();
|
||||
}
|
||||
|
||||
public static int generateRandomInt(int min, int max) {
|
||||
return min >= max ? min : getInstance().random.nextInt(max - min + 1) + min;
|
||||
return min >= max ? min : ThreadLocalRandom.current().nextInt(max - min) + min;
|
||||
}
|
||||
|
||||
public static boolean generateRandomBoolean() {
|
||||
return getInstance().random.nextBoolean();
|
||||
return ThreadLocalRandom.current().nextBoolean();
|
||||
}
|
||||
|
||||
public static double triangle(double mode, double deviation) {
|
||||
@@ -39,7 +27,7 @@ public class RandomUtils {
|
||||
}
|
||||
|
||||
public static <T> T getRandomElementFromArray(T[] array) {
|
||||
int index = getInstance().random.nextInt(array.length);
|
||||
int index = ThreadLocalRandom.current().nextInt(array.length);
|
||||
return array[index];
|
||||
}
|
||||
|
||||
@@ -50,7 +38,7 @@ public class RandomUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] result = (T[]) new Object[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index = getInstance().random.nextInt(array.length - i);
|
||||
int index = ThreadLocalRandom.current().nextInt(array.length - i);
|
||||
result[i] = array[index];
|
||||
array[index] = array[array.length - i - 1];
|
||||
}
|
||||
|
||||
@@ -47,11 +47,11 @@ public class CEChunk {
|
||||
}
|
||||
|
||||
public Map<Integer, BlockEntityState> blockEntities() {
|
||||
return blockEntities;
|
||||
return this.blockEntities;
|
||||
}
|
||||
|
||||
public boolean dirty() {
|
||||
return dirty;
|
||||
return this.dirty;
|
||||
}
|
||||
|
||||
public void setDirty(boolean dirty) {
|
||||
|
||||
Reference in New Issue
Block a user