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

Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
jhqwqmc
2025-05-23 04:50:31 +08:00
15 changed files with 172 additions and 22 deletions

View File

@@ -41,6 +41,8 @@ dependencies {
compileOnly("com.viaversion:viaversion-api:5.3.2")
// Skript
compileOnly("com.github.SkriptLang:Skript:2.11.0")
// AuraSkills
compileOnly("dev.aurelium:auraskills-api-bukkit:2.2.4")
// FAWE
compileOnly(platform("com.intellectualsites.bom:bom-newest:1.52"))
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")

View File

@@ -5,6 +5,7 @@ import net.momirealms.craftengine.bukkit.compatibility.bettermodel.BetterModelMo
import net.momirealms.craftengine.bukkit.compatibility.item.MMOItemsProvider;
import net.momirealms.craftengine.bukkit.compatibility.item.NeigeItemsProvider;
import net.momirealms.craftengine.bukkit.compatibility.legacy.slimeworld.LegacySlimeFormatStorageAdaptor;
import net.momirealms.craftengine.bukkit.compatibility.leveler.AuraSkillsLevelerProvider;
import net.momirealms.craftengine.bukkit.compatibility.modelengine.ModelEngineModel;
import net.momirealms.craftengine.bukkit.compatibility.modelengine.ModelEngineUtils;
import net.momirealms.craftengine.bukkit.compatibility.papi.PlaceholderAPIUtils;
@@ -16,24 +17,36 @@ import net.momirealms.craftengine.bukkit.compatibility.worldedit.WorldEditBlockR
import net.momirealms.craftengine.bukkit.font.BukkitFontManager;
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.core.entity.furniture.AbstractExternalModel;
import net.momirealms.craftengine.core.entity.furniture.ExternalModel;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.compatibility.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.compatibility.LevelerProvider;
import net.momirealms.craftengine.core.plugin.compatibility.ModelProvider;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.VersionHelper;
import net.momirealms.craftengine.core.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
public class BukkitCompatibilityManager implements CompatibilityManager {
private final BukkitCraftEngine plugin;
private final Map<String, ModelProvider> modelProviders;
private final Map<String, LevelerProvider> levelerProviders;
private boolean hasPlaceholderAPI;
private boolean hasViaVersion;
public BukkitCompatibilityManager(BukkitCraftEngine plugin) {
this.plugin = plugin;
this.modelProviders = new HashMap<>(Map.of(
"ModelEngine", ModelEngineModel::new,
"BetterModel", BetterModelModel::new
));
this.levelerProviders = new HashMap<>();
}
@Override
@@ -85,6 +98,14 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
this.initLuckPermsHook();
logHook("LuckPerms");
}
if (this.isPluginEnabled("AuraSkills")) {
this.registerLevelerProvider("AuraSkills", new AuraSkillsLevelerProvider());
}
}
@Override
public void registerLevelerProvider(String plugin, LevelerProvider provider) {
this.levelerProviders.put(plugin, provider);
}
private void logHook(String plugin) {
@@ -92,13 +113,22 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
}
@Override
public AbstractExternalModel createModelEngineModel(String id) {
return new ModelEngineModel(id);
public void addLevelerExp(Player player, String plugin, String target, double value) {
Optional.ofNullable(this.levelerProviders.get(plugin)).ifPresentOrElse(leveler -> leveler.addExp(player, target, value),
() -> this.plugin.logger().warn("[Compatibility] '" + plugin + "' leveler provider not found"));
}
@Override
public AbstractExternalModel createBetterModelModel(String id) {
return new BetterModelModel(id);
public int getLevel(Player player, String plugin, String target) {
return Optional.ofNullable(this.levelerProviders.get(plugin)).map(leveler -> leveler.getLevel(player, target)).orElseGet(() -> {
this.plugin.logger().warn("[Compatibility] '" + plugin + "' leveler provider not found");
return 0;
});
}
@Override
public ExternalModel createModel(String plugin, String id) {
return this.modelProviders.get(plugin).createModel(id);
}
@Override

View File

@@ -0,0 +1,19 @@
package net.momirealms.craftengine.bukkit.compatibility.leveler;
import dev.aurelium.auraskills.api.AuraSkillsApi;
import dev.aurelium.auraskills.api.registry.NamespacedId;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.plugin.compatibility.LevelerProvider;
public class AuraSkillsLevelerProvider implements LevelerProvider {
@Override
public void addExp(Player player, String target, double amount) {
AuraSkillsApi.get().getUser(player.uuid()).addSkillXp(AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)), amount);
}
@Override
public int getLevel(Player player, String target) {
return AuraSkillsApi.get().getUser(player.uuid()).getSkillLevel(AuraSkillsApi.get().getGlobalRegistry().getSkill(NamespacedId.fromDefault(target)));
}
}

View File

@@ -330,6 +330,9 @@ warning.config.function.particle.missing_from: "<yellow>Issue found in file <arg
warning.config.function.particle.missing_to: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'to' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_item: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'item' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_block_state: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'block-state' argument for 'particle' function.</yellow>"
warning.config.function.leveler_exp.missing_count: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'count' argument for 'leveler_exp' function.</yellow>"
warning.config.function.leveler_exp.missing_leveler: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'leveler' argument for 'leveler_exp' function.</yellow>"
warning.config.function.leveler_exp.missing_plugin: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'plugin' argument for 'leveler_exp' function.</yellow>"
warning.config.selector.missing_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'type' argument for selector.</yellow>"
warning.config.selector.invalid_type: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid selector type '<arg:2>'.</yellow>"
warning.config.selector.invalid_target: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is using an invalid selector target '<arg:2>'.</yellow>"

View File

@@ -321,15 +321,18 @@ warning.config.function.open_window.missing_gui_type: "<yellow>在文件 <arg:0>
warning.config.function.open_window.invalid_gui_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 为 'open_window' 函数使用了无效的 GUI 类型 <arg:2>. 允许的类型: [<arg:3>]。</yellow>"
warning.config.function.run.missing_functions: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'run' 函数必需的 'functions' 参数</yellow>"
warning.config.function.place_block.missing_block_state: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'place_block' 函数必需的 'block-state' 参数.</yellow>"
warning.config.function.set_food.missing_food: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'food' argument for 'set_food' function.</yellow>"
warning.config.function.set_saturation.missing_saturation: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'saturation' argument for 'set_saturation' function.</yellow>"
warning.config.function.play_sound.missing_sound: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'sound' argument for 'play_sound' function.</yellow>"
warning.config.function.particle.missing_particle: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'particle' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_color: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'color' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_from: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'from' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_to: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'to' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_item: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'item' argument for 'particle' function.</yellow>"
warning.config.function.particle.missing_block_state: "<yellow>Issue found in file <arg:0> - The config '<arg:1>' is missing the required 'block-state' argument for 'particle' function.</yellow>"
warning.config.function.set_food.missing_food: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'set_food' 函数必需的 'food' 参数</yellow>"
warning.config.function.set_saturation.missing_saturation: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'set_saturation' 函数必需的 'saturation' 参数</yellow>"
warning.config.function.play_sound.missing_sound: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'play_sound' 函数必需的 'sound' 参数</yellow>"
warning.config.function.particle.missing_particle: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'particle' 参数</yellow>"
warning.config.function.particle.missing_color: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'color' 参数</yellow>"
warning.config.function.particle.missing_from: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'from' 参数</yellow>"
warning.config.function.particle.missing_to: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'to' 参数</yellow>"
warning.config.function.particle.missing_item: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'item' 参数</yellow>"
warning.config.function.particle.missing_block_state: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'particle' 函数必需的 'block-state' 参数</yellow>"
warning.config.function.leveler_exp.missing_count: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'leveler_exp' 函数必需的 'count' 参数</yellow>"
warning.config.function.leveler_exp.missing_leveler: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'leveler_exp' 函数必需的 'leveler' 参数</yellow>"
warning.config.function.leveler_exp.missing_plugin: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少 'leveler_exp' 函数必需的 'plugin' 参数</yellow>"
warning.config.selector.missing_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 缺少选择器必需的 'type' 参数</yellow>"
warning.config.selector.invalid_type: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的选择器类型 '<arg:2>'</yellow>"
warning.config.selector.invalid_target: "<yellow>在文件 <arg:0> 中发现问题 - 配置项 '<arg:1>' 使用了无效的选择器目标 '<arg:2>'</yellow>"

View File

@@ -26,7 +26,7 @@ import net.momirealms.craftengine.bukkit.util.EventUtils;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.bukkit.world.BukkitWorldManager;
import net.momirealms.craftengine.core.item.ItemManager;
import net.momirealms.craftengine.core.plugin.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.compatibility.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.classpath.ReflectionClassPathAppender;
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;

View File

@@ -116,9 +116,9 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
// external model providers
Optional<ExternalModel> externalModel;
if (placementArguments.containsKey("model-engine")) {
externalModel = Optional.of(plugin.compatibilityManager().createModelEngineModel(placementArguments.get("model-engine").toString()));
externalModel = Optional.of(plugin.compatibilityManager().createModel("ModelEngine", placementArguments.get("model-engine").toString()));
} else if (placementArguments.containsKey("better-model")) {
externalModel = Optional.of(plugin.compatibilityManager().createBetterModelModel(placementArguments.get("better-model").toString()));
externalModel = Optional.of(plugin.compatibilityManager().createModel("BetterModel", placementArguments.get("better-model").toString()));
} else {
externalModel = Optional.empty();
}

View File

@@ -13,6 +13,7 @@ import net.momirealms.craftengine.core.pack.PackManager;
import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;
import net.momirealms.craftengine.core.plugin.compatibility.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.template.TemplateManager;
import net.momirealms.craftengine.core.plugin.config.template.TemplateManagerImpl;

View File

@@ -11,6 +11,7 @@ import net.momirealms.craftengine.core.loot.VanillaLootManager;
import net.momirealms.craftengine.core.pack.PackManager;
import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;
import net.momirealms.craftengine.core.plugin.compatibility.CompatibilityManager;
import net.momirealms.craftengine.core.plugin.config.Config;
import net.momirealms.craftengine.core.plugin.config.template.TemplateManager;
import net.momirealms.craftengine.core.plugin.context.GlobalVariableManager;

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.core.plugin;
package net.momirealms.craftengine.core.plugin.compatibility;
import net.momirealms.craftengine.core.entity.furniture.AbstractExternalModel;
import net.momirealms.craftengine.core.entity.furniture.ExternalModel;
import net.momirealms.craftengine.core.entity.player.Player;
import java.util.UUID;
@@ -13,9 +14,13 @@ public interface CompatibilityManager {
void onDelayedEnable();
AbstractExternalModel createModelEngineModel(String id);
void registerLevelerProvider(String plugin, LevelerProvider provider);
AbstractExternalModel createBetterModelModel(String id);
void addLevelerExp(Player player, String plugin, String target, double value);
int getLevel(Player player, String plugin, String target);
ExternalModel createModel(String plugin, String id);
int interactionToBaseEntity(int id);

View File

@@ -0,0 +1,10 @@
package net.momirealms.craftengine.core.plugin.compatibility;
import net.momirealms.craftengine.core.entity.player.Player;
public interface LevelerProvider {
void addExp(Player player, String target, double amount);
int getLevel(Player player, String target);
}

View File

@@ -0,0 +1,8 @@
package net.momirealms.craftengine.core.plugin.compatibility;
import net.momirealms.craftengine.core.entity.furniture.ExternalModel;
public interface ModelProvider {
ExternalModel createModel(String id);
}

View File

@@ -35,6 +35,7 @@ public class EventFunctions {
register(CommonFunctions.PLAY_SOUND, new PlaySoundFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.PARTICLE, new ParticleFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.POTION_EFFECT, new PotionEffectFunction.FactoryImpl<>(EventConditions::fromMap));
register(CommonFunctions.LEVELER_EXP, new LevelerExpFunction.FactoryImpl<>(EventConditions::fromMap));
}
public static void register(Key key, FunctionFactory<PlayerOptionalContext> factory) {

View File

@@ -23,5 +23,5 @@ public final class CommonFunctions {
public static final Key SET_SATURATION = Key.of("craftengine:saturation");
public static final Key DROP_LOOT = Key.of("craftengine:drop_loot");
public static final Key SWING_HAND = Key.of("craftengine:swing_hand");
public static final Key PLUGIN_EXP = Key.of("craftengine:plugin_exp");
public static final Key LEVELER_EXP = Key.of("craftengine:leveler_exp");
}

View File

@@ -0,0 +1,67 @@
package net.momirealms.craftengine.core.plugin.context.function;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.context.*;
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.DirectContextParameters;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class LevelerExpFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
private final PlayerSelector<CTX> selector;
private final NumberProvider count;
private final String leveler;
private final String plugin;
public LevelerExpFunction(NumberProvider count, String leveler, String plugin, PlayerSelector<CTX> selector, List<Condition<CTX>> predicates) {
super(predicates);
this.count = count;
this.leveler = leveler;
this.plugin = plugin;
this.selector = selector;
}
@Override
public void runInternal(CTX ctx) {
if (this.selector == null) {
ctx.getOptionalParameter(DirectContextParameters.PLAYER).ifPresent(it -> {
CraftEngine.instance().compatibilityManager().addLevelerExp(it, this.plugin, this.leveler, this.count.getDouble(ctx));
});
} else {
for (Player target : this.selector.get(ctx)) {
RelationalContext relationalContext = ViewerContext.of(ctx, PlayerOptionalContext.of(target, ContextHolder.EMPTY));
CraftEngine.instance().compatibilityManager().addLevelerExp(target, this.plugin, this.leveler, this.count.getDouble(relationalContext));
}
}
}
@Override
public Key type() {
return CommonFunctions.LEVELER_EXP;
}
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
super(factory);
}
@Override
public Function<CTX> create(Map<String, Object> arguments) {
Object count = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("count"), "warning.config.function.leveler_exp.missing_count");
String leveler = ResourceConfigUtils.requireNonEmptyStringOrThrow("leveler", "warning.config.function.leveler_exp.missing_leveler");
String plugin = ResourceConfigUtils.requireNonEmptyStringOrThrow("plugin", "warning.config.function.leveler_exp.missing_plugin");
return new LevelerExpFunction<>(NumberProviders.fromObject(count), leveler, plugin, PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), getPredicates(arguments));
}
}
}