mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-23 17:09:19 +00:00
add alias for section name
This commit is contained in:
@@ -14,9 +14,9 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface BlockManager extends Reloadable, ModelGenerator, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "blocks";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"blocks", "block"};
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface FurnitureManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "furniture";
|
||||
String[] CONFIG_SECTION_NAME = new String[] { "furniture" };
|
||||
String FURNITURE_ADMIN_NODE = "craftengine.furniture.admin";
|
||||
|
||||
void delayedLoad();
|
||||
@@ -22,7 +22,7 @@ public interface FurnitureManager extends Reloadable, ConfigSectionParser {
|
||||
void delayedInit();
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface ImageManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "images";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"images", "image"};
|
||||
Key DEFAULT_FONT = Key.of("minecraft:default");
|
||||
String BYPASS_BOOK = "craftengine.filter.bypass.book";
|
||||
String BYPASS_SIGN = "craftengine.filter.bypass.sign";
|
||||
@@ -20,12 +20,18 @@ public interface ImageManager extends Reloadable, ConfigSectionParser {
|
||||
String BYPASS_COMMAND = "craftengine.filter.bypass.command";
|
||||
String BYPASS_ANVIL = "craftengine.filter.bypass.anvil";
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
void delayedLoad();
|
||||
|
||||
void delayedInit();
|
||||
|
||||
default int loadingSequence() {
|
||||
return LoadingSequence.FONT;
|
||||
}
|
||||
|
||||
boolean isDefaultFontInUse();
|
||||
|
||||
boolean isIllegalCharacter(int codepoint);
|
||||
@@ -69,10 +75,4 @@ public interface ImageManager extends Reloadable, ConfigSectionParser {
|
||||
default String createRawOffsets(int offset) {
|
||||
return createOffsets(offset, (raw, font) -> raw);
|
||||
}
|
||||
|
||||
default int loadingSequence() {
|
||||
return LoadingSequence.FONT;
|
||||
}
|
||||
|
||||
void delayedInit();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.craftengine.core.font.emoji;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
public abstract class AbstractEmojiManager implements EmojiManager {
|
||||
protected CraftEngine plugin;
|
||||
|
||||
public AbstractEmojiManager(CraftEngine plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.momirealms.craftengine.core.font.emoji;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.LoadingSequence;
|
||||
import net.momirealms.craftengine.core.plugin.Reloadable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
|
||||
public interface EmojiManager extends Reloadable, ConfigSectionParser {
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"emoji", "emojis"};
|
||||
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
default int loadingSequence() {
|
||||
return LoadingSequence.EMOJI;
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,9 @@ import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public interface ItemManager<T> extends Reloadable, ModelGenerator, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "items";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface RecipeManager<T> extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "recipes";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"recipes", "recipe"};
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface VanillaLootManager extends ConfigSectionParser, Reloadable {
|
||||
String CONFIG_SECTION_NAME = "vanilla-loots";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"vanilla-loots", "vanilla-loot", "loots", "loot"};
|
||||
|
||||
@Override
|
||||
default int loadingSequence() {
|
||||
@@ -15,7 +15,7 @@ public interface VanillaLootManager extends ConfigSectionParser, Reloadable {
|
||||
}
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +192,12 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
|
||||
@Override
|
||||
public boolean registerConfigSectionParser(ConfigSectionParser parser) {
|
||||
if (this.sectionParsers.containsKey(parser.sectionId())) return false;
|
||||
this.sectionParsers.put(parser.sectionId(), parser);
|
||||
for (String id : parser.sectionId()) {
|
||||
if (this.sectionParsers.containsKey(id)) return false;
|
||||
}
|
||||
for (String id : parser.sectionId()) {
|
||||
this.sectionParsers.put(id, parser);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -404,7 +408,7 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
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();
|
||||
boolean isTemplate = parser.sectionId().equals(TemplateManager.CONFIG_SECTION_NAME);
|
||||
boolean isTemplate = parser.sectionId()[0].equals(TemplateManager.CONFIG_SECTION_NAME[0]);
|
||||
long t1 = System.nanoTime();
|
||||
for (CachedConfig cached : entry.getValue()) {
|
||||
for (Map.Entry<String, Object> configEntry : cached.config().entrySet()) {
|
||||
@@ -420,16 +424,16 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
parser.parseSection(cached.pack(), cached.filePath(), id, plugin.templateManager().applyTemplates(configSection1));
|
||||
}
|
||||
} else {
|
||||
this.plugin.logger().warn(cached.filePath(), "Configuration section is required for " + parser.sectionId() + "." + configEntry.getKey() + " - ");
|
||||
this.plugin.logger().warn(cached.filePath(), "Configuration section is required for " + parser.sectionId()[0] + "." + configEntry.getKey() + " - ");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn(cached.filePath(), "Error loading " + parser.sectionId() + "." + key, e);
|
||||
this.plugin.logger().warn(cached.filePath(), "Error loading " + parser.sectionId()[0] + "." + key, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
long t2 = System.nanoTime();
|
||||
this.plugin.logger().info("Loaded " + parser.sectionId() + " in " + String.format("%.2f", ((t2 - t1) / 1_000_000.0)) + " ms");
|
||||
this.plugin.logger().info("Loaded " + parser.sectionId()[0] + " in " + String.format("%.2f", ((t2 - t1) / 1_000_000.0)) + " ms");
|
||||
}
|
||||
this.cachedConfigs.clear();
|
||||
}
|
||||
|
||||
@@ -13,4 +13,5 @@ public class LoadingSequence {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ public interface PackManager extends Reloadable {
|
||||
|
||||
boolean unregisterConfigSectionParser(String id);
|
||||
|
||||
default boolean unregisterConfigSectionParser(ConfigSectionParser parser) {
|
||||
return this.unregisterConfigSectionParser(parser.sectionId());
|
||||
default void unregisterConfigSectionParser(ConfigSectionParser parser) {
|
||||
for (String id : parser.sectionId()) {
|
||||
unregisterConfigSectionParser(id);
|
||||
}
|
||||
}
|
||||
|
||||
void delayedInit();
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class AbstractCommandManager<C> implements CraftEngineCommandMan
|
||||
injectExceptionHandler(CommandExecutionException.class, MinecraftExceptionHandler.createDefaultCommandExecutionHandler(), StandardCaptionKeys.EXCEPTION_UNEXPECTED);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private void injectExceptionHandler(Class<? extends Throwable> type, MinecraftExceptionHandler.MessageFactory<C, ?> factory, Caption key) {
|
||||
getCommandManager().exceptionController().registerHandler(type, ctx -> {
|
||||
final @Nullable ComponentLike message = factory.message(captionFormatter, (ExceptionContext) ctx);
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.incendo.cloud.parser.ArgumentParseResult;
|
||||
import org.incendo.cloud.parser.ArgumentParser;
|
||||
import org.incendo.cloud.parser.ParserDescriptor;
|
||||
import org.incendo.cloud.suggestion.BlockingSuggestionProvider;
|
||||
import org.incendo.cloud.suggestion.Suggestion;
|
||||
|
||||
public class BlockStateParser<C> implements ArgumentParser<C, ImmutableBlockState>, BlockingSuggestionProvider.Strings<C> {
|
||||
|
||||
@@ -36,9 +37,7 @@ public class BlockStateParser<C> implements ArgumentParser<C, ImmutableBlockStat
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<@NonNull String> stringSuggestions(@NonNull CommandContext<C> commandContext, @NonNull CommandInput input) {
|
||||
return CraftEngine.instance().blockManager().cachedSuggestions().stream().map(it -> {
|
||||
return it.suggestion();
|
||||
}).toList();
|
||||
return CraftEngine.instance().blockManager().cachedSuggestions().stream().map(Suggestion::suggestion).toList();
|
||||
}
|
||||
|
||||
public static final class BlockStateParseException extends ParserException {
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
|
||||
public interface ConfigSectionParser extends Comparable<ConfigSectionParser> {
|
||||
|
||||
String sectionId();
|
||||
String[] sectionId();
|
||||
|
||||
void parseSection(Pack pack, Path path, Key id, Map<String, Object> section);
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public interface TemplateManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "templates";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"templates", "template"};
|
||||
Pattern PATTERN = Pattern.compile("\\{[^{}]+}");
|
||||
String TEMPLATE = "template";
|
||||
String OVERRIDES = "overrides";
|
||||
String ARGUMENTS = "arguments";
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ import java.util.TreeSet;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public interface ItemBrowserManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "categories";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"categories", "category"};
|
||||
int MAX_RECIPE_DEPTH = 16;
|
||||
String GET_ITEM_PERMISSION = "craftengine.browser.get_item";
|
||||
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface ClientLangManager extends Reloadable, ConfigSectionParser {
|
||||
Collectors.mapping(split -> split[1], Collectors.toUnmodifiableList())
|
||||
));
|
||||
|
||||
String CONFIG_SECTION_NAME = "lang";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"lang", "language", "languages"};
|
||||
|
||||
Map<String, I18NData> langData();
|
||||
|
||||
@@ -48,7 +48,7 @@ public interface ClientLangManager extends Reloadable, ConfigSectionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
public interface TranslationManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "i18n";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"i18n", "internationalization", "translation", "translations"};
|
||||
|
||||
static TranslationManager instance() {
|
||||
return TranslationManagerImpl.instance;
|
||||
@@ -44,7 +44,7 @@ public interface TranslationManager extends Reloadable, ConfigSectionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SoundManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "sounds";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"sounds", "sound"};
|
||||
|
||||
void delayedLoad();
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface SoundManager extends Reloadable, ConfigSectionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.plugin.Reloadable;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
|
||||
|
||||
public interface JukeboxSongManager extends Reloadable, ConfigSectionParser {
|
||||
String CONFIG_SECTION_NAME = "jukebox_songs";
|
||||
String[] CONFIG_SECTION_NAME = new String[] {"jukebox_songs", "song", "songs", "jukebox", "jukebox_song"};
|
||||
|
||||
@Override
|
||||
default int loadingSequence() {
|
||||
@@ -13,7 +13,7 @@ public interface JukeboxSongManager extends Reloadable, ConfigSectionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
default String sectionId() {
|
||||
default String[] sectionId() {
|
||||
return CONFIG_SECTION_NAME;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user