From f05a50204ad710ced0b1b78ec69c0b954f5e2986 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 25 Sep 2022 18:46:22 +0800 Subject: Fix forge api and default plugin publishing and fix #1055 --- .../me/shedaniel/rei/forge/PluginDetectorImpl.java | 47 +++++++++++++++------- .../java/me/shedaniel/rei/forge/REIPlugin.java | 1 + .../me/shedaniel/rei/forge/REIPluginClient.java | 34 ++++++++++++++++ .../me/shedaniel/rei/forge/REIPluginCommon.java | 34 ++++++++++++++++ .../rei/forge/REIPluginDedicatedServer.java | 34 ++++++++++++++++ .../me/shedaniel/rei/forge/REIPluginLoader.java | 1 + .../shedaniel/rei/forge/REIPluginLoaderClient.java | 34 ++++++++++++++++ .../shedaniel/rei/forge/REIPluginLoaderCommon.java | 34 ++++++++++++++++ .../rei/forge/REIPluginLoaderDedicatedServer.java | 34 ++++++++++++++++ 9 files changed, 239 insertions(+), 14 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java create mode 100644 forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java index 7c6092240..d4286ac02 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/PluginDetectorImpl.java @@ -38,6 +38,8 @@ import me.shedaniel.rei.plugin.common.runtime.DefaultRuntimePlugin; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.loading.FMLEnvironment; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.function.Supplier; @@ -45,7 +47,7 @@ import java.util.function.Supplier; public class PluginDetectorImpl implements PluginDetector { private static

> REIPluginProvider

wrapPlugin(List modId, REIPluginProvider

plugin) { return new REIPluginProvider

() { - String nameSuffix = " [" + String.join(", ", modId) + "]"; + final String nameSuffix = " [" + String.join(", ", modId) + "]"; @Override public Collection

provide() { @@ -64,13 +66,17 @@ public class PluginDetectorImpl implements PluginDetector { }; } - private static final Supplier>, List>>> loaderProvided = Suppliers.memoize(() -> { - List>, List>> list = new ArrayList<>(); - AnnotationUtils.>>scanAnnotation(REIPluginLoader.class, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { + private static final Supplier>, List>>> loaderProvided = + Suppliers.memoize(() -> getPluginsLoader(REIPluginLoader.class)); + + @NotNull + private static > List, List>> getPluginsLoader(Class annotation) { + List, List>> list = new ArrayList<>(); + AnnotationUtils.>scanAnnotation(annotation, REIPluginProvider.class::isAssignableFrom, (modId, provider, clazz) -> { list.add(new AbstractMap.SimpleEntry<>(provider.get(), modId)); }); return list; - }); + } @Override public void detectServerPlugins() { @@ -79,6 +85,11 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + AnnotationUtils.scanAnnotation(REIPluginDedicatedServer.class, REIServerPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + } for (Map.Entry>, List> entry : loaderProvided.get()) { REIPluginProvider> provider = entry.getKey(); Collection> objects = provider.provide(); @@ -89,6 +100,11 @@ public class PluginDetectorImpl implements PluginDetector { } } } + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderDedicatedServer.class)) { + ((PluginView) PluginManager.getServerInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } + } } @Override @@ -97,6 +113,12 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.>scanAnnotation(REIPlugin.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + AnnotationUtils.>scanAnnotation(REIPluginCommon.class, me.shedaniel.rei.api.common.plugins.REIPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); + for (Map.Entry>, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderCommon.class)) { + ((PluginView) PluginManager.getInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } } @OnlyIn(Dist.CLIENT) @@ -108,6 +130,9 @@ public class PluginDetectorImpl implements PluginDetector { AnnotationUtils.scanAnnotation(REIPlugin.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); }); + AnnotationUtils.scanAnnotation(REIPluginClient.class, REIClientPlugin.class::isAssignableFrom, (modId, plugin, clazz) -> { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(modId, plugin.get())); + }); for (Map.Entry>, List> entry : loaderProvided.get()) { REIPluginProvider> provider = entry.getKey(); Collection> objects = provider.provide(); @@ -117,15 +142,9 @@ public class PluginDetectorImpl implements PluginDetector { } } } -// ClientInternals.attachInstance((Supplier>) () -> { -// List modIds = new ArrayList<>(); -// for (REIPluginProvider plugin : PluginManager.getClientInstance().getPluginProviders()) { -// if (plugin instanceof JEIPluginDetector.JEIPluginProvider) { -// modIds.addAll(((JEIPluginDetector.JEIPluginProvider) plugin).modIds); -// } -// } -// return modIds; -// }, "jeiCompatMods"); + for (Map.Entry, List> entry : PluginDetectorImpl.getPluginsLoader(REIPluginLoaderClient.class)) { + ((PluginView) PluginManager.getClientInstance()).registerPlugin(wrapPlugin(entry.getValue(), entry.getKey())); + } }; } } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java index db15c8093..70593ad9a 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPlugin.java @@ -32,6 +32,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Deprecated(forRemoval = true) public @interface REIPlugin { Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java new file mode 100644 index 000000000..5584b5f7c --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginClient.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginClient { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java new file mode 100644 index 000000000..b07ee4e0b --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginCommon.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginCommon { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java new file mode 100644 index 000000000..38545d041 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginDedicatedServer.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginDedicatedServer { +} diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java index 2ef9410fb..133a17a63 100644 --- a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoader.java @@ -32,6 +32,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) +@Deprecated(forRemoval = true) public @interface REIPluginLoader { Dist[] value() default {Dist.CLIENT, Dist.DEDICATED_SERVER}; } diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java new file mode 100644 index 000000000..6824f511c --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderClient.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderClient { +} \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java new file mode 100644 index 000000000..7398e1d0d --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderCommon.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderCommon { +} \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java new file mode 100644 index 000000000..246b8c3cf --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/forge/REIPluginLoaderDedicatedServer.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.forge; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface REIPluginLoaderDedicatedServer { +} \ No newline at end of file -- cgit