mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-03 14:22:25 +00:00
添加铭牌支持
This commit is contained in:
@@ -376,7 +376,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
// internal
|
||||
plugin.saveResource("resources/internal/pack.yml");
|
||||
plugin.saveResource("resources/internal/configuration/i18n.yml");
|
||||
plugin.saveResource("resources/internal/configuration/translations.yml");
|
||||
plugin.saveResource("resources/internal/configuration/fix_client_visual.yml");
|
||||
plugin.saveResource("resources/internal/configuration/offset_chars.yml");
|
||||
plugin.saveResource("resources/internal/configuration/gui.yml");
|
||||
@@ -413,7 +413,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
plugin.saveResource("resources/default/configuration/templates.yml");
|
||||
plugin.saveResource("resources/default/configuration/categories.yml");
|
||||
plugin.saveResource("resources/default/configuration/emoji.yml");
|
||||
plugin.saveResource("resources/default/configuration/i18n.yml");
|
||||
plugin.saveResource("resources/default/configuration/translations.yml");
|
||||
plugin.saveResource("resources/default/configuration/items/cap.yml");
|
||||
plugin.saveResource("resources/default/configuration/items/flame_elytra.yml");
|
||||
plugin.saveResource("resources/default/configuration/items/gui_head.yml");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import net.momirealms.craftengine.core.world.particle.ParticleType;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package net.momirealms.craftengine.core.plugin.compatibility;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.entity.furniture.ExternalModel;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -15,6 +17,8 @@ public interface CompatibilityManager {
|
||||
|
||||
void registerLevelerProvider(String plugin, LevelerProvider provider);
|
||||
|
||||
void registerTagResolverProvider(TagResolverProvider provider);
|
||||
|
||||
void addLevelerExp(Player player, String plugin, String target, double value);
|
||||
|
||||
int getLevel(Player player, String plugin, String target);
|
||||
@@ -36,4 +40,6 @@ public interface CompatibilityManager {
|
||||
int getPlayerProtocolVersion(UUID uuid);
|
||||
|
||||
void executeMMSkill(String skill, float power, Player player);
|
||||
|
||||
TagResolver[] createExternalTagResolvers(Context context);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.craftengine.core.plugin.compatibility;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
|
||||
public interface TagResolverProvider {
|
||||
|
||||
String name();
|
||||
|
||||
TagResolver getTagResolver(Context context);
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package net.momirealms.craftengine.core.plugin.context;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import net.momirealms.craftengine.core.util.ArrayUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -32,12 +35,27 @@ 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),
|
||||
new PlaceholderTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
this.tagResolvers = getTagResolver();
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected TagResolver[] getTagResolver() {
|
||||
return ArrayUtils.mergeNoCopy(getExternalTagResolvers(), getInternalTagResolvers());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected TagResolver[] getExternalTagResolvers() {
|
||||
return CraftEngine.instance().compatibilityManager().createExternalTagResolvers(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected TagResolver[] getInternalTagResolvers() {
|
||||
return new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new I18NTag(this), new NamedArgumentTag(this),
|
||||
new PlaceholderTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
|
||||
if (!this.additionalParameterProviders.isEmpty()) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
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.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -22,13 +20,4 @@ public final class NetworkTextReplaceContext extends PlayerOptionalContext imple
|
||||
public Player player() {
|
||||
return super.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagResolver[] tagResolvers() {
|
||||
if (this.tagResolvers == null) {
|
||||
this.tagResolvers = new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new PlaceholderTag(this), new I18NTag(this),
|
||||
new NamedArgumentTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
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.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -63,14 +61,4 @@ public class PlayerOptionalContext extends AbstractChainParameterContext impleme
|
||||
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), new I18NTag(this),
|
||||
new NamedArgumentTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
return this.tagResolvers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class LangData {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "I18NData{" + translations + "}";
|
||||
return "LangData{" + translations + "}";
|
||||
}
|
||||
|
||||
public static void merge(Map<String, LangData> target, Map<String, LangData> source) {
|
||||
|
||||
@@ -276,7 +276,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
}
|
||||
|
||||
public class TranslationParser extends IdSectionConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"translations", "translation", "l10n", "localization", "i18n", "internationalization", };
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"translations", "translation", "l10n", "localization", "i18n", "internationalization"};
|
||||
|
||||
@Override
|
||||
public int loadingSequence() {
|
||||
@@ -292,7 +292,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
public void parseSection(Pack pack, Path path, String node, net.momirealms.craftengine.core.util.Key id, Map<String, Object> section) {
|
||||
Locale locale = TranslationManager.parseLocale(id.value());
|
||||
if (locale == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.i18n.unknown_locale");
|
||||
throw new LocalizedResourceConfigException("warning.config.translation.unknown_locale");
|
||||
}
|
||||
|
||||
Map<String, String> bundle = new HashMap<>();
|
||||
|
||||
@@ -10,6 +10,8 @@ import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FormattedLine {
|
||||
TagResolver[] CUSTOM_RESOLVERS = new TagResolver[]{
|
||||
createDummyResolvers("expr"),
|
||||
@@ -22,6 +24,19 @@ public interface FormattedLine {
|
||||
createDummyResolvers("rel_papi")
|
||||
};
|
||||
|
||||
class Companion {
|
||||
public static TagResolver[] LATEST_RESOLVERS = CUSTOM_RESOLVERS;
|
||||
|
||||
public static void resetWithCustomResolvers(List<String> customResolvers) {
|
||||
TagResolver[] resolvers = new TagResolver[customResolvers.size() + CUSTOM_RESOLVERS.length];
|
||||
System.arraycopy(CUSTOM_RESOLVERS, 0, resolvers, 0, CUSTOM_RESOLVERS.length);
|
||||
for (int i = 0; i < customResolvers.size(); i++) {
|
||||
resolvers[CUSTOM_RESOLVERS.length + i] = createDummyResolvers(customResolvers.get(i));
|
||||
}
|
||||
LATEST_RESOLVERS = resolvers;
|
||||
}
|
||||
}
|
||||
|
||||
Component parse(net.momirealms.craftengine.core.plugin.context.Context context);
|
||||
|
||||
private static TagResolver createDummyResolvers(String tag) {
|
||||
@@ -39,7 +54,7 @@ public interface FormattedLine {
|
||||
}
|
||||
|
||||
static FormattedLine create(String line) {
|
||||
if (line.equals(AdventureHelper.customMiniMessage().stripTags(line, CUSTOM_RESOLVERS))) {
|
||||
if (line.equals(AdventureHelper.customMiniMessage().stripTags(line, Companion.LATEST_RESOLVERS))) {
|
||||
return new PreParsedLine(AdventureHelper.miniMessage().deserialize(line));
|
||||
} else {
|
||||
return new DynamicLine(line);
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.json.JSONOptions;
|
||||
import net.kyori.adventure.text.serializer.json.legacyimpl.NBTLegacyHoverEventSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.text.component.ComponentProvider;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
|
||||
@@ -42,6 +42,26 @@ public class ArrayUtils {
|
||||
return mergedArray;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T[] mergeNoCopy(T[] array1, T[] array2) {
|
||||
if (array1 == null && array2 == null) {
|
||||
return null;
|
||||
}
|
||||
if (array1 == null) {
|
||||
return array2;
|
||||
}
|
||||
if (array2 == null) {
|
||||
return array1;
|
||||
}
|
||||
T[] mergedArray = (T[]) Array.newInstance(
|
||||
array1.getClass().getComponentType(),
|
||||
array1.length + array2.length
|
||||
);
|
||||
System.arraycopy(array1, 0, mergedArray, 0, array1.length);
|
||||
System.arraycopy(array2, 0, mergedArray, array1.length, array2.length);
|
||||
return mergedArray;
|
||||
}
|
||||
|
||||
public static <T> List<T[]> splitArray(T[] array, int chunkSize) {
|
||||
List<T[]> result = new ArrayList<>();
|
||||
for (int i = 0; i < array.length; i += chunkSize) {
|
||||
|
||||
Reference in New Issue
Block a user