Skip to content

Commit

Permalink
Continue to split components - 3
Browse files Browse the repository at this point in the history
  • Loading branch information
404Setup committed Sep 7, 2024
1 parent 6f720f3 commit a5f961f
Show file tree
Hide file tree
Showing 101 changed files with 900 additions and 894 deletions.
274 changes: 274 additions & 0 deletions patches/server/0007-Vine-Config-Util.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 404Setup <[email protected]>
Date: Sun, 23 Jun 2024 21:01:06 +0800
Subject: [PATCH] Vine Config Util


diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
index a7ffbbfd2a9fdeae0953ec8753ce48e93ccce086..9e58bce64d46a1ac12bcc067a07883069a27e482 100644
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
@@ -121,6 +121,8 @@ public class Main {
JvmProfiler.INSTANCE.start(Environment.SERVER);
}

+ one.tranic.vine.config.ConfigUtil.load(); // Vine - load config
+
ShreddedPaperConfigurationLoader.init((File) optionset.valueOf("shreddedpaper-settings")); // ShreddedPaper

// Purpur start - load config files early
diff --git a/src/main/java/one/tranic/vine/config/package-info.java b/src/main/java/one/tranic/vine/config/package-info.java
new file mode 100644
index 0000000000000000000000000000000000000000..45f4c24cc689252513752e7b1cfa6736aa465f6b
--- /dev/null
+++ b/src/main/java/one/tranic/vine/config/package-info.java
@@ -0,0 +1,10 @@
+/**
+ * Vine Server configuration file package
+ * <p>
+ * If the public method needs to be called by Java, it needs to be annotated with @JvmStatic.
+ * If it is a field exposed to Java, it needs to be annotated with @JvmField.
+ * <p>
+ * If you need to modify this file, you'll need to modify the Vine Config commit using
+ * `git rebase -i HEAD~N` rather than patching it in a new patch.
+ * */
+package one.tranic.vine.config;
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/ConfigUtil.kt b/src/main/kotlin/one/tranic/vine/config/ConfigUtil.kt
new file mode 100644
index 0000000000000000000000000000000000000000..2f4afece99a273baf515d02a52a8ed7299f02e1a
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/ConfigUtil.kt
@@ -0,0 +1,74 @@
+package one.tranic.vine.config
+
+import com.aayushatharva.brotli4j.Brotli4jLoader
+import one.tranic.vine.region.Compression
+import one.tranic.vine.region.Format
+import one.tranic.vine.util.VineLogger
+import org.bukkit.configuration.file.YamlConfiguration
+import java.io.File
+
+object ConfigUtil {
+ private lateinit var configuration: YamlConfiguration
+
+ fun getConfiguration() : YamlConfiguration {
+ return configuration
+ }
+
+ @JvmStatic
+ fun reload() {
+ runCatching {
+ val configFile = File("vine.yml")
+ if (!configFile.exists()) {
+ configFile.createNewFile()
+ }
+ configuration = YamlConfiguration.loadConfiguration(configFile)
+ addDefault(configFile)
+ one.tranic.vine.config.module.Module.load()
+ }.getOrElse {
+ throw RuntimeException(it)
+ }
+ }
+
+ @JvmStatic
+ fun load() {
+ reload()
+ reload()
+ // If SECTORFILE is enabled and BROTLI is selected as the compression format,
+ // initialize the dependent libraries.
+ if (Format.equals(Format.SECTORFILE) && Compression.equals(Compression.BROTLI)) {
+ Brotli4jLoader.ensureAvailability()
+ VineLogger.warn(
+ listOf(
+ "****************************",
+ "Brotli in SectorFile currently faces poor performance issues,",
+ "it is recommended to choose ZSTD instead of Brotli",
+ "****************************"
+ )
+ )
+ }
+ VineLogger.warn(
+ listOf(
+ "******************************************",
+ "Since Vine is compatible with multiple region formats, it is not possible to automatically convert between them. ",
+ "Currently, it only supports conversion between ANVIL and SectorFile.",
+ "If you have relevant needs, please download the relevant tools to convert region formats.",
+ "******************************************"
+ )
+ )
+ }
+
+ private fun addDefault(configFile: File) {
+ configuration.options().setHeader(
+ listOf(
+ "Vine Abstract Configuration",
+ "Vine Github: https://github.com/LevelTranic/Vine",
+ "It is recommended to always keep the latest version, download it at https://tranic.one/downloads/vine"
+ )
+ )
+
+ one.tranic.vine.config.module.Module.default()
+
+ configuration.options().copyDefaults(true)
+ configuration.save(configFile)
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/impl/ConfigImpl.kt b/src/main/kotlin/one/tranic/vine/config/impl/ConfigImpl.kt
new file mode 100644
index 0000000000000000000000000000000000000000..173945a287f4d66ffc0373d0e0db9ba553bcce6e
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/impl/ConfigImpl.kt
@@ -0,0 +1,6 @@
+package one.tranic.vine.config.impl
+
+interface ConfigImpl {
+ fun default()
+ fun load()
+}
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/module/Locker.kt b/src/main/kotlin/one/tranic/vine/config/module/Locker.kt
new file mode 100644
index 0000000000000000000000000000000000000000..d336332ccdd0fb8d78da01004981fea5716fa29e
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/module/Locker.kt
@@ -0,0 +1,12 @@
+package one.tranic.vine.config.module
+
+import one.tranic.vine.region.Compression
+import one.tranic.vine.region.Format
+
+object Locker {
+ var compressionFormat: Compression? = null
+ var regionFormat: Format? = null
+ var regionCompressionLevel: Int? = null
+ var secureSeed: Boolean? = null
+ var virtualThread: Boolean? = null
+}
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/module/Module.kt b/src/main/kotlin/one/tranic/vine/config/module/Module.kt
new file mode 100644
index 0000000000000000000000000000000000000000..3ccd0ab0e830c91575702bc23d706b4f17e5f821
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/module/Module.kt
@@ -0,0 +1,34 @@
+package one.tranic.vine.config.module
+
+import one.tranic.vine.config.impl.ConfigImpl
+import one.tranic.vine.util.Reflect
+
+object Module : ConfigImpl {
+ private val clazz: ArrayList<ConfigImpl> = ArrayList()
+
+ private fun ArrayList<ConfigImpl>.addImpl(packageName: String) {
+ this.addAll(Reflect.findObjectClass(packageName))
+ }
+
+ init {
+ clazz.addImpl("one.tranic.vine.config.module.feature")
+ clazz.addImpl("one.tranic.vine.config.module.fix")
+ clazz.addImpl("one.tranic.vine.config.module.optimize")
+ clazz.addImpl("one.tranic.vine.config.module.optimize.entitygoal")
+ clazz.addImpl("one.tranic.vine.config.module.optimize.entitygoal.player")
+ clazz.addImpl("one.tranic.vine.config.module.optimize.entitygoal.mob")
+ clazz.addImpl("one.tranic.vine.config.module.optimize.entitygoal.mob.zombievillage")
+ }
+
+ override fun default() {
+ for (c in clazz) {
+ c.default()
+ }
+ }
+
+ override fun load() {
+ for (c in clazz) {
+ c.load()
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/one/tranic/vine/config/util/ConfigHelper.kt b/src/main/kotlin/one/tranic/vine/config/util/ConfigHelper.kt
new file mode 100644
index 0000000000000000000000000000000000000000..ba49e9075843cacf74b43da8da84dbbe0fc725c7
--- /dev/null
+++ b/src/main/kotlin/one/tranic/vine/config/util/ConfigHelper.kt
@@ -0,0 +1,77 @@
+package one.tranic.vine.config.util
+
+import one.tranic.vine.config.ConfigUtil
+
+open class ConfigHelper {
+ // Vine start - Configuration file tools
+ fun addDefault(path: String, value: Any) {
+ ConfigUtil.getConfiguration().addDefault(path, value)
+ }
+
+ fun addDefault(path: String, value: Any, comment: String) {
+ ConfigUtil.getConfiguration().addDefault(path, value)
+ ConfigUtil.getConfiguration().setComments(path, listOf(comment))
+ }
+
+ fun addComment(path: String, comment: String) {
+ ConfigUtil.getConfiguration().setComments(path, listOf(comment))
+ }
+
+ fun addComment(path: String, comment: List<String>) {
+ ConfigUtil.getConfiguration().setComments(path, comment)
+ }
+
+ fun addDefault(path: String, value: Any, comment: List<String>) {
+ ConfigUtil.getConfiguration().addDefault(path, value)
+ ConfigUtil.getConfiguration().setComments(path, comment)
+ }
+
+ fun getBoolean(path: String): Boolean {
+ return ConfigUtil.getConfiguration().getBoolean(path)
+ }
+
+ fun getBoolean(path: String, function: (it: Boolean) -> Unit) {
+ function(getBoolean(path))
+ }
+
+ fun getDouble(path: String): Double {
+ return ConfigUtil.getConfiguration().getDouble(path)
+ }
+
+ fun getDouble(path: String, function: (it: Double) -> Unit) {
+ function(getDouble(path))
+ }
+
+ fun getInt(path: String): Int {
+ return ConfigUtil.getConfiguration().getInt(path)
+ }
+
+ fun getInt(path: String, function: (it: Int) -> Unit) {
+ function(getInt(path))
+ }
+
+ fun getString(path: String): String? {
+ return ConfigUtil.getConfiguration().getString(path)
+ }
+
+ fun getString(path: String, function: (it: String?) -> Unit) {
+ function(getString(path))
+ }
+
+ fun getList(path: String): MutableList<*>? {
+ return ConfigUtil.getConfiguration().getList(path)
+ }
+
+ fun getStringList(path: String): MutableList<String> {
+ return ConfigUtil.getConfiguration().getStringList(path)
+ }
+
+ fun getStringList(path: String, function: (it: MutableList<String>) -> Unit) {
+ function(getStringList(path))
+ }
+
+ fun getMapList(path: String): MutableList<MutableMap<*, *>> {
+ return ConfigUtil.getConfiguration().getMapList(path)
+ }
+ // Vine end - Configuration file tools
+}
\ No newline at end of file
Loading

0 comments on commit a5f961f

Please sign in to comment.