From 65cd5573a2c3bd8104c2e6d76cba84b596cb6afa Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 12 Sep 2024 03:23:07 +0800 Subject: [PATCH] Fix: Annotated classes loading, fix floodgate-fabric mixin config plugin --- ...mpl.java => ModMixinConfigPluginImpl.java} | 2 +- .../mod/mixin/FloodgateUtilMixin.java | 2 +- .../org.geysermc.floodgate.core.util.AutoBind | 3 +++ .../neoforge/NeoForgeFloodgateMod.java | 21 --------------- .../mixin/NeoForgeFloodgateUtilMixin.java | 27 ------------------- .../resources/META-INF/neoforge.mods.toml | 4 +-- .../resources/floodgate_neoforge.mixins.json | 12 --------- 7 files changed, 6 insertions(+), 65 deletions(-) rename fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/{MixinConfigPluginImpl.java => ModMixinConfigPluginImpl.java} (89%) create mode 100644 mod/src/main/resources/org.geysermc.floodgate.core.util.AutoBind delete mode 100644 neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/mixin/NeoForgeFloodgateUtilMixin.java delete mode 100644 neoforge/src/main/resources/floodgate_neoforge.mixins.json diff --git a/fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/MixinConfigPluginImpl.java b/fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/ModMixinConfigPluginImpl.java similarity index 89% rename from fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/MixinConfigPluginImpl.java rename to fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/ModMixinConfigPluginImpl.java index bf8f6d2..ffd3fe3 100644 --- a/fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/MixinConfigPluginImpl.java +++ b/fabric/src/main/java/org/geysermc/floodgate/mod/util/fabric/ModMixinConfigPluginImpl.java @@ -2,7 +2,7 @@ import net.fabricmc.loader.api.FabricLoader; -public class MixinConfigPluginImpl { +public class ModMixinConfigPluginImpl { public static boolean isGeyserLoaded() { return FabricLoader.getInstance().isModLoaded("geyser-fabric"); diff --git a/mod/src/main/java/org/geysermc/floodgate/mod/mixin/FloodgateUtilMixin.java b/mod/src/main/java/org/geysermc/floodgate/mod/mixin/FloodgateUtilMixin.java index e654b7c..d251182 100644 --- a/mod/src/main/java/org/geysermc/floodgate/mod/mixin/FloodgateUtilMixin.java +++ b/mod/src/main/java/org/geysermc/floodgate/mod/mixin/FloodgateUtilMixin.java @@ -37,7 +37,7 @@ public class FloodgateUtilMixin { Path path = FloodgateMod.INSTANCE.resourcePath(string); if (path == null) { - throw new IllegalStateException("Unable to find annotation class! " + string); + throw new IllegalStateException("Unable to find classes marked by annotation class! " + string); } try { diff --git a/mod/src/main/resources/org.geysermc.floodgate.core.util.AutoBind b/mod/src/main/resources/org.geysermc.floodgate.core.util.AutoBind new file mode 100644 index 0000000..7d85275 --- /dev/null +++ b/mod/src/main/resources/org.geysermc.floodgate.core.util.AutoBind @@ -0,0 +1,3 @@ +org.geysermc.floodgate.core.util.Metrics +org.geysermc.floodgate.core.news.NewsChecker +org.geysermc.floodgate.core.util.PostEnableMessages diff --git a/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/NeoForgeFloodgateMod.java b/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/NeoForgeFloodgateMod.java index e3d09d5..9268bbd 100644 --- a/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/NeoForgeFloodgateMod.java +++ b/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/NeoForgeFloodgateMod.java @@ -11,7 +11,6 @@ import net.neoforged.neoforge.event.server.ServerStoppingEvent; import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import org.checkerframework.checker.nullness.qual.Nullable; -import org.geysermc.floodgate.api.logger.FloodgateLogger; import org.geysermc.floodgate.core.module.PluginMessageModule; import org.geysermc.floodgate.core.module.ServerCommonModule; import org.geysermc.floodgate.mod.FloodgateMod; @@ -20,11 +19,7 @@ import org.geysermc.floodgate.platform.neoforge.module.NeoForgePlatformModule; import org.geysermc.floodgate.platform.neoforge.pluginmessage.NeoForgePluginMessageRegistration; -import java.lang.annotation.Annotation; -import java.lang.annotation.ElementType; import java.nio.file.Path; -import java.util.Set; -import java.util.stream.Collectors; @Mod("floodgate") public final class NeoForgeFloodgateMod extends FloodgateMod { @@ -82,20 +77,4 @@ public boolean isClient() { return FMLLoader.getDist().isClient(); } - public Set> getAnnotatedClasses(Class annotationClass) { - return container.getModInfo() - .getOwningFile() - .getFile() - .getScanResult() - .getAnnotatedBy(annotationClass, ElementType.TYPE) - .map(annotationData -> { - try { - return Class.forName(annotationData.clazz().getClassName()); - } catch (Exception e) { - injector.getInstance(FloodgateLogger.class).error(e.getMessage(), e); - return null; - } - }) - .collect(Collectors.toSet()); - } } diff --git a/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/mixin/NeoForgeFloodgateUtilMixin.java b/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/mixin/NeoForgeFloodgateUtilMixin.java deleted file mode 100644 index cee3218..0000000 --- a/neoforge/src/main/java/org/geysermc/floodgate/platform/neoforge/mixin/NeoForgeFloodgateUtilMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.geysermc.floodgate.platform.neoforge.mixin; - -import org.geysermc.floodgate.core.util.Utils; -import org.geysermc.floodgate.mod.FloodgateMod; -import org.geysermc.floodgate.platform.neoforge.NeoForgeFloodgateMod; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -import java.lang.annotation.Annotation; -import java.util.Set; - -/** - * Mixin into Floodgate's {@link Utils} class as NeoForge is really picky about how it allows scanning - * mod-owned classes. - */ -@Mixin(value = Utils.class, remap = false) -public class NeoForgeFloodgateUtilMixin { - - /** - * @author geysermc - * @reason NeoForge is really picky about how it allows scanning mod-owned classes. - */ - @Overwrite(remap = false) - public static Set> getGeneratedClassesForAnnotation(Class annotationClass) { - return ((NeoForgeFloodgateMod) FloodgateMod.INSTANCE).getAnnotatedClasses(annotationClass); - } -} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index 04901ca..7d7373f 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -11,8 +11,6 @@ authors="$author" description="$description" [[mixins]] config = "floodgate.mixins.json" -[[mixins]] -config = "floodgate_neoforge.mixins.json" [[dependencies.floodgate]] modId="neoforge" type="required" @@ -24,4 +22,4 @@ modId="minecraft" type="required" versionRange="[$minecraft_version,)" ordering="NONE" -side="BOTH" \ No newline at end of file +side="BOTH" diff --git a/neoforge/src/main/resources/floodgate_neoforge.mixins.json b/neoforge/src/main/resources/floodgate_neoforge.mixins.json deleted file mode 100644 index 9c06f8d..0000000 --- a/neoforge/src/main/resources/floodgate_neoforge.mixins.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "org.geysermc.floodgate.platform.neoforge.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "NeoForgeFloodgateUtilMixin" - ], - "injectors": { - "defaultRequire": 1 - } -}