Skip to content

Commit

Permalink
Move config annotations (#178)
Browse files Browse the repository at this point in the history
* Move config annotations & Add @experimental

* Requested changes
  • Loading branch information
HaHaWTH authored Dec 2, 2024
1 parent 9e2e128 commit 6baa110
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 35 deletions.
111 changes: 80 additions & 31 deletions patches/server/0003-Leaf-Config.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add per world config
Add config reload

diff --git a/build.gradle.kts b/build.gradle.kts
index 4426855192b7dcc58b16d41b8a9d44bbbed3b55f..78d29b5e5047f9f03d1b8e93047953e727611c5e 100644
index c3790a8ebeeaaa395449e30ab69f1abfa9637034..a56ff254fb752030600fdf1d4ce62ff7ec14765d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -14,6 +14,13 @@ val alsoShade: Configuration by configurations.creating
Expand Down Expand Up @@ -56,14 +56,21 @@ index 4efbd656c57672b84c5d90f987bd57c67fc0c550..05f805c7e7a6ff6d40b9f86aaac5362a
long tickSection = Util.getNanos();
diff --git a/src/main/java/org/dreeam/leaf/config/ConfigModules.java b/src/main/java/org/dreeam/leaf/config/ConfigModules.java
new file mode 100644
index 0000000000000000000000000000000000000000..f05e1ee109a36c39857f75c296f2ff21800aba8e
index 0000000000000000000000000000000000000000..475da1247655dd07ab59273ab5794b04b20e05ed
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/ConfigModules.java
@@ -0,0 +1,26 @@
@@ -0,0 +1,57 @@
+package org.dreeam.leaf.config;
+
+import org.dreeam.leaf.config.annotations.Experimental;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public abstract class ConfigModules extends LeafConfig {
Expand All @@ -76,29 +83,39 @@ index 0000000000000000000000000000000000000000..f05e1ee109a36c39857f75c296f2ff21
+ }
+
+ public static void initModules() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
+ List<Class<?>> enabledExperimentalModules = new ArrayList<>();
+ for (Class<?> clazz : LeafConfig.getClasses(LeafConfig.I_CONFIG_PKG)) {
+ ConfigModules module = (ConfigModules) clazz.getConstructor().newInstance();
+ module.onLoaded();
+
+ modules.add(module);
+ for (Field field : getAnnotatedStaticFields(clazz, Experimental.class)) {
+ Object obj = field.get(null);
+ if (!(obj instanceof Boolean)) continue;
+ boolean enabled = (Boolean) obj;
+ if (enabled) {
+ enabledExperimentalModules.add(clazz);
+ break;
+ }
+ }
+ }
+ if (!enabledExperimentalModules.isEmpty()) {
+ LeafConfig.LOGGER.warn("You have following experimental module(s) enabled: {}, please report any bugs you found!", enabledExperimentalModules.stream().map(Class::getSimpleName).toList());
+ }
+ }
+
+ public abstract void onLoaded();
+}
diff --git a/src/main/java/org/dreeam/leaf/config/DoNotLoad.java b/src/main/java/org/dreeam/leaf/config/DoNotLoad.java
new file mode 100644
index 0000000000000000000000000000000000000000..42ce82d388336906a91547b81f6f70766f2b10f0
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/DoNotLoad.java
@@ -0,0 +1,8 @@
+package org.dreeam.leaf.config;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+ private static List<Field> getAnnotatedStaticFields(Class<?> clazz, Class<? extends Annotation> annotation) {
+ List<Field> fields = new ArrayList<>();
+ for (Field field : clazz.getDeclaredFields()) {
+ if (field.isAnnotationPresent(annotation) && Modifier.isStatic(field.getModifiers())) {
+ field.setAccessible(true);
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DoNotLoad {
+ public abstract void onLoaded();
+}
diff --git a/src/main/java/org/dreeam/leaf/config/EnumConfigCategory.java b/src/main/java/org/dreeam/leaf/config/EnumConfigCategory.java
new file mode 100644
Expand Down Expand Up @@ -132,20 +149,6 @@ index 0000000000000000000000000000000000000000..7d99f0711c6b4f298dd296c26c11dd9d
+ return VALUES;
+ }
+}
diff --git a/src/main/java/org/dreeam/leaf/config/HotReloadUnsupported.java b/src/main/java/org/dreeam/leaf/config/HotReloadUnsupported.java
new file mode 100644
index 0000000000000000000000000000000000000000..f7ab1ff5f298ff1e5e16fe5396d1e9e62a55fdfb
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/HotReloadUnsupported.java
@@ -0,0 +1,8 @@
+package org.dreeam.leaf.config;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HotReloadUnsupported {
+}
diff --git a/src/main/java/org/dreeam/leaf/config/LeafConfig.java b/src/main/java/org/dreeam/leaf/config/LeafConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..fdbdf3f6a5071ce629d2881e861075dbeef11b42
Expand Down Expand Up @@ -564,3 +567,49 @@ index 0000000000000000000000000000000000000000..794bc822d987ee2bb69b953ea70ae3ee
+ return isCN ? cn : en;
+ }
+}
diff --git a/src/main/java/org/dreeam/leaf/config/annotations/DoNotLoad.java b/src/main/java/org/dreeam/leaf/config/annotations/DoNotLoad.java
new file mode 100644
index 0000000000000000000000000000000000000000..b6687584b7bd914ae53f97df592d7a309a7e1d51
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/annotations/DoNotLoad.java
@@ -0,0 +1,8 @@
+package org.dreeam.leaf.config.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DoNotLoad {
+}
diff --git a/src/main/java/org/dreeam/leaf/config/annotations/Experimental.java b/src/main/java/org/dreeam/leaf/config/annotations/Experimental.java
new file mode 100644
index 0000000000000000000000000000000000000000..26a6967ca8917bbabb31804a44326a1091b9cb96
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/annotations/Experimental.java
@@ -0,0 +1,12 @@
+package org.dreeam.leaf.config.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Indicates that a feature is experimental and may be removed or changed in the future.
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target(value = {ElementType.FIELD})
+public @interface Experimental {
+}
diff --git a/src/main/java/org/dreeam/leaf/config/annotations/HotReloadUnsupported.java b/src/main/java/org/dreeam/leaf/config/annotations/HotReloadUnsupported.java
new file mode 100644
index 0000000000000000000000000000000000000000..c89bf6a7ec4bdd94a9ee69eb3907e8e899e6d69b
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/annotations/HotReloadUnsupported.java
@@ -0,0 +1,8 @@
+package org.dreeam.leaf.config.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HotReloadUnsupported {
+}
4 changes: 2 additions & 2 deletions patches/server/0049-Linear-region-file-format.patch
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,16 @@ index 54f7aa95cfbcf39bb86ad1b4eb0f9ff2f8526030..7c4b81e97562bb158478c70dae082526
} catch (final IOException ex) {
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/RegionFormatConfig.java b/src/main/java/org/dreeam/leaf/config/modules/misc/RegionFormatConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..7f95e17544b762ad4674315e53fcff8e80105cb8
index 0000000000000000000000000000000000000000..d94f8dd4a8682125ea356d36632e2b68e73d8af3
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/RegionFormatConfig.java
@@ -0,0 +1,62 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import com.mojang.logging.LogUtils;
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.DoNotLoad;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.annotations.DoNotLoad;
+import org.slf4j.Logger;
+import org.stupidcraft.linearpaper.region.EnumRegionFileExtension;
+
Expand Down
6 changes: 4 additions & 2 deletions patches/server/0152-Smooth-teleport-config.patch
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,23 @@ index f3b98a4a66cec8d6c9dc46479d573c2fb453837a..00b9d244898ffdc1584eb25464355777
entityplayer1.connection.send(new ClientboundSetExperiencePacket(entityplayer1.experienceProgress, entityplayer1.totalExperience, entityplayer1.experienceLevel));
diff --git a/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java b/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java
new file mode 100644
index 0000000000000000000000000000000000000000..5fd8923efb2f8369d990767d40d75c004ceb7a1b
index 0000000000000000000000000000000000000000..afed2f9210a1016afd5b7db0a3541ecc8c712d32
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/gameplay/SmoothTeleport.java
@@ -0,0 +1,27 @@
@@ -0,0 +1,29 @@
+package org.dreeam.leaf.config.modules.gameplay;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.annotations.Experimental;
+
+public class SmoothTeleport extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.GAMEPLAY.getBaseKeyName() + ".smooth-teleport";
+ }
+
+ @Experimental
+ public static boolean enabled = false;
+
+ @Override
Expand Down

0 comments on commit 6baa110

Please sign in to comment.