mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
添加全局变量和rel变量解析
This commit is contained in:
@@ -192,6 +192,11 @@ public class BukkitCompatibilityManager implements CompatibilityManager {
|
||||
return PlaceholderAPIUtils.parse((org.bukkit.entity.Player) player.platformPlayer(), text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(Player player1, Player player2, String text) {
|
||||
return PlaceholderAPIUtils.parse((org.bukkit.entity.Player) player1.platformPlayer(), (org.bukkit.entity.Player) player2.platformPlayer(), text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerProtocolVersion(UUID uuid) {
|
||||
return ViaVersionUtils.getPlayerProtocolVersion(uuid);
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.compatibility.papi;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlaceholderAPIUtils {
|
||||
|
||||
@@ -12,6 +13,10 @@ public class PlaceholderAPIUtils {
|
||||
return PlaceholderAPI.setPlaceholders(player, text);
|
||||
}
|
||||
|
||||
public static String parse(Player player1, Player player2, String text) {
|
||||
return PlaceholderAPI.setRelationalPlaceholders(player1, player2, text);
|
||||
}
|
||||
|
||||
public static void registerExpansions(CraftEngine plugin) {
|
||||
new ImageExpansion(plugin).register();
|
||||
new ShiftExpansion(plugin).register();
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.core.advancement.AbstractAdvancementManager;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -31,11 +31,11 @@ public class BukkitAdvancementManager extends AbstractAdvancementManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.advancementParser;
|
||||
}
|
||||
|
||||
public class AdvancementParser implements ConfigSectionParser {
|
||||
public class AdvancementParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"advancements", "advancement"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import net.momirealms.craftengine.core.pack.ResourceLocation;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -193,7 +193,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.blockParser;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class BlockParser implements ConfigSectionParser {
|
||||
public class BlockParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"blocks", "block"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.momirealms.craftengine.core.loot.LootTable;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.sound.SoundData;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -86,11 +86,11 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.furnitureParser;
|
||||
}
|
||||
|
||||
public class FurnitureParser implements ConfigSectionParser {
|
||||
public class FurnitureParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] { "furniture" };
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,7 +27,7 @@ import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.pack.model.select.ChargeTypeSelectProperty;
|
||||
import net.momirealms.craftengine.core.pack.model.select.TrimMaterialSelectProperty;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -164,7 +164,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.itemParser;
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
return wrapped.id();
|
||||
}
|
||||
|
||||
public class ItemParser implements ConfigSectionParser {
|
||||
public class ItemParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.momirealms.craftengine.core.loot.LootTable;
|
||||
import net.momirealms.craftengine.core.loot.VanillaLoot;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.CommonParameters;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
@@ -87,11 +87,11 @@ public class BukkitVanillaLootManager extends AbstractVanillaLootManager impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.vanillaLootParser;
|
||||
}
|
||||
|
||||
public class VanillaLootParser implements ConfigSectionParser {
|
||||
public class VanillaLootParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"vanilla-loots", "vanilla-loot", "loots", "loot"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.momirealms.craftengine.core.advancement;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
|
||||
public interface AdvancementManager extends Manageable {
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.google.gson.JsonElement;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGenerator;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Optional;
|
||||
|
||||
public interface BlockManager extends Manageable, ModelGenerator {
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
Collection<ModelGeneration> modelsToGenerate();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.Entity;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
@@ -15,7 +15,7 @@ import java.util.Optional;
|
||||
public interface FurnitureManager extends Manageable {
|
||||
String FURNITURE_ADMIN_NODE = "craftengine.furniture.admin";
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
void initSuggestions();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.pack.ResourceLocation;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
@@ -75,8 +75,8 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser[] parsers() {
|
||||
return new ConfigSectionParser[] {this.imageParser, this.emojiParser};
|
||||
public ConfigParser[] parsers() {
|
||||
return new ConfigParser[] {this.imageParser, this.emojiParser};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -339,7 +339,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
return this.fonts.computeIfAbsent(key, Font::new);
|
||||
}
|
||||
|
||||
public class EmojiParser implements ConfigSectionParser {
|
||||
public class EmojiParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"emoji", "emojis"};
|
||||
|
||||
@Override
|
||||
@@ -400,7 +400,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class ImageParser implements ConfigSectionParser {
|
||||
public class ImageParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"images", "image"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.CharacterUtils;
|
||||
import net.momirealms.craftengine.core.util.FormatUtils;
|
||||
@@ -45,7 +45,7 @@ public interface FontManager extends Manageable {
|
||||
|
||||
IllegalCharacterProcessResult processIllegalCharacters(String raw, char replacement);
|
||||
|
||||
ConfigSectionParser[] parsers();
|
||||
ConfigParser[] parsers();
|
||||
|
||||
default EmojiTextProcessResult replaceMiniMessageEmoji(@NotNull String miniMessage, @Nullable Player player) {
|
||||
return replaceMiniMessageEmoji(miniMessage, player, Config.maxEmojisPerParse());
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.pack.model.ItemModel;
|
||||
import net.momirealms.craftengine.core.pack.model.LegacyOverridesModel;
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGenerator;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
@@ -17,7 +17,7 @@ import java.util.*;
|
||||
|
||||
public interface ItemManager<T> extends Manageable, ModelGenerator {
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
Map<Key, TreeSet<LegacyOverridesModel>> legacyItemOverrides();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -35,7 +35,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.recipeParser;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public class RecipeParser implements ConfigSectionParser {
|
||||
public class RecipeParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"recipes", "recipe"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.item.recipe;
|
||||
|
||||
import net.momirealms.craftengine.core.item.recipe.input.RecipeInput;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Optional;
|
||||
|
||||
public interface RecipeManager<T> extends Manageable {
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
boolean isDataPackRecipe(Key key);
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package net.momirealms.craftengine.core.loot;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface VanillaLootManager extends Manageable {
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
Optional<VanillaLoot> getBlockLoot(int blockState);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import net.momirealms.craftengine.core.pack.model.generation.ModelGenerator;
|
||||
import net.momirealms.craftengine.core.pack.obfuscation.ObfA;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor;
|
||||
import net.momirealms.craftengine.core.plugin.locale.I18NData;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
@@ -70,8 +70,8 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
private final CraftEngine plugin;
|
||||
private final BiConsumer<Path, Path> eventDispatcher;
|
||||
private final Map<String, Pack> loadedPacks = new HashMap<>();
|
||||
private final Map<String, ConfigSectionParser> sectionParsers = new HashMap<>();
|
||||
private final TreeMap<ConfigSectionParser, List<CachedConfig>> cachedConfigs = new TreeMap<>();
|
||||
private final Map<String, ConfigParser> sectionParsers = new HashMap<>();
|
||||
private final TreeMap<ConfigParser, List<CachedConfig>> cachedConfigs = new TreeMap<>();
|
||||
protected BiConsumer<Path, Path> zipGenerator;
|
||||
protected ResourcePackHost resourcePackHost;
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerConfigSectionParser(ConfigSectionParser parser) {
|
||||
public boolean registerConfigSectionParser(ConfigParser parser) {
|
||||
for (String id : parser.sectionId()) {
|
||||
if (this.sectionParsers.containsKey(id)) return false;
|
||||
}
|
||||
@@ -404,7 +404,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/gui/sprites/tooltip/topaz_frame.png.mcmeta");
|
||||
}
|
||||
|
||||
private void loadResourceConfigs(Predicate<ConfigSectionParser> predicate) {
|
||||
private void loadResourceConfigs(Predicate<ConfigParser> predicate) {
|
||||
long o1 = System.nanoTime();
|
||||
for (Pack pack : loadedPacks()) {
|
||||
if (!pack.enabled()) continue;
|
||||
@@ -435,8 +435,8 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
}
|
||||
long o2 = System.nanoTime();
|
||||
this.plugin.logger().info("Loaded packs. Took " + String.format("%.2f", ((o2 - o1) / 1_000_000.0)) + " ms");
|
||||
for (Map.Entry<ConfigSectionParser, List<CachedConfig>> entry : this.cachedConfigs.entrySet()) {
|
||||
ConfigSectionParser parser = entry.getKey();
|
||||
for (Map.Entry<ConfigParser, List<CachedConfig>> entry : this.cachedConfigs.entrySet()) {
|
||||
ConfigParser parser = entry.getKey();
|
||||
long t1 = System.nanoTime();
|
||||
for (CachedConfig cached : entry.getValue()) {
|
||||
for (Map.Entry<String, Object> configEntry : cached.config().entrySet()) {
|
||||
@@ -444,8 +444,8 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
try {
|
||||
Key id = Key.withDefaultNamespace(key, cached.pack().namespace());
|
||||
try {
|
||||
if (parser.isTemplate()) {
|
||||
this.plugin.templateManager().addTemplate(cached.pack(), cached.filePath(), id, configEntry.getValue());
|
||||
if (parser.supportsParsingObject()) {
|
||||
parser.parseObject(cached.pack(), cached.filePath(), id, configEntry.getValue());
|
||||
} else if (predicate.test(parser)) {
|
||||
if (configEntry.getValue() instanceof Map<?, ?> configSection0) {
|
||||
Map<String, Object> configSection1 = castToMap(configSection0, false);
|
||||
|
||||
@@ -2,17 +2,18 @@ package net.momirealms.craftengine.core.pack;
|
||||
|
||||
public class LoadingSequence {
|
||||
public static final int TEMPLATE = 0;
|
||||
public static final int LANG = 10;
|
||||
public static final int TRANSLATION = 20;
|
||||
public static final int BLOCK = 30;
|
||||
public static final int ITEM = 40;
|
||||
public static final int FURNITURE = 50;
|
||||
public static final int IMAGE = 60;
|
||||
public static final int RECIPE = 70;
|
||||
public static final int CATEGORY = 80;
|
||||
public static final int SOUND = 90;
|
||||
public static final int JUKEBOX_SONG = 100;
|
||||
public static final int VANILLA_LOOTS = 110;
|
||||
public static final int EMOJI = 120;
|
||||
public static final int ADVANCEMENT = 130;
|
||||
public static final int GLOBAL_VAR = 10;
|
||||
public static final int LANG = 20;
|
||||
public static final int TRANSLATION = 30;
|
||||
public static final int BLOCK = 40;
|
||||
public static final int ITEM = 50;
|
||||
public static final int FURNITURE = 60;
|
||||
public static final int IMAGE = 70;
|
||||
public static final int RECIPE = 80;
|
||||
public static final int CATEGORY = 90;
|
||||
public static final int SOUND = 100;
|
||||
public static final int JUKEBOX_SONG = 110;
|
||||
public static final int VANILLA_LOOTS = 120;
|
||||
public static final int EMOJI = 130;
|
||||
public static final int ADVANCEMENT = 140;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.pack;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -16,17 +16,17 @@ public interface PackManager extends Manageable {
|
||||
@NotNull
|
||||
Collection<Pack> loadedPacks();
|
||||
|
||||
boolean registerConfigSectionParser(ConfigSectionParser parser);
|
||||
boolean registerConfigSectionParser(ConfigParser parser);
|
||||
|
||||
default void registerConfigSectionParsers(ConfigSectionParser[] parsers) {
|
||||
for (ConfigSectionParser parser : parsers) {
|
||||
default void registerConfigSectionParsers(ConfigParser[] parsers) {
|
||||
for (ConfigParser parser : parsers) {
|
||||
registerConfigSectionParser(parser);
|
||||
}
|
||||
}
|
||||
|
||||
boolean unregisterConfigSectionParser(String id);
|
||||
|
||||
default void unregisterConfigSectionParser(ConfigSectionParser parser) {
|
||||
default void unregisterConfigSectionParser(ConfigParser parser) {
|
||||
for (String id : parser.sectionId()) {
|
||||
unregisterConfigSectionParser(id);
|
||||
}
|
||||
|
||||
@@ -27,5 +27,7 @@ public interface CompatibilityManager {
|
||||
|
||||
String parse(Player player, String text);
|
||||
|
||||
String parse(Player player1, Player player2, String text);
|
||||
|
||||
int getPlayerProtocolVersion(UUID uuid);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;
|
||||
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;
|
||||
import net.momirealms.craftengine.core.plugin.context.GlobalVariableManager;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.Dependencies;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.Dependency;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.DependencyManager;
|
||||
@@ -68,6 +69,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
protected VanillaLootManager vanillaLootManager;
|
||||
protected AdvancementManager advancementManager;
|
||||
protected CompatibilityManager compatibilityManager;
|
||||
protected GlobalVariableManager globalVariableManager;
|
||||
|
||||
private final Consumer<CraftEngine> reloadEventDispatcher;
|
||||
private boolean isReloading;
|
||||
@@ -133,6 +135,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.translationManager.reload();
|
||||
// clear the outdated cache by reloading the managers
|
||||
this.templateManager.reload();
|
||||
this.globalVariableManager.reload();
|
||||
this.furnitureManager.reload();
|
||||
this.fontManager.reload();
|
||||
this.itemManager.reload();
|
||||
@@ -198,6 +201,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.isInitializing = true;
|
||||
this.networkManager.init();
|
||||
this.templateManager = new TemplateManagerImpl();
|
||||
this.globalVariableManager = new GlobalVariableManager();
|
||||
this.itemBrowserManager = new ItemBrowserManagerImpl(this);
|
||||
this.commandManager.registerDefaultFeatures();
|
||||
// delay the reload so other plugins can register some custom parsers
|
||||
@@ -245,6 +249,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
if (this.soundManager != null) this.soundManager.disable();
|
||||
if (this.vanillaLootManager != null) this.vanillaLootManager.disable();
|
||||
if (this.translationManager != null) this.translationManager.disable();
|
||||
if (this.globalVariableManager != null) this.globalVariableManager.disable();
|
||||
if (this.scheduler != null) this.scheduler.shutdownScheduler();
|
||||
if (this.scheduler != null) this.scheduler.shutdownExecutor();
|
||||
if (this.commandManager != null) this.commandManager.unregisterFeatures();
|
||||
@@ -255,6 +260,8 @@ public abstract class CraftEngine implements Plugin {
|
||||
protected void registerDefaultParsers() {
|
||||
// register template parser
|
||||
this.packManager.registerConfigSectionParser(this.templateManager.parser());
|
||||
// register global variables parser
|
||||
this.packManager.registerConfigSectionParser(this.globalVariableManager.parser());
|
||||
// register font parser
|
||||
this.packManager.registerConfigSectionParsers(this.fontManager.parsers());
|
||||
// register item parser
|
||||
@@ -430,6 +437,11 @@ public abstract class CraftEngine implements Plugin {
|
||||
return compatibilityManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GlobalVariableManager globalVariableManager() {
|
||||
return globalVariableManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Platform platform() {
|
||||
return platform;
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
|
||||
import net.momirealms.craftengine.core.plugin.command.sender.SenderFactory;
|
||||
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;
|
||||
import net.momirealms.craftengine.core.plugin.dependency.DependencyManager;
|
||||
import net.momirealms.craftengine.core.plugin.gui.GuiManager;
|
||||
import net.momirealms.craftengine.core.plugin.gui.category.ItemBrowserManager;
|
||||
@@ -91,5 +92,7 @@ public interface Plugin {
|
||||
|
||||
CompatibilityManager compatibilityManager();
|
||||
|
||||
GlobalVariableManager globalVariableManager();
|
||||
|
||||
Platform platform();
|
||||
}
|
||||
|
||||
@@ -8,20 +8,25 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ConfigSectionParser extends Comparable<ConfigSectionParser> {
|
||||
public interface ConfigParser extends Comparable<ConfigParser> {
|
||||
|
||||
String[] sectionId();
|
||||
|
||||
void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) throws LocalizedException;
|
||||
default void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) throws LocalizedException {
|
||||
this.parseObject(pack, path, id, section);
|
||||
}
|
||||
|
||||
default void parseObject(Pack pack, Path path, Key id, Object object) throws LocalizedException {
|
||||
}
|
||||
|
||||
int loadingSequence();
|
||||
|
||||
default boolean isTemplate() {
|
||||
default boolean supportsParsingObject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
default int compareTo(@NotNull ConfigSectionParser another) {
|
||||
default int compareTo(@NotNull ConfigParser another) {
|
||||
return Integer.compare(loadingSequence(), another.loadingSequence());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,8 @@
|
||||
package net.momirealms.craftengine.core.plugin.config.template;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -17,9 +14,7 @@ public interface TemplateManager extends Manageable {
|
||||
String OVERRIDES = "overrides";
|
||||
String ARGUMENTS = "arguments";
|
||||
|
||||
ConfigSectionParser parser();
|
||||
|
||||
void addTemplate(Pack pack, Path path, Key id, Object obj);
|
||||
ConfigParser parser();
|
||||
|
||||
Map<String, Object> applyTemplates(Map<String, Object> input);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.momirealms.craftengine.core.plugin.config.template;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.GsonHelper;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
@@ -24,7 +24,7 @@ public class TemplateManagerImpl implements TemplateManager {
|
||||
this.templateParser = new TemplateParser();
|
||||
}
|
||||
|
||||
public class TemplateParser implements ConfigSectionParser {
|
||||
public class TemplateParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"templates", "template"};
|
||||
|
||||
@Override
|
||||
@@ -38,13 +38,16 @@ public class TemplateManagerImpl implements TemplateManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemplate() {
|
||||
public boolean supportsParsingObject() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseSection(Pack pack, Path path, Key id, Map<String, Object> section) {
|
||||
addTemplate(pack, path, id, section);
|
||||
public void parseObject(Pack pack, Path path, Key id, Object obj) {
|
||||
if (templates.containsKey(id)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.template.duplicate", path.toString(), id.toString());
|
||||
}
|
||||
templates.put(id, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,18 +57,10 @@ public class TemplateManagerImpl implements TemplateManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.templateParser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTemplate(Pack pack, Path path, Key id, Object obj) {
|
||||
if (this.templates.containsKey(id)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.template.duplicate", path.toString(), id.toString());
|
||||
}
|
||||
this.templates.put(id, obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> applyTemplates(Map<String, Object> input) {
|
||||
Objects.requireNonNull(input, "Input must not be null");
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class AbstractCommonContext implements Context {
|
||||
public TagResolver[] tagResolvers() {
|
||||
if (this.tagResolvers == null) {
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new I18NTag(this), new NamedArgumentTag(this),
|
||||
new PlaceholderTag(null), new ExpressionTag(this)};
|
||||
new PlaceholderTag(null), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package net.momirealms.craftengine.core.plugin.context;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GlobalVariableManager implements Manageable {
|
||||
private final Map<String, String> globalVariables = new HashMap<>();
|
||||
private final GlobalVariableParser parser = new GlobalVariableParser();
|
||||
|
||||
@Nullable
|
||||
public String get(final String key) {
|
||||
return this.globalVariables.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.globalVariables.clear();
|
||||
}
|
||||
|
||||
public ConfigParser parser() {
|
||||
return this.parser;
|
||||
}
|
||||
|
||||
public class GlobalVariableParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"global-variables", "global-variable"};
|
||||
|
||||
@Override
|
||||
public int loadingSequence() {
|
||||
return LoadingSequence.GLOBAL_VAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParsingObject() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseObject(Pack pack, Path path, net.momirealms.craftengine.core.util.Key id, Object object) throws LocalizedException {
|
||||
if (object != null) {
|
||||
globalVariables.put(id.value(), object.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,11 +48,16 @@ public class PlayerOptionalContext extends AbstractAdditionalParameterContext im
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public boolean isPlayerPresent() {
|
||||
return this.player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TagResolver[] tagResolvers() {
|
||||
if (this.tagResolvers == null) {
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new PlaceholderTag(this.player), new I18NTag(this), new NamedArgumentTag(this), new ExpressionTag(this)};
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new PlaceholderTag(this.player), new I18NTag(this),
|
||||
new NamedArgumentTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
|
||||
@@ -57,10 +57,18 @@ public class ViewerContext implements RelationalContext {
|
||||
if (this.owner instanceof PlayerOptionalContext context) {
|
||||
optionalOwner = context.player();
|
||||
}
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE,
|
||||
new PlaceholderTag(optionalOwner), new ViewerPlaceholderTag(this.viewer.player()),
|
||||
new NamedArgumentTag(this.owner), new ViewerNamedArgumentTag(this.viewer),
|
||||
new I18NTag(this), new ExpressionTag(this)};
|
||||
if (optionalOwner != null && this.viewer.player != null) {
|
||||
this.tagResolvers = new TagResolver[]{new RelationalPlaceholderTag(optionalOwner, this.viewer.player),
|
||||
ShiftTag.INSTANCE, ImageTag.INSTANCE,
|
||||
new PlaceholderTag(optionalOwner), new ViewerPlaceholderTag(this.viewer.player()),
|
||||
new NamedArgumentTag(this.owner), new ViewerNamedArgumentTag(this.viewer),
|
||||
new I18NTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
} else {
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE,
|
||||
new PlaceholderTag(optionalOwner), new ViewerPlaceholderTag(this.viewer.player()),
|
||||
new NamedArgumentTag(this.owner), new ViewerNamedArgumentTag(this.viewer),
|
||||
new I18NTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.gui.Gui;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
@@ -19,7 +19,7 @@ public interface ItemBrowserManager extends Manageable {
|
||||
int MAX_RECIPE_DEPTH = 16;
|
||||
String GET_ITEM_PERMISSION = "craftengine.browser.get_item";
|
||||
|
||||
ConfigSectionParser parser();
|
||||
ConfigParser parser();
|
||||
|
||||
void addExternalCategoryMember(Key item, List<Key> category);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.item.recipe.*;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.gui.*;
|
||||
@@ -68,7 +68,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser parser() {
|
||||
public ConfigParser parser() {
|
||||
return this.categoryParser;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
|
||||
return Optional.ofNullable(this.byId.get(key));
|
||||
}
|
||||
|
||||
public class CategoryParser implements ConfigSectionParser {
|
||||
public class CategoryParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"categories", "category"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.momirealms.craftengine.core.plugin.locale;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
@@ -44,7 +44,7 @@ public interface TranslationManager extends Manageable {
|
||||
return TranslationManagerImpl.instance;
|
||||
}
|
||||
|
||||
ConfigSectionParser[] parsers();
|
||||
ConfigParser[] parsers();
|
||||
|
||||
default String miniMessageTranslation(String key) {
|
||||
return miniMessageTranslation(key, null);
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.Plugin;
|
||||
import net.momirealms.craftengine.core.plugin.PluginProperties;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.IndexedArgumentTag;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
@@ -63,8 +63,8 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser[] parsers() {
|
||||
return new ConfigSectionParser[] {this.langParser, this.i18nParser};
|
||||
public ConfigParser[] parsers() {
|
||||
return new ConfigParser[] {this.langParser, this.i18nParser};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -277,7 +277,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class I18NParser implements ConfigSectionParser {
|
||||
public class I18NParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"i18n", "internationalization", "translation", "translations"};
|
||||
|
||||
@Override
|
||||
@@ -308,7 +308,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class LangParser implements ConfigSectionParser {
|
||||
public class LangParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"lang", "language", "languages"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.momirealms.craftengine.core.plugin.text.minimessage;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.ParsingException;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GlobalVariableTag implements TagResolver {
|
||||
private final Context context;
|
||||
|
||||
public GlobalVariableTag(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull net.kyori.adventure.text.minimessage.Context ctx) throws ParsingException {
|
||||
if (!this.has(name)) {
|
||||
return null;
|
||||
}
|
||||
String id = arguments.popOr("No argument variable id provided").toString();
|
||||
String value = CraftEngine.instance().globalVariableManager().get(id);
|
||||
if (value == null) {
|
||||
throw ctx.newException("Unknown variable: ", arguments);
|
||||
}
|
||||
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(value, this.context.tagResolvers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull String name) {
|
||||
return "global".equals(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package net.momirealms.craftengine.core.plugin.text.minimessage;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.Context;
|
||||
import net.kyori.adventure.text.minimessage.ParsingException;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RelationalPlaceholderTag implements TagResolver {
|
||||
private final Player player1;
|
||||
private final Player player2;
|
||||
|
||||
public RelationalPlaceholderTag(@NotNull Player player1, @NotNull Player player2) {
|
||||
this.player1 = player1;
|
||||
this.player2 = player2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull Context ctx) throws ParsingException {
|
||||
if (!this.has(name) || !CraftEngine.instance().compatibilityManager().hasPlaceholderAPI()) {
|
||||
return null;
|
||||
}
|
||||
String placeholder = "%" + arguments.popOr("No argument placeholder provided") + "%";
|
||||
String parsed = CraftEngine.instance().compatibilityManager().parse(player1, player2, placeholder);
|
||||
if (parsed.equals(placeholder)) {
|
||||
parsed = arguments.popOr("No default papi value provided").toString();
|
||||
}
|
||||
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(parsed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull String name) {
|
||||
return "rel_papi".equals(name);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
|
||||
@@ -32,8 +32,8 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigSectionParser[] parsers() {
|
||||
return new ConfigSectionParser[] { this.soundParser, this.songParser };
|
||||
public ConfigParser[] parsers() {
|
||||
return new ConfigParser[] { this.soundParser, this.songParser };
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,7 +59,7 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
|
||||
protected abstract void registerSongs(Map<Key, JukeboxSong> songs);
|
||||
|
||||
public class SongParser implements ConfigSectionParser {
|
||||
public class SongParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"jukebox_songs", "song", "songs", "jukebox", "jukebox_song"};
|
||||
|
||||
@Override
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
}
|
||||
}
|
||||
|
||||
public class SoundParser implements ConfigSectionParser {
|
||||
public class SoundParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"sounds", "sound"};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.momirealms.craftengine.core.sound;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -10,7 +10,7 @@ public interface SoundManager extends Manageable {
|
||||
|
||||
boolean isVanillaSoundEvent(Key key);
|
||||
|
||||
ConfigSectionParser[] parsers();
|
||||
ConfigParser[] parsers();
|
||||
|
||||
Map<Key, SoundEvent> sounds();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user