Files
LuminolMC/patches/server/0003-Added-empty-luminol-config.patch
2024-01-27 14:38:04 +00:00

180 lines
7.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <novau233@163.com>
Date: Sat, 27 Jan 2024 07:36:28 +0000
Subject: [PATCH] Added empty luminol config
diff --git a/build.gradle.kts b/build.gradle.kts
index b9c5ef4d15aa97a380419912e3ee09d094ae752e..83660616a26d989ce441e17acab103ab166304d8 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -19,6 +19,7 @@ dependencies {
exclude("io.papermc.paper", "paper-api")
}
// Folia end
+ implementation("com.electronwill.night-config:toml:3.6.0") //Luminol - Night config
// Paper start
implementation("org.jline:jline-terminal-jansi:3.21.0")
implementation("net.minecrell:terminalconsoleappender:1.3.0")
diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..1f9ff0fc33fa36c90fc4cbbd21b7b790de581632
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/LuminolConfig.java
@@ -0,0 +1,99 @@
+package me.earthme.luminol;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import net.minecraft.server.level.ServerLevel;
+
+import java.io.File;
+import java.io.IOException;
+
+public class LuminolConfig {
+ private static final File PARENT_FOLDER = new File("luminol_config");
+ private static final File MAIN_CONFIG_FILE = new File(PARENT_FOLDER,"luminol_global.toml");
+ private static CommentedFileConfig MAIN_CONFIG;
+
+ public static String serverModName = "Luminol";
+ public static boolean fakeVanillaModeEnabled = false;
+
+ public static void init() throws IOException {
+ PARENT_FOLDER.mkdir();
+
+ if (!MAIN_CONFIG_FILE.exists()){
+ MAIN_CONFIG_FILE.createNewFile();
+ }
+
+ MAIN_CONFIG = CommentedFileConfig.ofConcurrent(MAIN_CONFIG_FILE);
+
+ MAIN_CONFIG.load();
+ initValues();
+ MAIN_CONFIG.save();
+ }
+
+ public static void initValues(){
+ serverModName = get("misc.server_mod_name",serverModName,"The servermod name will be sent to players,and you can see it in F3 or motd responses");
+ fakeVanillaModeEnabled = get("misc.enable_fake_vanilla_mode",fakeVanillaModeEnabled,"Enable this to make the ping response of your server like a vanilla server");
+ }
+
+ public static <T> T get(String key,T def){
+ if (MAIN_CONFIG.contains(key)){
+ return MAIN_CONFIG.get(key);
+ }
+
+ MAIN_CONFIG.set(key,def);
+ return def;
+ }
+
+ public static <T> T get(String key,T def,String comment){
+ MAIN_CONFIG.setComment(key,comment);
+
+ if (MAIN_CONFIG.contains(key)){
+ return MAIN_CONFIG.get(key);
+ }
+
+ MAIN_CONFIG.set(key,def);
+ return def;
+ }
+
+ public static class LumionalWorldConfig{
+ private final File configFile;
+ private CommentedFileConfig commentedFileConfig;
+
+ public LumionalWorldConfig(ServerLevel level) {
+ this.configFile = new File(PARENT_FOLDER,"luminol_world_"+level.getWorld().getName()+".toml");
+ }
+
+ public void init() throws IOException {
+ if (!this.configFile.exists()){
+ this.configFile.createNewFile();
+ }
+
+ this.commentedFileConfig = CommentedFileConfig.ofConcurrent(this.configFile);
+ this.commentedFileConfig.load();
+ this.initValues();
+ this.commentedFileConfig.save();
+ }
+
+ public void initValues(){
+
+ }
+
+ public <T> T get(String key,T def,String comment){
+ this.commentedFileConfig.setComment(key,comment);
+
+ if (this.commentedFileConfig.contains(key)){
+ return this.commentedFileConfig.get(key);
+ }
+
+ this.commentedFileConfig.set(key,def);
+ return def;
+ }
+
+ public <T> T get(String key,T def){
+ if (this.commentedFileConfig.contains(key)){
+ return this.commentedFileConfig.get(key);
+ }
+
+ this.commentedFileConfig.set(key,def);
+ return def;
+ }
+ }
+}
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 98ea5cecac2ab647acfb4d8bbea8ada9872cc4cd..e5eeb361fc29c831a76f87c60896b5dd23f58736 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -19,6 +19,8 @@ import java.util.Locale;
import java.util.Optional;
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;
+
+import me.earthme.luminol.LuminolConfig;
import net.minecraft.DefaultUncaughtExceptionHandler;
import net.minecraft.DefaultUncaughtExceptionHandlerWithName;
import net.minecraft.SharedConstants;
@@ -205,6 +207,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
org.spigotmc.SpigotConfig.registerCommands();
// Spigot end
io.papermc.paper.util.ObfHelper.INSTANCE.getClass(); // Paper - load mappings for stacktrace deobf and etc.
+ LuminolConfig.init(); //Luminol
// Paper start - initialize global and world-defaults configuration
this.paperConfigurations.initializeGlobalConfiguration(this.registryAccess());
this.paperConfigurations.initializeWorldDefaultsConfiguration(this.registryAccess());
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 653728709b275fee822e55a511e67ec11fdc48f7..daf8c44ec34fad2330d23e9f32c26ed67597bf0c 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -38,6 +38,8 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+
+import me.earthme.luminol.LuminolConfig;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.Util;
@@ -772,6 +774,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
}
// Folia end - region threading
+ public final LuminolConfig.LumionalWorldConfig lumionalWorldConfig; //Luminol
+
// Add env and gen to constructor, IWorldDataServer -> WorldDataServer
public ServerLevel(MinecraftServer minecraftserver, Executor executor, LevelStorageSource.LevelStorageAccess convertable_conversionsession, PrimaryLevelData iworlddataserver, ResourceKey<Level> resourcekey, LevelStem worlddimension, ChunkProgressListener worldloadlistener, boolean flag, long i, List<CustomSpawner> list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) {
// IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error
@@ -856,6 +860,12 @@ public class ServerLevel extends Level implements WorldGenLevel {
this.chunkTaskScheduler = new io.papermc.paper.chunk.system.scheduling.ChunkTaskScheduler(this, io.papermc.paper.chunk.system.scheduling.ChunkTaskScheduler.workerThreads); // Paper - rewrite chunk system
this.entityLookup = new io.papermc.paper.chunk.system.entity.EntityLookup(this, new EntityCallbacks()); // Paper - rewrite chunk system
this.updateTickData(); // Folia - region threading - make sure it is initialised before ticked
+ this.lumionalWorldConfig = new LuminolConfig.LumionalWorldConfig(this);
+ try {
+ this.lumionalWorldConfig.init();
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to create luminol config for level "+ this.getWorld().getName()+"!",e);
+ }
}
// Folia start - region threading