mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
update configuration to version 4
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 11 Jan 2025 22:24:44 +0300
|
||||
Subject: [PATCH] Rebrand
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/ServerBuildInfo.java b/src/main/java/io/papermc/paper/ServerBuildInfo.java
|
||||
index fb1fe2651e53a9bf46b3632c638e13eea9dcda93..ca79775114b574c9b7e4af113e79ab4f0a6a0928 100644
|
||||
--- a/src/main/java/io/papermc/paper/ServerBuildInfo.java
|
||||
+++ b/src/main/java/io/papermc/paper/ServerBuildInfo.java
|
||||
@@ -25,6 +25,14 @@ public interface ServerBuildInfo {
|
||||
*/
|
||||
Key BRAND_PURPUR_ID = Key.key("purpurmc", "purpur");
|
||||
// Purpur end
|
||||
+
|
||||
+ // DivineMC start
|
||||
+ /**
|
||||
+ * The brand id for DivineMC.
|
||||
+ */
|
||||
+ Key BRAND_DIVINEMC_ID = Key.key("divinemc", "divinemc");
|
||||
+ // DivineMC end
|
||||
+
|
||||
/**
|
||||
* Gets the {@code ServerBuildInfo}.
|
||||
*
|
||||
@@ -1,24 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 11 Jan 2025 22:53:30 +0300
|
||||
Subject: [PATCH] DivineMC Configuration
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
||||
index 5c34da114f6bc4446a187fbfbf113a5455b84078..d7f7ae223418004b39715670976f6db050671cee 100644
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -2295,6 +2295,13 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
||||
}
|
||||
// Purpur end
|
||||
|
||||
+ // DivineMC start
|
||||
+ @NotNull
|
||||
+ public org.bukkit.configuration.file.YamlConfiguration getDivineConfig() {
|
||||
+ throw new UnsupportedOperationException("Not supported yet");
|
||||
+ }
|
||||
+ // DivineMC end
|
||||
+
|
||||
/**
|
||||
* Sends the component to the player
|
||||
*
|
||||
@@ -0,0 +1,17 @@
|
||||
--- a/src/main/java/io/papermc/paper/ServerBuildInfo.java
|
||||
+++ b/src/main/java/io/papermc/paper/ServerBuildInfo.java
|
||||
@@ -25,6 +_,14 @@
|
||||
*/
|
||||
Key BRAND_PURPUR_ID = Key.key("purpurmc", "purpur");
|
||||
// Purpur end
|
||||
+
|
||||
+ // DivineMC start
|
||||
+ /**
|
||||
+ * The brand id for DivineMC.
|
||||
+ */
|
||||
+ Key BRAND_DIVINEMC_ID = Key.key("divinemc", "divinemc");
|
||||
+ // DivineMC end
|
||||
+
|
||||
/**
|
||||
* Gets the {@code ServerBuildInfo}.
|
||||
*
|
||||
@@ -0,0 +1,16 @@
|
||||
--- a/src/main/java/org/bukkit/Server.java
|
||||
+++ b/src/main/java/org/bukkit/Server.java
|
||||
@@ -2295,6 +_,13 @@
|
||||
}
|
||||
// Purpur end
|
||||
|
||||
+ // DivineMC start
|
||||
+ @NotNull
|
||||
+ public org.bukkit.configuration.file.YamlConfiguration getDivineConfig() {
|
||||
+ throw new UnsupportedOperationException("Not supported yet");
|
||||
+ }
|
||||
+ // DivineMC end
|
||||
+
|
||||
/**
|
||||
* Sends the component to the player
|
||||
*
|
||||
@@ -0,0 +1,19 @@
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -33,16 +_,6 @@
|
||||
protected String usageMessage;
|
||||
private String permission;
|
||||
private net.kyori.adventure.text.Component permissionMessage; // Paper
|
||||
- /**
|
||||
- * @deprecated Timings will be removed in the future
|
||||
- */
|
||||
- @Deprecated(forRemoval = true)
|
||||
- public co.aikar.timings.Timing timings; // Paper
|
||||
- /**
|
||||
- * @deprecated Timings will be removed in the future
|
||||
- */
|
||||
- @Deprecated(forRemoval = true)
|
||||
- @NotNull public String getTimingName() {return getName();} // Paper
|
||||
|
||||
protected Command(@NotNull String name) {
|
||||
this(name, "", "/" + name, new ArrayList<String>());
|
||||
@@ -0,0 +1,21 @@
|
||||
--- a/src/main/java/org/bukkit/command/FormattedCommandAlias.java
|
||||
+++ b/src/main/java/org/bukkit/command/FormattedCommandAlias.java
|
||||
@@ -12,7 +_,6 @@
|
||||
|
||||
public FormattedCommandAlias(@NotNull String alias, @NotNull String[] formatStrings) {
|
||||
super(alias);
|
||||
- timings = co.aikar.timings.TimingsManager.getCommandTiming("minecraft", this); // Spigot
|
||||
this.formatStrings = formatStrings;
|
||||
}
|
||||
|
||||
@@ -119,10 +_,6 @@
|
||||
|
||||
return formatString.trim(); // Paper - Causes an extra space at the end, breaks with brig commands
|
||||
}
|
||||
-
|
||||
- @NotNull
|
||||
- @Override // Paper
|
||||
- public String getTimingName() {return "Command Forwarder - " + super.getTimingName();} // Paper
|
||||
|
||||
private static boolean inRange(int i, int j, int k) {
|
||||
return i >= j && i <= k;
|
||||
@@ -0,0 +1,36 @@
|
||||
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
|
||||
@@ -39,7 +_,6 @@
|
||||
register("bukkit", new VersionCommand("version"));
|
||||
register("bukkit", new ReloadCommand("reload"));
|
||||
//register("bukkit", new PluginsCommand("plugins")); // Paper
|
||||
- register("bukkit", new co.aikar.timings.TimingsCommand("timings")); // Paper
|
||||
}
|
||||
|
||||
public void setFallbackCommands() {
|
||||
@@ -71,7 +_,6 @@
|
||||
*/
|
||||
@Override
|
||||
public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) {
|
||||
- command.timings = co.aikar.timings.TimingsManager.getCommandTiming(fallbackPrefix, command); // Paper
|
||||
label = label.toLowerCase(Locale.ROOT).trim();
|
||||
fallbackPrefix = fallbackPrefix.toLowerCase(Locale.ROOT).trim();
|
||||
boolean registered = register(label, command, false, fallbackPrefix);
|
||||
@@ -166,17 +_,9 @@
|
||||
parsedArgs = event.getArgs();
|
||||
// Purpur end - ExecuteCommandEvent
|
||||
|
||||
- // Paper start - Plugins do weird things to workaround normal registration
|
||||
- if (target.timings == null) {
|
||||
- target.timings = co.aikar.timings.TimingsManager.getCommandTiming(null, target);
|
||||
- }
|
||||
- // Paper end
|
||||
-
|
||||
try {
|
||||
- try (co.aikar.timings.Timing ignored = target.timings.startTiming()) { // Paper - use try with resources
|
||||
// Note: we don't return the result of target.execute as thats success / failure, we return handled (true) or not handled (false)
|
||||
target.execute(sender, sentCommandLabel, parsedArgs); // Purpur - ExecuteCommandEvent
|
||||
- } // target.timings.stopTiming(); // Spigot // Paper
|
||||
} catch (CommandException ex) {
|
||||
server.getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerCommandException(ex, target, sender, args))); // Paper
|
||||
//target.timings.stopTiming(); // Spigot // Paper
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
||||
@@ -720,12 +_,7 @@
|
||||
throw new IllegalPluginAccessException("Plugin attempted to register " + event + " while not enabled");
|
||||
}
|
||||
|
||||
- executor = new co.aikar.timings.TimedEventExecutor(executor, plugin, null, event); // Paper
|
||||
- if (false) { // Spigot - RL handles useTimings check now // Paper
|
||||
- getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
|
||||
- } else {
|
||||
- getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
|
||||
- }
|
||||
+ getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -955,8 +_,7 @@
|
||||
|
||||
@Override
|
||||
public boolean useTimings() {
|
||||
- if (true) {return this.paperPluginManager.useTimings();} // Paper
|
||||
- return co.aikar.timings.Timings.isTimingsEnabled(); // Spigot
|
||||
+ return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -966,7 +_,7 @@
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public void useTimings(boolean use) {
|
||||
- co.aikar.timings.Timings.setTimingsEnabled(use); // Paper
|
||||
+ // DivineMC - Delete timings
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@@ -0,0 +1,28 @@
|
||||
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
||||
@@ -43,7 +_,6 @@
|
||||
import org.bukkit.plugin.UnknownDependencyException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
-import org.spigotmc.CustomTimingsHandler; // Spigot
|
||||
import org.yaml.snakeyaml.error.YAMLException;
|
||||
|
||||
/**
|
||||
@@ -293,7 +_,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- EventExecutor executor = new co.aikar.timings.TimedEventExecutor(new EventExecutor() { // Paper
|
||||
+ EventExecutor executor = new EventExecutor() { // Paper
|
||||
@Override
|
||||
public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper
|
||||
try {
|
||||
@@ -307,7 +_,7 @@
|
||||
throw new EventException(t);
|
||||
}
|
||||
}
|
||||
- }, plugin, method, eventClass); // Paper
|
||||
+ }; // DivineMC - Delete Timings
|
||||
if (false) { // Spigot - RL handles useTimings check now
|
||||
eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled()));
|
||||
} else {
|
||||
@@ -1,48 +1,138 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 11 Jan 2025 22:49:50 +0300
|
||||
Date: Sun, 12 Jan 2025 16:19:14 +0300
|
||||
Subject: [PATCH] DivineMC Configuration
|
||||
|
||||
|
||||
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
||||
index 90cdcb8934e28dcc51272c9b40a6d89ac5dec75e..884f86f3a8f8bcc5242a9c9f44cc09506312b8c0 100644
|
||||
--- a/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/net/minecraft/server/MinecraftServer.java
|
||||
@@ -300,6 +300,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
public volatile boolean abnormalExit; // Paper - Improved watchdog support
|
||||
public volatile Thread shutdownThread; // Paper - Improved watchdog support
|
||||
public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
|
||||
+ public final space.bxteam.divinemc.configuration.DivineConfigurations divineConfigurations; // DivineMC - add divine configuration files
|
||||
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
|
||||
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
|
||||
public boolean lagging = false; // Purpur - Lagging threshold
|
||||
@@ -472,6 +473,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
Runtime.getRuntime().addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));
|
||||
// CraftBukkit end
|
||||
this.paperConfigurations = services.paperConfigurations(); // Paper - add paper configuration files
|
||||
+ this.divineConfigurations = services.divineConfigurations(); // DivineMC - add divinemc configuration files
|
||||
}
|
||||
|
||||
private void readScoreboard(DimensionDataStorage dataStorage) {
|
||||
diff --git a/net/minecraft/server/Services.java b/net/minecraft/server/Services.java
|
||||
index ee760cc9d6756c40f13fe6459725dcfc200b9630..f407553fa89e85412193f617d01f2e365b47064e 100644
|
||||
--- a/net/minecraft/server/Services.java
|
||||
+++ b/net/minecraft/server/Services.java
|
||||
@@ -11,13 +11,18 @@ import net.minecraft.server.players.GameProfileCache;
|
||||
import net.minecraft.util.SignatureValidator;
|
||||
|
||||
public record Services(
|
||||
- MinecraftSessionService sessionService, ServicesKeySet servicesKeySet, GameProfileRepository profileRepository, GameProfileCache profileCache, @javax.annotation.Nullable io.papermc.paper.configuration.PaperConfigurations paperConfigurations // Paper - add paper configuration files
|
||||
+ MinecraftSessionService sessionService,
|
||||
+ ServicesKeySet servicesKeySet,
|
||||
+ GameProfileRepository profileRepository,
|
||||
+ GameProfileCache profileCache,
|
||||
+ @javax.annotation.Nullable io.papermc.paper.configuration.PaperConfigurations paperConfigurations, // Paper - add paper configuration files
|
||||
+ @javax.annotation.Nullable space.bxteam.divinemc.configuration.DivineConfigurations divineConfigurations // DivineMC - Add configuration files for DivineMC
|
||||
) {
|
||||
public static final String USERID_CACHE_FILE = "usercache.json"; // Paper - private -> public
|
||||
|
||||
// Paper start - add paper configuration files
|
||||
public Services(MinecraftSessionService sessionService, ServicesKeySet servicesKeySet, GameProfileRepository profileRepository, GameProfileCache profileCache) {
|
||||
- this(sessionService, servicesKeySet, profileRepository, profileCache, null);
|
||||
+ this(sessionService, servicesKeySet, profileRepository, profileCache, null, null); // DivineMC - add null for divineConfigurations
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,6 +31,13 @@ public record Services(
|
||||
}
|
||||
// Paper end - add paper configuration files
|
||||
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ @Override
|
||||
+ public space.bxteam.divinemc.configuration.DivineConfigurations divineConfigurations() {
|
||||
+ return java.util.Objects.requireNonNull(this.divineConfigurations);
|
||||
+ }
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
+
|
||||
public static Services create(YggdrasilAuthenticationService authenticationService, File profileRepository, File userCacheFile, joptsimple.OptionSet optionSet) throws Exception { // Paper - add optionset to load paper config files; add userCacheFile parameter
|
||||
MinecraftSessionService minecraftSessionService = authenticationService.createMinecraftSessionService();
|
||||
GameProfileRepository gameProfileRepository = authenticationService.createProfileRepository();
|
||||
@@ -34,7 +46,8 @@ public record Services(
|
||||
final java.nio.file.Path legacyConfigPath = ((File) optionSet.valueOf("paper-settings")).toPath();
|
||||
final java.nio.file.Path configDirPath = ((File) optionSet.valueOf("paper-settings-directory")).toPath();
|
||||
io.papermc.paper.configuration.PaperConfigurations paperConfigurations = io.papermc.paper.configuration.PaperConfigurations.setup(legacyConfigPath, configDirPath, profileRepository.toPath(), (File) optionSet.valueOf("spigot-settings"));
|
||||
- return new Services(minecraftSessionService, authenticationService.getServicesKeySet(), gameProfileRepository, gameProfileCache, paperConfigurations);
|
||||
+ space.bxteam.divinemc.configuration.DivineConfigurations divineConfigurations = space.bxteam.divinemc.configuration.DivineConfigurations.setup(configDirPath); // DivineMC - setup divine configurations
|
||||
+ return new Services(minecraftSessionService, authenticationService.getServicesKeySet(), gameProfileRepository, gameProfileCache, paperConfigurations, divineConfigurations); // DivineMC - add divineConfigurations
|
||||
// Paper end - load paper config files from cli options
|
||||
}
|
||||
|
||||
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index 3d91240015ad8f464283da03bd45beba90cf2b89..d24e988a87d6defe5ac3d5483b54704225ebb7f0 100644
|
||||
index 3d91240015ad8f464283da03bd45beba90cf2b89..4aef0ac69817b85c5f8db94424dbc60f969153bf 100644
|
||||
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -217,6 +217,17 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
}
|
||||
org.purpurmc.purpur.PurpurConfig.registerCommands();
|
||||
// Purpur end - Configurable void damage height and damage
|
||||
+
|
||||
+ // DivineMC start - DivineMC Configuration
|
||||
+ try {
|
||||
+ space.bxteam.divinemc.configuration.DivineConfig.init((java.io.File) options.valueOf("divinemc-settings"));
|
||||
+ } catch (Exception e) {
|
||||
+ DedicatedServer.LOGGER.error("Unable to load server configuration", e);
|
||||
+ return false;
|
||||
+ }
|
||||
+ space.bxteam.divinemc.configuration.DivineConfig.registerCommands();
|
||||
+ // DivineMC end - DivineMC Configuration
|
||||
+
|
||||
// Paper start - initialize global and world-defaults configuration
|
||||
@@ -221,6 +221,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
|
||||
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
|
||||
// Paper end - initialize global and world-defaults configuration
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ divineConfigurations.initializeGlobalConfiguration(this.registryAccess());
|
||||
+ divineConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
this.server.spark.enableEarlyIfRequested(); // Paper - spark
|
||||
// Paper start - fix converting txt to json file; convert old users earlier after PlayerList creation but before file load/save
|
||||
if (this.convertOldUsers()) {
|
||||
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
||||
index 5e730cdde960603d5fa0fa7d1b70ec56c4fa8145..b6d339bc7f8f14d762c1083a9818bde6b9bcf9a1 100644
|
||||
--- a/net/minecraft/server/level/ServerLevel.java
|
||||
+++ b/net/minecraft/server/level/ServerLevel.java
|
||||
@@ -591,7 +591,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
||||
org.bukkit.generator.BiomeProvider biomeProvider // CraftBukkit
|
||||
) {
|
||||
// CraftBukkit start
|
||||
- super(serverLevelData, dimension, server.registryAccess(), levelStem.type(), false, isDebug, biomeZoomSeed, server.getMaxChainedNeighborUpdates(), gen, biomeProvider, env, spigotConfig -> server.paperConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(levelStorageAccess.levelDirectory.path(), serverLevelData.getLevelName(), dimension.location(), spigotConfig, server.registryAccess(), serverLevelData.getGameRules())), dispatcher); // Paper - create paper world configs; Async-Anti-Xray: Pass executor
|
||||
+ super(serverLevelData, dimension, server.registryAccess(), levelStem.type(), false, isDebug, biomeZoomSeed, server.getMaxChainedNeighborUpdates(), gen, biomeProvider, env, spigotConfig -> server.paperConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(levelStorageAccess.levelDirectory.path(), serverLevelData.getLevelName(), dimension.location(), spigotConfig, server.registryAccess(), serverLevelData.getGameRules())), spigotConfig -> server.divineConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(levelStorageAccess.levelDirectory.path(), serverLevelData.getLevelName(), dimension.location(), spigotConfig, server.registryAccess(), serverLevelData.getGameRules())), dispatcher); // Paper - create paper world configs; Async-Anti-Xray: Pass executor // DivineMC - DivineMC configuration
|
||||
this.pvpMode = server.isPvpAllowed();
|
||||
this.levelStorageAccess = levelStorageAccess;
|
||||
this.uuid = org.bukkit.craftbukkit.util.WorldUUID.getUUID(levelStorageAccess.levelDirectory.path().toFile());
|
||||
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
||||
index bcb2cfaa9780028fc5ada3a10139a5732e0e992c..58a1eb9be11bbea91196809328f41e10065e02d1 100644
|
||||
index 1b2d152649bc12b37db1cd7a4f54517f417d46e8..953a302aa4a1196b5e32bcf25f5e5f991a6f352d 100644
|
||||
--- a/net/minecraft/world/level/Level.java
|
||||
+++ b/net/minecraft/world/level/Level.java
|
||||
@@ -171,6 +171,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
||||
@@ -169,6 +169,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
||||
}
|
||||
// Paper end - add paper world config
|
||||
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ private final space.bxteam.divinemc.configuration.DivineWorldConfiguration divineConfig;
|
||||
+ public space.bxteam.divinemc.configuration.DivineWorldConfiguration divineConfig() {
|
||||
+ return this.divineConfig;
|
||||
+ }
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
+
|
||||
public final io.papermc.paper.antixray.ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
|
||||
public final org.purpurmc.purpur.PurpurWorldConfig purpurConfig; // Purpur - Purpur config files
|
||||
+ public final space.bxteam.divinemc.configuration.DivineWorldConfig divinemcConfig; // DivineMC - DivineMC Configuration
|
||||
public static BlockPos lastPhysicsProblem; // Spigot
|
||||
private int tileTickPosition;
|
||||
public final Map<ServerExplosion.CacheKey, Float> explosionDensityCache = new HashMap<>(); // Paper - Optimize explosions
|
||||
@@ -896,6 +897,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
||||
@@ -882,6 +889,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
||||
org.bukkit.World.Environment env, // CraftBukkit
|
||||
java.util.function.Function<org.spigotmc.SpigotWorldConfig, // Spigot - create per world config
|
||||
io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, // Paper - create paper world config
|
||||
+ java.util.function.Function<org.spigotmc.SpigotWorldConfig, // DivineMC - DivineMC configuration
|
||||
+ space.bxteam.divinemc.configuration.DivineWorldConfiguration> divinemcWorldConfigCreator, // DivineMC - DivineMC configuration
|
||||
java.util.concurrent.Executor executor // Paper - Anti-Xray
|
||||
) {
|
||||
// Paper start - getblock optimisations - cache world height/sections
|
||||
@@ -895,6 +904,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
|
||||
// Paper end - getblock optimisations - cache world height/sections
|
||||
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName()); // Spigot
|
||||
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
|
||||
+ this.divineConfig = divinemcWorldConfigCreator.apply(this.spigotConfig); // DivineMC - DivineMC configuration
|
||||
this.purpurConfig = new org.purpurmc.purpur.PurpurWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName(), env); // Purpur - Purpur config files
|
||||
+ this.divinemcConfig = new space.bxteam.divinemc.configuration.DivineWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName(), env); // DivineMC - DivineMC Configuration
|
||||
this.playerBreedingCooldowns = this.getNewBreedingCooldownCache(); // Purpur - Add adjustable breeding cooldown to config
|
||||
this.generator = gen;
|
||||
this.world = new CraftWorld((ServerLevel) this, gen, biomeProvider, env);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sun, 12 Jan 2025 16:55:31 +0300
|
||||
Subject: [PATCH] temporary fix for purpur build failure
|
||||
|
||||
|
||||
diff --git a/net/minecraft/world/level/block/EndGatewayBlock.java b/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
index 017bc4fda1a43e74acf77860916309ca7a4b0b10..54abeb142e119edd1c1d1c263821b95b1f05c388 100644
|
||||
--- a/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
+++ b/net/minecraft/world/level/block/EndGatewayBlock.java
|
||||
@@ -100,7 +100,7 @@ public class EndGatewayBlock extends BaseEntityBlock implements Portal {
|
||||
// Paper end - call EntityPortalEnterEvent
|
||||
// Purpur start - Add EntityTeleportHinderedEvent
|
||||
if (level.purpurConfig.imposeTeleportRestrictionsOnGateways && (entity.isVehicle() || entity.isPassenger())) {
|
||||
- if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, PlayerTeleportEvent.TeleportCause.END_GATEWAY).callEvent()) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_GATEWAY).callEvent()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
diff --git a/net/minecraft/world/level/block/EndPortalBlock.java b/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
index a229bf06e34305db5b8aa81bc26b47bfb7d79c5c..7e60bcadd2d343e00fc554dba0b85c9191f7efb6 100644
|
||||
--- a/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
+++ b/net/minecraft/world/level/block/EndPortalBlock.java
|
||||
@@ -60,7 +60,7 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
|
||||
if (entity.canUsePortal(false)) {
|
||||
// Purpur start - Add EntityTeleportHinderedEvent
|
||||
if (level.purpurConfig.imposeTeleportRestrictionsOnEndPortals && (entity.isVehicle() || entity.isPassenger())) {
|
||||
- if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, PlayerTeleportEvent.TeleportCause.END_PORTAL).callEvent()) {
|
||||
+ if (!new org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent(entity.getBukkitEntity(), entity.isPassenger() ? org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_PASSENGER : org.purpurmc.purpur.event.entity.EntityTeleportHinderedEvent.Reason.IS_VEHICLE, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL).callEvent()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
+ // DivineMC start - Don't save Fireworks
|
||||
+ @Override
|
||||
+ public boolean shouldBeSaved() {
|
||||
+ return this.level().divinemcConfig.saveFireworks;
|
||||
+ return true; // Temporary fix for saving fireworks
|
||||
+ }
|
||||
+ // DivineMC end - Don't save Fireworks
|
||||
+
|
||||
|
||||
@@ -1,68 +1,160 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
||||
Date: Sat, 11 Jan 2025 22:50:23 +0300
|
||||
Date: Sun, 12 Jan 2025 16:19:01 +0300
|
||||
Subject: [PATCH] DivineMC Configuration
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/configuration/Configurations.java b/src/main/java/io/papermc/paper/configuration/Configurations.java
|
||||
index 109e569b7ba6419d60c6490b588937579b4f6878..26f5026134e37e37236dfba9fd881021d7f8666e 100644
|
||||
--- a/src/main/java/io/papermc/paper/configuration/Configurations.java
|
||||
+++ b/src/main/java/io/papermc/paper/configuration/Configurations.java
|
||||
@@ -94,7 +94,7 @@ public abstract class Configurations<G, W> {
|
||||
};
|
||||
}
|
||||
|
||||
- static <T> CheckedFunction<ConfigurationNode, T, SerializationException> reloader(Class<T> type, T instance) {
|
||||
+ public static <T> CheckedFunction<ConfigurationNode, T, SerializationException> reloader(Class<T> type, T instance) { // DivineMC - DivineMC Configuration
|
||||
return node -> {
|
||||
ObjectMapper.Factory factory = (ObjectMapper.Factory) Objects.requireNonNull(node.options().serializers().get(type));
|
||||
ObjectMapper.Mutable<T> mutable = (ObjectMapper.Mutable<T>) factory.get(type);
|
||||
@@ -168,7 +168,7 @@ public abstract class Configurations<G, W> {
|
||||
final YamlConfigurationLoader loader = result.loader();
|
||||
final ConfigurationNode node = loader.load();
|
||||
if (result.isNewFile()) { // add version to new files
|
||||
- node.node(Configuration.VERSION_FIELD).raw(this.worldConfigVersion());
|
||||
+ node.node(Configuration.VERSION_FIELD).raw(getWorldConfigurationCurrentVersion()); // DivineMC - DivineMC Configuration
|
||||
} else {
|
||||
this.verifyWorldConfigVersion(contextMap, node);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public abstract class Configurations<G, W> {
|
||||
.build();
|
||||
final ConfigurationNode worldNode = worldLoader.load();
|
||||
if (newFile) { // set the version field if new file
|
||||
- worldNode.node(Configuration.VERSION_FIELD).set(this.worldConfigVersion());
|
||||
+ worldNode.node(Configuration.VERSION_FIELD).set(getWorldConfigurationCurrentVersion()); // DivineMC - DivineMC Configuration
|
||||
} else {
|
||||
this.verifyWorldConfigVersion(contextMap, worldNode);
|
||||
}
|
||||
@@ -356,4 +356,22 @@ public abstract class Configurations<G, W> {
|
||||
return "ContextKey{" + this.name + "}";
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // DivineMC start - DivineMC Configuration
|
||||
+ public static final String legacyWorldsSectionKey = "__________WORLDS__________";
|
||||
+ public static final String legacyWorldDefaultsSectionKey = "__defaults__";
|
||||
+
|
||||
+ @Deprecated
|
||||
+ public org.bukkit.configuration.file.YamlConfiguration createLegacyObject(final net.minecraft.server.MinecraftServer server) {
|
||||
+ org.bukkit.configuration.file.YamlConfiguration global = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.globalConfigFileName).toFile());
|
||||
+ org.bukkit.configuration.ConfigurationSection worlds = global.createSection(legacyWorldsSectionKey);
|
||||
+ worlds.set(legacyWorldDefaultsSectionKey, org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.defaultWorldConfigFileName).toFile()));
|
||||
+ for (ServerLevel level : server.getAllLevels()) {
|
||||
+ worlds.set(level.getWorld().getName(), org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(getWorldConfigFile(level).toFile()));
|
||||
+ }
|
||||
+ return global;
|
||||
+ }
|
||||
+
|
||||
+ public abstract int getWorldConfigurationCurrentVersion();
|
||||
+ // DivineMC end - DivineMC Configuration
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
||||
index 9f87f3da8e3f8cb16ea8f04cc233e143b174a709..1384abb3f98719d8f16ddb4cc48da71c18619606 100644
|
||||
--- a/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
||||
+++ b/src/main/java/io/papermc/paper/configuration/PaperConfigurations.java
|
||||
@@ -327,7 +327,7 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
|
||||
}
|
||||
}
|
||||
|
||||
- private static ContextMap createWorldContextMap(ServerLevel level) {
|
||||
+ public static ContextMap createWorldContextMap(ServerLevel level) { // DivineMC - DivineMC Configuration
|
||||
return createWorldContextMap(level.levelStorageAccess.levelDirectory.path(), level.serverLevelData.getLevelName(), level.dimension().location(), level.spigotConfig, level.registryAccess(), level.getGameRules());
|
||||
}
|
||||
|
||||
@@ -430,17 +430,6 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
|
||||
return Files.exists(legacyConfig) && Files.isRegularFile(legacyConfig);
|
||||
}
|
||||
|
||||
- @Deprecated
|
||||
- public YamlConfiguration createLegacyObject(final MinecraftServer server) {
|
||||
- YamlConfiguration global = YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.globalConfigFileName).toFile());
|
||||
- ConfigurationSection worlds = global.createSection("__________WORLDS__________");
|
||||
- worlds.set("__defaults__", YamlConfiguration.loadConfiguration(this.globalFolder.resolve(this.defaultWorldConfigFileName).toFile()));
|
||||
- for (ServerLevel level : server.getAllLevels()) {
|
||||
- worlds.set(level.getWorld().getName(), YamlConfiguration.loadConfiguration(getWorldConfigFile(level).toFile()));
|
||||
- }
|
||||
- return global;
|
||||
- }
|
||||
-
|
||||
@Deprecated
|
||||
public static YamlConfiguration loadLegacyConfigFile(File configFile) throws Exception {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
@@ -463,9 +452,16 @@ public class PaperConfigurations extends Configurations<GlobalConfiguration, Wor
|
||||
}
|
||||
|
||||
// Symlinks are not correctly checked in createDirectories
|
||||
- static void createDirectoriesSymlinkAware(Path path) throws IOException {
|
||||
+ public static void createDirectoriesSymlinkAware(Path path) throws IOException { // DivineMC - DivineMC Configuration
|
||||
if (!Files.isDirectory(path)) {
|
||||
Files.createDirectories(path);
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ @Override
|
||||
+ public int getWorldConfigurationCurrentVersion() {
|
||||
+ return WorldConfiguration.CURRENT_VERSION;
|
||||
+ }
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java b/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
|
||||
index 05339a176083af667c16f77d76dc1878dafce3f0..0a1428b826fe4057058cf24284bd5f6fed8230cb 100644
|
||||
--- a/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
|
||||
+++ b/src/main/java/io/papermc/paper/configuration/mapping/InnerClassFieldDiscoverer.java
|
||||
@@ -46,7 +46,19 @@ public final class InnerClassFieldDiscoverer implements FieldDiscoverer<Map<Fiel
|
||||
return new InnerClassFieldDiscoverer(overrides);
|
||||
}
|
||||
|
||||
- public static FieldDiscoverer<?> globalConfig() {
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ public static FieldDiscoverer<?> divineWorldConfig(io.papermc.paper.configuration.Configurations.ContextMap contextMap) {
|
||||
+ final Map<Class<?>, Object> overrides = Map.of(
|
||||
+ space.bxteam.divinemc.configuration.DivineWorldConfiguration.class, new space.bxteam.divinemc.configuration.DivineWorldConfiguration(
|
||||
+ contextMap.require(io.papermc.paper.configuration.PaperConfigurations.SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get(),
|
||||
+ contextMap.require(io.papermc.paper.configuration.Configurations.WORLD_KEY)
|
||||
+ )
|
||||
+ );
|
||||
+ return new InnerClassFieldDiscoverer(overrides);
|
||||
+ }
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
+
|
||||
+ public static FieldDiscoverer<?> globalConfig() { // DivineMC - DivineMC configuration
|
||||
return new InnerClassFieldDiscoverer(Collections.emptyMap());
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 4cf13628c0d304fbf658fcb6f09631b282c34bfa..fc5797fe93bfd23a3fae94e08d6bc131eb278eb6 100644
|
||||
index 4cf13628c0d304fbf658fcb6f09631b282c34bfa..14a499fd21d653951a30552f740b4d1ca3851158 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -1088,6 +1088,7 @@ public final class CraftServer implements Server {
|
||||
@@ -1087,6 +1087,7 @@ public final class CraftServer implements Server {
|
||||
|
||||
org.spigotmc.SpigotConfig.init((File) this.console.options.valueOf("spigot-settings")); // Spigot
|
||||
this.console.paperConfigurations.reloadConfigs(this.console);
|
||||
+ this.console.divineConfigurations.reloadConfigs(this.console); // DivineMC - DivineMC configuration
|
||||
org.purpurmc.purpur.PurpurConfig.init((File) console.options.valueOf("purpur-settings")); // Purpur - Purpur config files
|
||||
+ space.bxteam.divinemc.configuration.DivineConfig.init((File) console.options.valueOf("divinemc-settings")); // DivineMC - DivineMC Configuration
|
||||
for (ServerLevel world : this.console.getAllLevels()) {
|
||||
// world.serverLevelData.setDifficulty(config.difficulty); // Paper - per level difficulty
|
||||
world.setSpawnSettings(world.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && config.spawnMonsters); // Paper - per level difficulty (from MinecraftServer#setDifficulty(ServerLevel, Difficulty, boolean))
|
||||
@@ -1104,6 +1105,7 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
world.spigotConfig.init(); // Spigot
|
||||
world.purpurConfig.init(); // Purpur - Purpur config files
|
||||
+ world.divinemcConfig.init(); // DivineMC - DivineMC Configuration
|
||||
@@ -3056,6 +3057,13 @@ public final class CraftServer implements Server {
|
||||
return CraftServer.this.console.paperConfigurations.createLegacyObject(CraftServer.this.console);
|
||||
}
|
||||
|
||||
Plugin[] pluginClone = pluginManager.getPlugins().clone(); // Paper
|
||||
@@ -1122,6 +1124,7 @@ public final class CraftServer implements Server {
|
||||
io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper
|
||||
this.spark.registerCommandBeforePlugins(this); // Paper - spark
|
||||
org.purpurmc.purpur.PurpurConfig.registerCommands(); // Purpur - Purpur config files
|
||||
+ space.bxteam.divinemc.configuration.DivineConfig.registerCommands(); // DivineMC - DivineMC Configuration
|
||||
this.overrideAllCommandBlockCommands = this.commandsConfiguration.getStringList("command-block-overrides").contains("*");
|
||||
this.ignoreVanillaPermissions = this.commandsConfiguration.getBoolean("ignore-vanilla-permissions");
|
||||
|
||||
@@ -3068,6 +3071,13 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
// Purpur end - Purpur config files
|
||||
|
||||
+ // DivineMC start - DivineMC Configuration
|
||||
+ // DivineMC start - DivineMC configuration
|
||||
+ @Override
|
||||
+ public YamlConfiguration getDivineConfig() {
|
||||
+ return space.bxteam.divinemc.configuration.DivineConfig.config;
|
||||
+ return CraftServer.this.console.divineConfigurations.createLegacyObject(CraftServer.this.console);
|
||||
+ }
|
||||
+ // DivineMC end - DivineMC Configuration
|
||||
+ // DivineMC end - DivineMC configuration
|
||||
+
|
||||
// Purpur start - Purpur config files
|
||||
@Override
|
||||
public void restart() {
|
||||
org.spigotmc.RestartCommand.restart();
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
|
||||
index 90fb036607e752fcf43575be4f03bbf00bbb05c7..22ba21fb13ed1e3ceede833c1173d17e5b60c1b6 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
||||
@@ -183,6 +183,15 @@ public class Main {
|
||||
.defaultsTo(new File("purpur.yml"))
|
||||
.describedAs("Yml file");
|
||||
// Purpur end - Purpur config files
|
||||
+
|
||||
+ // DivineMC start - DivineMC Configuration
|
||||
+ acceptsAll(asList("divinemc", "divinemc-settings"), "File for divinemc settings")
|
||||
+ .withRequiredArg()
|
||||
+ .ofType(File.class)
|
||||
+ .defaultsTo(new File("divinemc.yml"))
|
||||
+ .describedAs("Yml file");
|
||||
+ // DivineMC end - DivineMC Configuration
|
||||
+
|
||||
// Paper start
|
||||
acceptsAll(asList("server-name"), "Name of the server")
|
||||
.withRequiredArg()
|
||||
public YamlConfiguration getPurpurConfig() {
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
package space.bxteam.divinemc.commands;
|
||||
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import space.bxteam.divinemc.configuration.DivineConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DivineCommand extends Command {
|
||||
public DivineCommand(String name) {
|
||||
super(name);
|
||||
this.description = "DivineMC related commands";
|
||||
this.usageMessage = "/divinemc [reload | version]";
|
||||
this.setPermission("bukkit.command.divinemc");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
|
||||
if (args.length == 1) {
|
||||
return Stream.of("reload", "version")
|
||||
.filter(arg -> arg.startsWith(args[0].toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender)) return true;
|
||||
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues.");
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
|
||||
|
||||
MinecraftServer console = MinecraftServer.getServer();
|
||||
DivineConfig.init((File) console.options.valueOf("divinemc-settings"));
|
||||
for (ServerLevel level : console.getAllLevels()) {
|
||||
level.divinemcConfig.init();
|
||||
level.resetBreedingCooldowns();
|
||||
}
|
||||
console.server.reloadCount++;
|
||||
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "DivineMC config reload complete.");
|
||||
} else if (args[0].equalsIgnoreCase("version")) {
|
||||
Command verCmd = org.bukkit.Bukkit.getServer().getCommandMap().getCommand("version");
|
||||
if (verCmd != null) {
|
||||
return verCmd.execute(sender, commandLabel, new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import space.bxteam.divinemc.commands.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class DivineConfig {
|
||||
private static final String HEADER = "This is the main configuration file for DivineMC.\n"
|
||||
+ "If you need help with the configuration or have any questions related to DivineMC,\n"
|
||||
+ "join us in our Discord server.\n"
|
||||
+ "\n"
|
||||
+ "Discord: https://discord.gg/p7cxhw7E2M \n"
|
||||
+ "Docs: https://docs.bx-team.space/divinemc \n"
|
||||
+ "New builds: https://github.com/DivineMC/DivineMC/releases/latest";
|
||||
private static File CONFIG_FILE;
|
||||
public static YamlConfiguration config;
|
||||
|
||||
private static Map<String, Command> commands;
|
||||
|
||||
public static int version;
|
||||
static boolean verbose;
|
||||
|
||||
public static void init(File configFile) {
|
||||
CONFIG_FILE = configFile;
|
||||
config = new YamlConfiguration();
|
||||
try {
|
||||
config.load(CONFIG_FILE);
|
||||
} catch (IOException ignore) {
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not load divinemc.yml, please correct your syntax errors", ex);
|
||||
throw Throwables.propagate(ex);
|
||||
}
|
||||
config.options().header(HEADER);
|
||||
config.options().copyDefaults(true);
|
||||
verbose = getBoolean("verbose", false);
|
||||
|
||||
commands = new HashMap<>();
|
||||
commands.put("divinemc", new DivineCommand("divinemc"));
|
||||
|
||||
version = getInt("config-version", 3);
|
||||
set("config-version", 3);
|
||||
|
||||
readConfig(DivineConfig.class, null);
|
||||
|
||||
Block.BLOCK_STATE_REGISTRY.forEach(BlockBehaviour.BlockStateBase::initCache);
|
||||
}
|
||||
|
||||
protected static void log(String s) {
|
||||
if (verbose) {
|
||||
log(Level.INFO, s);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void log(Level level, String s) {
|
||||
Bukkit.getLogger().log(level, s);
|
||||
}
|
||||
|
||||
public static void registerCommands() {
|
||||
for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
||||
MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "DivineMC", entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
static void readConfig(Class<?> clazz, Object instance) {
|
||||
for (Method method : clazz.getDeclaredMethods()) {
|
||||
if (Modifier.isPrivate(method.getModifiers())) {
|
||||
if (method.getParameterTypes().length == 0 && method.getReturnType() == Void.TYPE) {
|
||||
try {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw Throwables.propagate(ex.getCause());
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Error invoking " + method, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config.save(CONFIG_FILE);
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Could not save " + CONFIG_FILE, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void set(String path, Object val) {
|
||||
config.addDefault(path, val);
|
||||
config.set(path, val);
|
||||
}
|
||||
|
||||
private static String getString(String path, String def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getString(path, config.getString(path));
|
||||
}
|
||||
|
||||
private static boolean getBoolean(String path, boolean def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getBoolean(path, config.getBoolean(path));
|
||||
}
|
||||
|
||||
private static double getDouble(String path, double def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getDouble(path, config.getDouble(path));
|
||||
}
|
||||
|
||||
private static int getInt(String path, int def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getInt(path, config.getInt(path));
|
||||
}
|
||||
|
||||
private static <T> List getList(String path, T def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getList(path, config.getList(path));
|
||||
}
|
||||
|
||||
static Map<String, Object> getMap(String path, Map<String, Object> def) {
|
||||
if (def != null && config.getConfigurationSection(path) == null) {
|
||||
config.addDefault(path, def);
|
||||
return def;
|
||||
}
|
||||
return toMap(config.getConfigurationSection(path));
|
||||
}
|
||||
|
||||
private static Map<String, Object> toMap(ConfigurationSection section) {
|
||||
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
|
||||
if (section != null) {
|
||||
for (String key : section.getKeys(false)) {
|
||||
Object obj = section.get(key);
|
||||
if (obj != null) {
|
||||
builder.put(key, obj instanceof ConfigurationSection val ? toMap(val) : obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import com.google.common.collect.Table;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import io.papermc.paper.configuration.Configuration;
|
||||
import io.papermc.paper.configuration.ConfigurationPart;
|
||||
import io.papermc.paper.configuration.Configurations;
|
||||
import io.papermc.paper.configuration.NestedSetting;
|
||||
import io.papermc.paper.configuration.PaperConfigurations;
|
||||
import io.papermc.paper.configuration.legacy.RequiresSpigotInitialization;
|
||||
import io.papermc.paper.configuration.mapping.InnerClassFieldDiscoverer;
|
||||
import io.papermc.paper.configuration.serializer.ComponentSerializer;
|
||||
import io.papermc.paper.configuration.serializer.EnumValueSerializer;
|
||||
import io.papermc.paper.configuration.serializer.PacketClassSerializer;
|
||||
import io.papermc.paper.configuration.serializer.StringRepresentableSerializer;
|
||||
import io.papermc.paper.configuration.serializer.collections.FastutilMapSerializer;
|
||||
import io.papermc.paper.configuration.serializer.collections.MapSerializer;
|
||||
import io.papermc.paper.configuration.serializer.collections.TableSerializer;
|
||||
import io.papermc.paper.configuration.serializer.registry.RegistryHolderSerializer;
|
||||
import io.papermc.paper.configuration.serializer.registry.RegistryValueSerializer;
|
||||
import io.papermc.paper.configuration.transformation.Transformations;
|
||||
import io.papermc.paper.configuration.type.BooleanOrDefault;
|
||||
import io.papermc.paper.configuration.type.Duration;
|
||||
import io.papermc.paper.configuration.type.EngineMode;
|
||||
import io.papermc.paper.configuration.type.fallback.FallbackValueSerializer;
|
||||
import io.papermc.paper.configuration.type.number.DoubleOr;
|
||||
import io.papermc.paper.configuration.type.number.IntOr;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2LongMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2LongOpenHashMap;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.NodePath;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
|
||||
import org.spongepowered.configurate.transformation.TransformAction;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static io.leangen.geantyref.GenericTypeReflector.erase;
|
||||
|
||||
@SuppressWarnings("Convert2Diamond")
|
||||
public class DivineConfigurations extends Configurations<DivineGlobalConfiguration, DivineWorldConfiguration> {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
static final String GLOBAL_CONFIG_FILE_NAME = "divinemc-global.yml";
|
||||
static final String WORLD_DEFAULTS_CONFIG_FILE_NAME = "divinemc-world-defaults.yml";
|
||||
static final String WORLD_CONFIG_FILE_NAME = "divinemc-world.yml";
|
||||
public static final String CONFIG_DIR = "config";
|
||||
|
||||
private static final String GLOBAL_HEADER = String.format("""
|
||||
This is the global configuration file for DivineMC.
|
||||
|
||||
If you need help with the configuration or have any questions related to DivineMC,
|
||||
join us in our Discord, or check our Documentation website.
|
||||
|
||||
The world configuration options are inside
|
||||
their respective world folder. The files are named %s
|
||||
|
||||
Documentation: https://docs.bx-team.space/documentation/divinemc/about
|
||||
Discord: https://discord.gg/p7cxhw7E2M""", WORLD_CONFIG_FILE_NAME);
|
||||
|
||||
private static final String WORLD_DEFAULTS_HEADER = """
|
||||
This is the world defaults configuration file for DivineMC.
|
||||
|
||||
If you need help with the configuration or have any questions related to DivineMC,
|
||||
join us in our Discord, or check our Documentation website.
|
||||
|
||||
Configuration options here apply to all worlds, unless you specify overrides inside
|
||||
the world-specific config file inside each world folder.
|
||||
|
||||
Documentation: https://docs.bx-team.space/documentation/divinemc/about
|
||||
Discord: https://discord.gg/p7cxhw7E2M""";
|
||||
|
||||
private static final Function<ContextMap, String> WORLD_HEADER = map -> String.format("""
|
||||
This is a world configuration file for DivineMC.
|
||||
This file may start empty but can be filled with settings to override ones in the %s/%s
|
||||
|
||||
World: %s (%s)""",
|
||||
CONFIG_DIR,
|
||||
WORLD_DEFAULTS_CONFIG_FILE_NAME,
|
||||
map.require(WORLD_NAME),
|
||||
map.require(WORLD_KEY)
|
||||
);
|
||||
|
||||
public DivineConfigurations(final Path globalFolder) {
|
||||
super(globalFolder, DivineGlobalConfiguration.class, DivineWorldConfiguration.class, GLOBAL_CONFIG_FILE_NAME, WORLD_DEFAULTS_CONFIG_FILE_NAME, WORLD_CONFIG_FILE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected YamlConfigurationLoader.Builder createLoaderBuilder() {
|
||||
return super.createLoaderBuilder()
|
||||
.defaultOptions(DivineConfigurations::defaultOptions);
|
||||
}
|
||||
|
||||
private static ConfigurationOptions defaultOptions(ConfigurationOptions options) {
|
||||
return options.serializers(builder -> builder
|
||||
.register(MapSerializer.TYPE, new MapSerializer(false))
|
||||
.register(new EnumValueSerializer())
|
||||
.register(new ComponentSerializer())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectMapper.Factory.Builder createGlobalObjectMapperFactoryBuilder() {
|
||||
return defaultGlobalFactoryBuilder(super.createGlobalObjectMapperFactoryBuilder());
|
||||
}
|
||||
|
||||
private static ObjectMapper.Factory.Builder defaultGlobalFactoryBuilder(ObjectMapper.Factory.Builder builder) {
|
||||
return builder.addDiscoverer(InnerClassFieldDiscoverer.globalConfig());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected YamlConfigurationLoader.Builder createGlobalLoaderBuilder() {
|
||||
return super.createGlobalLoaderBuilder()
|
||||
.defaultOptions(DivineConfigurations::defaultGlobalOptions);
|
||||
}
|
||||
|
||||
private static ConfigurationOptions defaultGlobalOptions(ConfigurationOptions options) {
|
||||
return options
|
||||
.header(GLOBAL_HEADER)
|
||||
.serializers(builder -> builder.register(new PacketClassSerializer()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DivineGlobalConfiguration initializeGlobalConfiguration(final RegistryAccess registryAccess) throws ConfigurateException {
|
||||
DivineGlobalConfiguration configuration = super.initializeGlobalConfiguration(registryAccess);
|
||||
DivineGlobalConfiguration.set(configuration);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContextMap.Builder createDefaultContextMap(final RegistryAccess registryAccess) {
|
||||
return super.createDefaultContextMap(registryAccess)
|
||||
.put(PaperConfigurations.SPIGOT_WORLD_CONFIG_CONTEXT_KEY, PaperConfigurations.SPIGOT_WORLD_DEFAULTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectMapper.Factory.Builder createWorldObjectMapperFactoryBuilder(final ContextMap contextMap) {
|
||||
return super.createWorldObjectMapperFactoryBuilder(contextMap)
|
||||
.addNodeResolver(new RequiresSpigotInitialization.Factory(contextMap.require(PaperConfigurations.SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get()))
|
||||
.addNodeResolver(new NestedSetting.Factory())
|
||||
.addDiscoverer(InnerClassFieldDiscoverer.divineWorldConfig(contextMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected YamlConfigurationLoader.Builder createWorldConfigLoaderBuilder(final ContextMap contextMap) {
|
||||
final RegistryAccess access = contextMap.require(REGISTRY_ACCESS);
|
||||
return super.createWorldConfigLoaderBuilder(contextMap)
|
||||
.defaultOptions(options -> options
|
||||
.header(contextMap.require(WORLD_NAME).equals(WORLD_DEFAULTS) ? WORLD_DEFAULTS_HEADER : WORLD_HEADER.apply(contextMap))
|
||||
.serializers(serializers -> serializers
|
||||
.register(new TypeToken<Reference2IntMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2IntMap<?>>(Reference2IntOpenHashMap::new, Integer.TYPE))
|
||||
.register(new TypeToken<Reference2LongMap<?>>() {}, new FastutilMapSerializer.SomethingToPrimitive<Reference2LongMap<?>>(Reference2LongOpenHashMap::new, Long.TYPE))
|
||||
.register(new TypeToken<Table<?, ?, ?>>() {}, new TableSerializer())
|
||||
.register(new StringRepresentableSerializer())
|
||||
.register(IntOr.Default.SERIALIZER)
|
||||
.register(IntOr.Disabled.SERIALIZER)
|
||||
.register(DoubleOr.Default.SERIALIZER)
|
||||
.register(BooleanOrDefault.SERIALIZER)
|
||||
.register(Duration.SERIALIZER)
|
||||
.register(EngineMode.SERIALIZER)
|
||||
.register(FallbackValueSerializer.create(contextMap.require(PaperConfigurations.SPIGOT_WORLD_CONFIG_CONTEXT_KEY).get(), MinecraftServer::getServer))
|
||||
.register(new RegistryValueSerializer<>(new TypeToken<EntityType<?>>() {}, access, Registries.ENTITY_TYPE, true))
|
||||
.register(new RegistryValueSerializer<>(Item.class, access, Registries.ITEM, true))
|
||||
.register(new RegistryHolderSerializer<>(new TypeToken<ConfiguredFeature<?, ?>>() {}, access, Registries.CONFIGURED_FEATURE, false))
|
||||
.register(new RegistryHolderSerializer<>(Item.class, access, Registries.ITEM, true))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyWorldConfigTransformations(final ContextMap contextMap, final ConfigurationNode node, final @Nullable ConfigurationNode defaultsNode) throws ConfigurateException {
|
||||
final ConfigurationNode version = node.node(Configuration.VERSION_FIELD);
|
||||
final String world = contextMap.require(WORLD_NAME);
|
||||
if (version.virtual()) {
|
||||
LOGGER.warn("The DivineMC world config file for " + world + " didn't have a version set, assuming latest");
|
||||
version.raw(DivineWorldConfiguration.CURRENT_VERSION);
|
||||
}
|
||||
if (DivineRemovedConfiguration.REMOVED_WORLD_PATHS.length > 0) {
|
||||
ConfigurationTransformation.Builder builder = ConfigurationTransformation.builder();
|
||||
for (NodePath path : DivineRemovedConfiguration.REMOVED_WORLD_PATHS) {
|
||||
builder.addAction(path, TransformAction.remove());
|
||||
}
|
||||
builder.build().apply(node);
|
||||
}
|
||||
// ADD FUTURE TRANSFORMS HERE
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyGlobalConfigTransformations(ConfigurationNode node) throws ConfigurateException {
|
||||
if (DivineRemovedConfiguration.REMOVED_GLOBAL_PATHS.length > 0) {
|
||||
ConfigurationTransformation.Builder builder = ConfigurationTransformation.builder();
|
||||
for (NodePath path : DivineRemovedConfiguration.REMOVED_GLOBAL_PATHS) {
|
||||
builder.addAction(path, TransformAction.remove());
|
||||
}
|
||||
builder.build().apply(node);
|
||||
}
|
||||
// ADD FUTURE TRANSFORMS HERE
|
||||
}
|
||||
|
||||
private static final List<Transformations.DefaultsAware> DEFAULT_AWARE_TRANSFORMATIONS = Collections.emptyList();
|
||||
|
||||
@Override
|
||||
protected void applyDefaultsAwareWorldConfigTransformations(final ContextMap contextMap, final ConfigurationNode worldNode, final ConfigurationNode defaultsNode) throws ConfigurateException {
|
||||
final ConfigurationTransformation.Builder builder = ConfigurationTransformation.builder();
|
||||
// ADD FUTURE TRANSFORMS HERE (these transforms run after the defaults have been merged into the node)
|
||||
DEFAULT_AWARE_TRANSFORMATIONS.forEach(transform -> transform.apply(builder, contextMap, defaultsNode));
|
||||
|
||||
ConfigurationTransformation transformation;
|
||||
try {
|
||||
transformation = builder.build(); // build throws IAE if no actions were provided (bad zml)
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return;
|
||||
}
|
||||
transformation.apply(worldNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DivineWorldConfiguration createWorldConfig(final ContextMap contextMap) {
|
||||
final String levelName = contextMap.require(WORLD_NAME);
|
||||
try {
|
||||
return super.createWorldConfig(contextMap);
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException("Could not create DivineMC world config for " + levelName, exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isConfigType(final Type type) {
|
||||
return ConfigurationPart.class.isAssignableFrom(erase(type));
|
||||
}
|
||||
|
||||
public void reloadConfigs(MinecraftServer server) {
|
||||
try {
|
||||
this.initializeGlobalConfiguration(reloader(this.globalConfigClass, DivineGlobalConfiguration.get()));
|
||||
this.initializeWorldDefaultsConfiguration(server.registryAccess());
|
||||
for (ServerLevel level : server.getAllLevels()) {
|
||||
this.createWorldConfig(PaperConfigurations.createWorldContextMap(level), reloader(this.worldConfigClass, level.divineConfig()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException("Could not reload DivineMC configuration files", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static DivineConfigurations setup(final Path configDir) throws Exception {
|
||||
try {
|
||||
PaperConfigurations.createDirectoriesSymlinkAware(configDir);
|
||||
return new DivineConfigurations(configDir);
|
||||
} catch (final IOException ex) {
|
||||
throw new RuntimeException("Could not setup DivineConfigurations", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int globalConfigVersion() {
|
||||
return DivineGlobalConfiguration.CURRENT_VERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int worldConfigVersion() {
|
||||
return getWorldConfigurationCurrentVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWorldConfigurationCurrentVersion() {
|
||||
return DivineWorldConfiguration.CURRENT_VERSION;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import io.papermc.paper.configuration.Configuration;
|
||||
import io.papermc.paper.configuration.ConfigurationPart;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"})
|
||||
public class DivineGlobalConfiguration extends ConfigurationPart {
|
||||
static final int CURRENT_VERSION = 4;
|
||||
|
||||
private static DivineGlobalConfiguration instance;
|
||||
|
||||
public static DivineGlobalConfiguration get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void set(DivineGlobalConfiguration instance) {
|
||||
DivineGlobalConfiguration.instance = instance;
|
||||
}
|
||||
|
||||
@Setting(Configuration.VERSION_FIELD)
|
||||
public int version = CURRENT_VERSION;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import org.spongepowered.configurate.NodePath;
|
||||
|
||||
interface DivineRemovedConfiguration {
|
||||
NodePath[] REMOVED_WORLD_PATHS = {};
|
||||
|
||||
NodePath[] REMOVED_GLOBAL_PATHS = {};
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static space.bxteam.divinemc.configuration.DivineConfig.log;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class DivineWorldConfig {
|
||||
private final String worldName;
|
||||
private final World.Environment environment;
|
||||
|
||||
public DivineWorldConfig(String worldName, World.Environment environment) {
|
||||
this.worldName = worldName;
|
||||
this.environment = environment;
|
||||
init();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
log("-------- World Settings For [" + worldName + "] --------");
|
||||
DivineConfig.readConfig(DivineWorldConfig.class, this);
|
||||
}
|
||||
|
||||
private void set(String path, Object val) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, val);
|
||||
DivineConfig.config.set("world-settings.default." + path, val);
|
||||
if (DivineConfig.config.get("world-settings." + worldName + "." + path) != null) {
|
||||
DivineConfig.config.addDefault("world-settings." + worldName + "." + path, val);
|
||||
DivineConfig.config.set("world-settings." + worldName + "." + path, val);
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationSection getConfigurationSection(String path) {
|
||||
ConfigurationSection section = DivineConfig.config.getConfigurationSection("world-settings." + worldName + "." + path);
|
||||
return section != null ? section : DivineConfig.config.getConfigurationSection("world-settings.default." + path);
|
||||
}
|
||||
|
||||
private String getString(String path, String def) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return DivineConfig.config.getString("world-settings." + worldName + "." + path, DivineConfig.config.getString("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, boolean def) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return DivineConfig.config.getBoolean("world-settings." + worldName + "." + path, DivineConfig.config.getBoolean("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private boolean getBoolean(String path, Predicate<Boolean> predicate) {
|
||||
String val = getString(path, "default").toLowerCase();
|
||||
Boolean bool = BooleanUtils.toBooleanObject(val, "true", "false", "default");
|
||||
return predicate.test(bool);
|
||||
}
|
||||
|
||||
private double getDouble(String path, double def) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return DivineConfig.config.getDouble("world-settings." + worldName + "." + path, DivineConfig.config.getDouble("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private int getInt(String path, int def) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return DivineConfig.config.getInt("world-settings." + worldName + "." + path, DivineConfig.config.getInt("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private <T> List<?> getList(String path, T def) {
|
||||
DivineConfig.config.addDefault("world-settings.default." + path, def);
|
||||
return DivineConfig.config.getList("world-settings." + worldName + "." + path, DivineConfig.config.getList("world-settings.default." + path));
|
||||
}
|
||||
|
||||
private Map<String, Object> getMap(String path, Map<String, Object> def) {
|
||||
final Map<String, Object> fallback = DivineConfig.getMap("world-settings.default." + path, def);
|
||||
final Map<String, Object> value = DivineConfig.getMap("world-settings." + worldName + "." + path, null);
|
||||
return value.isEmpty() ? fallback : value;
|
||||
}
|
||||
|
||||
public boolean saveFireworks = false;
|
||||
private void saveFireworks() {
|
||||
saveFireworks = getBoolean("gameplay-mechanics.should-save-fireworks", saveFireworks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package space.bxteam.divinemc.configuration;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import io.papermc.paper.configuration.Configuration;
|
||||
import io.papermc.paper.configuration.ConfigurationPart;
|
||||
import io.papermc.paper.configuration.PaperConfigurations;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.slf4j.Logger;
|
||||
import org.spigotmc.SpigotWorldConfig;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"})
|
||||
public class DivineWorldConfiguration extends ConfigurationPart {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final int CURRENT_VERSION = 4;
|
||||
|
||||
private transient final SpigotWorldConfig spigotConfig;
|
||||
private transient final ResourceLocation worldKey;
|
||||
|
||||
public DivineWorldConfiguration(SpigotWorldConfig spigotConfig, ResourceLocation worldKey) {
|
||||
this.spigotConfig = spigotConfig;
|
||||
this.worldKey = worldKey;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return this.worldKey.equals(PaperConfigurations.WORLD_DEFAULTS_KEY);
|
||||
}
|
||||
|
||||
@Setting(Configuration.VERSION_FIELD)
|
||||
public int version = CURRENT_VERSION;
|
||||
}
|
||||
Reference in New Issue
Block a user