mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
Merge PR, resolving conflicts by using upstream changes
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -26,4 +26,5 @@ replay_pid*
|
||||
build/
|
||||
.gradle/
|
||||
.idea/
|
||||
!**/libs/*.jar
|
||||
|
||||
!/libs/*.jar
|
||||
@@ -39,7 +39,7 @@ dependencies {
|
||||
compileOnly("org.incendo:cloud-minecraft-extras:${rootProject.properties["cloud_minecraft_extras_version"]}")
|
||||
compileOnly("org.incendo:cloud-paper:${rootProject.properties["cloud_paper_version"]}")
|
||||
// YAML
|
||||
compileOnly("dev.dejvokep:boosted-yaml:${rootProject.properties["boosted_yaml_version"]}")
|
||||
compileOnly(files("${rootProject.rootDir}/libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar"))
|
||||
// Item Tag
|
||||
implementation("com.saicone.rtag:rtag:${rootProject.properties["rtag_version"]}")
|
||||
implementation("com.saicone.rtag:rtag-item:${rootProject.properties["rtag_version"]}")
|
||||
|
||||
@@ -21,6 +21,7 @@ import net.momirealms.craftengine.core.loot.LootTable;
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.pack.generator.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
@@ -529,7 +530,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
private void loadMappingsAndAdditionalBlocks() {
|
||||
this.plugin.logger().info("Loading mappings.yml.");
|
||||
File mappingFile = new File(plugin.dataFolderFile(), "mappings.yml");
|
||||
YamlDocument mappings = plugin.loadOrCreateYamlData("mappings.yml");
|
||||
YamlDocument mappings = ConfigManager.instance().loadOrCreateYamlData("mappings.yml");
|
||||
Map<String, String> blockStateMappings = loadBlockStateMappings(mappings);
|
||||
this.validateBlockStateMappings(mappingFile, blockStateMappings);
|
||||
Map<Integer, String> stateMap = new HashMap<>();
|
||||
@@ -542,7 +543,7 @@ public class BukkitBlockManager extends AbstractBlockManager {
|
||||
this.blockAppearanceMapper = ImmutableMap.copyOf(appearanceMapper);
|
||||
this.blockAppearanceArranger = ImmutableMap.copyOf(appearanceArranger);
|
||||
this.plugin.logger().info("Freed " + this.blockAppearanceMapper.size() + " block state appearances.");
|
||||
YamlDocument additionalYaml = plugin.loadOrCreateYamlData("additional-real-blocks.yml");
|
||||
YamlDocument additionalYaml = ConfigManager.instance().loadOrCreateYamlData("additional-real-blocks.yml");
|
||||
this.registeredRealBlockSlots = this.buildRegisteredRealBlockSlots(blockTypeCounter, additionalYaml);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.block.behavior.BukkitBlockBehaviors;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
@@ -43,7 +38,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -295,51 +289,6 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlDocument loadYamlConfig(String filePath, GeneralSettings generalSettings, LoaderSettings loaderSettings, DumperSettings dumperSettings, UpdaterSettings updaterSettings) {
|
||||
try (InputStream inputStream = new FileInputStream(resolveConfig(filePath).toFile())) {
|
||||
return YamlDocument.create(inputStream, resourceStream(filePath), generalSettings, loaderSettings, dumperSettings, updaterSettings);
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to load config " + filePath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlDocument loadYamlData(File file) {
|
||||
try (InputStream inputStream = new FileInputStream(file)) {
|
||||
return YamlDocument.create(inputStream);
|
||||
} catch (IOException e) {
|
||||
logger.severe("Failed to load config " + file, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolveConfig(String filePath) {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
}
|
||||
filePath = filePath.replace('\\', '/');
|
||||
Path configFile = dataFolderPath().resolve(filePath);
|
||||
// if the config doesn't exist, create it based on the template in the resources dir
|
||||
if (!Files.exists(configFile)) {
|
||||
try {
|
||||
Files.createDirectories(configFile.getParent());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
try (InputStream is = resourceStream(filePath)) {
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("The embedded resource '" + filePath + "' cannot be found");
|
||||
}
|
||||
Files.copy(is, configFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public BukkitServerPlayer adapt(org.bukkit.entity.Player player) {
|
||||
if (player == null) return null;
|
||||
return Optional.ofNullable((BukkitServerPlayer) networkManager().getOnlineUser(player)).orElseGet(
|
||||
|
||||
@@ -13,7 +13,7 @@ dependencies {
|
||||
// JOML
|
||||
compileOnly("org.joml:joml:1.10.8")
|
||||
// YAML
|
||||
implementation(files("libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar"))
|
||||
compileOnly(files("${rootProject.rootDir}/libs/boosted-yaml-${rootProject.properties["boosted_yaml_version"]}.jar"))
|
||||
compileOnly("org.yaml:snakeyaml:${rootProject.properties["snake_yaml_version"]}")
|
||||
// NBT
|
||||
implementation("com.github.Xiao-MoMi:sparrow-nbt:${rootProject.properties["sparrow_nbt_version"]}")
|
||||
|
||||
@@ -4,8 +4,8 @@ import net.momirealms.craftengine.core.pack.generator.AbstractModelGenerator;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
public abstract class AbstractBlockManager extends AbstractModelGenerator implements BlockManager {
|
||||
|
||||
public AbstractBlockManager(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,12 @@ import net.momirealms.craftengine.core.loot.LootContext;
|
||||
import net.momirealms.craftengine.core.loot.condition.LootCondition;
|
||||
import net.momirealms.craftengine.core.loot.condition.LootConditions;
|
||||
import net.momirealms.craftengine.core.loot.parameter.LootParameters;
|
||||
import net.momirealms.craftengine.core.loot.provider.FixedNumberProvider;
|
||||
import net.momirealms.craftengine.core.loot.provider.NumberProviderFactory;
|
||||
import net.momirealms.craftengine.core.loot.provider.UniformNumberProvider;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.RandomUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class PackManagerImpl implements PackManager {
|
||||
String version = null;
|
||||
String author = null;
|
||||
if (Files.exists(metaFile) && Files.isRegularFile(metaFile)) {
|
||||
YamlDocument metaYML = plugin.loadYamlData(metaFile.toFile());
|
||||
YamlDocument metaYML = ConfigManager.instance().loadYamlData(metaFile.toFile());
|
||||
namespace = metaYML.getString("namespace", namespace);
|
||||
description = metaYML.getString("description");
|
||||
version = metaYML.getString("version");
|
||||
@@ -353,7 +353,7 @@ public class PackManagerImpl implements PackManager {
|
||||
private void generateBlockOverrides(Path generatedPackPath) {
|
||||
File blockStatesFile = new File(plugin.dataFolderFile(), "blockstates.yml");
|
||||
if (!blockStatesFile.exists()) plugin.saveResource("blockstates.yml");
|
||||
YamlDocument preset = plugin.loadYamlData(blockStatesFile);
|
||||
YamlDocument preset = ConfigManager.instance().loadYamlData(blockStatesFile);
|
||||
for (Map.Entry<Key, Map<String, JsonElement>> entry : plugin.blockManager().blockOverrides().entrySet()) {
|
||||
Key key = entry.getKey();
|
||||
Path overridedBlockPath = generatedPackPath
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import net.momirealms.craftengine.core.block.BlockManager;
|
||||
import net.momirealms.craftengine.core.entity.furniture.FurnitureManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
@@ -28,7 +27,6 @@ import net.momirealms.craftengine.core.plugin.scheduler.SchedulerAdapter;
|
||||
import net.momirealms.craftengine.core.world.WorldManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -66,6 +64,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
dependenciesToLoad.addAll(platformDependencies());
|
||||
this.dependencyManager.loadDependencies(dependenciesToLoad);
|
||||
this.translationManager = new TranslationManagerImpl(this);
|
||||
this.configManager = new ConfigManager(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,7 +90,6 @@ public abstract class CraftEngine implements Plugin {
|
||||
@Override
|
||||
public void enable() {
|
||||
this.networkManager.enable();
|
||||
this.configManager = new ConfigManager(this);
|
||||
this.packManager = new PackManagerImpl(this);
|
||||
this.fontManager = new FontManagerImpl(this);
|
||||
this.templateManager = new TemplateManagerImpl(this);
|
||||
@@ -127,7 +125,6 @@ public abstract class CraftEngine implements Plugin {
|
||||
|
||||
protected List<Dependency> commonDependencies() {
|
||||
return List.of(
|
||||
// Dependencies.BOOSTED_YAML,
|
||||
Dependencies.BSTATS_BASE,
|
||||
Dependencies.CAFFEINE,
|
||||
Dependencies.GEANTY_REF,
|
||||
@@ -137,7 +134,8 @@ public abstract class CraftEngine implements Plugin {
|
||||
Dependencies.COMMONS_IO,
|
||||
Dependencies.ZSTD,
|
||||
Dependencies.BYTE_BUDDY,
|
||||
Dependencies.SNAKE_YAML
|
||||
Dependencies.SNAKE_YAML,
|
||||
Dependencies.BOOSTED_YAML
|
||||
);
|
||||
}
|
||||
|
||||
@@ -217,12 +215,4 @@ public abstract class CraftEngine implements Plugin {
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public YamlDocument loadOrCreateYamlData(String fileName) {
|
||||
File file = new File(this.dataFolderFile(), fileName);
|
||||
if (!file.exists()) {
|
||||
this.saveResource(fileName);
|
||||
}
|
||||
return this.loadYamlData(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package net.momirealms.craftengine.core.plugin;
|
||||
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import net.momirealms.craftengine.core.block.BlockManager;
|
||||
import net.momirealms.craftengine.core.entity.furniture.FurnitureManager;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
@@ -42,10 +37,6 @@ public interface Plugin extends Reloadable {
|
||||
|
||||
void saveResource(String filePath);
|
||||
|
||||
YamlDocument loadYamlConfig(String filePath, GeneralSettings generalSettings, LoaderSettings loaderSettings, DumperSettings dumperSettings, UpdaterSettings updaterSettings);
|
||||
|
||||
YamlDocument loadYamlData(File file);
|
||||
|
||||
String pluginVersion();
|
||||
|
||||
String serverVersion();
|
||||
@@ -71,6 +62,4 @@ public interface Plugin extends Reloadable {
|
||||
boolean isPluginEnabled(String plugin);
|
||||
|
||||
String parse(Player player, String text);
|
||||
|
||||
Path resolveConfig(String filePath);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.momirealms.craftengine.core.plugin.Plugin;
|
||||
import net.momirealms.craftengine.core.plugin.command.sender.Sender;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.plugin.locale.CraftEngineCaptionFormatter;
|
||||
import net.momirealms.craftengine.core.plugin.locale.CraftEngineCaptionProvider;
|
||||
import net.momirealms.craftengine.core.util.ArrayUtils;
|
||||
@@ -125,7 +126,7 @@ public abstract class AbstractCommandManager<C> implements CraftEngineCommandMan
|
||||
|
||||
@Override
|
||||
public void registerDefaultFeatures() {
|
||||
YamlDocument document = plugin.loadYamlConfig(commandsFile,
|
||||
YamlDocument document = ConfigManager.instance().loadYamlConfig(commandsFile,
|
||||
GeneralSettings.DEFAULT,
|
||||
LoaderSettings
|
||||
.builder()
|
||||
|
||||
@@ -15,8 +15,14 @@ import net.momirealms.craftengine.core.plugin.Reloadable;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -33,6 +39,10 @@ public class ConfigManager implements Reloadable {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static ConfigManager instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected boolean debug;
|
||||
protected boolean checkUpdate;
|
||||
protected boolean metrics;
|
||||
@@ -57,7 +67,7 @@ public class ConfigManager implements Reloadable {
|
||||
@Override
|
||||
public void load() {
|
||||
configVersion = PluginProperties.getValue("config");
|
||||
config = plugin.loadYamlConfig(
|
||||
config = this.loadYamlConfig(
|
||||
"config.yml",
|
||||
GeneralSettings.builder()
|
||||
.setRouteSeparator('.')
|
||||
@@ -201,4 +211,54 @@ public class ConfigManager implements Reloadable {
|
||||
public static boolean enableRecipeSystem() {
|
||||
return instance.enableRecipeSystem;
|
||||
}
|
||||
|
||||
public YamlDocument loadOrCreateYamlData(String fileName) {
|
||||
File file = new File(this.plugin.dataFolderFile(), fileName);
|
||||
if (!file.exists()) {
|
||||
this.plugin.saveResource(fileName);
|
||||
}
|
||||
return this.loadYamlData(file);
|
||||
}
|
||||
|
||||
public YamlDocument loadYamlConfig(String filePath, GeneralSettings generalSettings, LoaderSettings loaderSettings, DumperSettings dumperSettings, UpdaterSettings updaterSettings) {
|
||||
try (InputStream inputStream = new FileInputStream(resolveConfig(filePath).toFile())) {
|
||||
return YamlDocument.create(inputStream, this.plugin.resourceStream(filePath), generalSettings, loaderSettings, dumperSettings, updaterSettings);
|
||||
} catch (IOException e) {
|
||||
this.plugin.logger().severe("Failed to load config " + filePath, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public YamlDocument loadYamlData(File file) {
|
||||
try (InputStream inputStream = new FileInputStream(file)) {
|
||||
return YamlDocument.create(inputStream);
|
||||
} catch (IOException e) {
|
||||
this.plugin.logger().severe("Failed to load config " + file, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Path resolveConfig(String filePath) {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
}
|
||||
filePath = filePath.replace('\\', '/');
|
||||
Path configFile = this.plugin.dataFolderPath().resolve(filePath);
|
||||
// if the config doesn't exist, create it based on the template in the resources dir
|
||||
if (!Files.exists(configFile)) {
|
||||
try {
|
||||
Files.createDirectories(configFile.getParent());
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
try (InputStream is = this.plugin.resourceStream(filePath)) {
|
||||
if (is == null) {
|
||||
throw new IllegalArgumentException("The embedded resource '" + filePath + "' cannot be found");
|
||||
}
|
||||
Files.copy(is, configFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return configFile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.plugin.Plugin;
|
||||
import net.momirealms.craftengine.core.plugin.PluginProperties;
|
||||
import net.momirealms.craftengine.core.plugin.config.ConfigManager;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -149,7 +150,7 @@ public class TranslationManagerImpl implements TranslationManager {
|
||||
}
|
||||
|
||||
Map<String, String> bundle = new HashMap<>();
|
||||
YamlDocument document = plugin.loadYamlConfig("translations" + File.separator + translationFile.getFileName(),
|
||||
YamlDocument document = ConfigManager.instance().loadYamlConfig("translations" + File.separator + translationFile.getFileName(),
|
||||
GeneralSettings.DEFAULT,
|
||||
LoaderSettings
|
||||
.builder()
|
||||
|
||||
@@ -40,7 +40,7 @@ zstd_version=1.5.6-9
|
||||
commons_io_version=2.17.0
|
||||
sparrow_nbt_version=0.3
|
||||
fastutil_version=8.5.15
|
||||
netty_version=4.1.115
|
||||
netty_version=4.1.117
|
||||
joml_version=1.10.8
|
||||
datafixerupper_version=1.0.20
|
||||
mojang_brigadier_version=1.0.18
|
||||
|
||||
BIN
libs/boosted-yaml-1.3.7.jar
Normal file
BIN
libs/boosted-yaml-1.3.7.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user