From 6c843f32be5853a416a15eeb7026d9abba44a635 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 17 Nov 2023 21:49:15 -0800 Subject: [PATCH] Update method of specifying modules for initialization, add permission service suggestions --- api | 2 +- impactor/build.gradle.kts | 12 +- .../core/commands/CommandsModule.java | 2 + .../core/modules/ModuleInitializer.java | 106 ++++++++++++++++ .../core/permissions/PermissionsModule.java | 68 ++++++++++ .../PermissionsRegistrationProvider.java | 81 ++++++++++++ .../SuggestPermissionServiceEventImpl.java | 60 +++++++++ .../core/plugin/BaseImpactorPlugin.java | 116 ++++-------------- .../impactdev/impactor/test/TestPlugin.java | 17 +-- integrations/vault/build.gradle.kts | 6 + .../impactor/fabric/FabricImpactorPlugin.java | 15 ++- .../impactor/forge/ForgeImpactorPlugin.java | 15 ++- .../forge/platform/ForgePlatformModule.java | 3 - .../minecraft/plugin/GameImpactorPlugin.java | 14 +-- 14 files changed, 380 insertions(+), 137 deletions(-) create mode 100644 impactor/src/main/java/net/impactdev/impactor/core/modules/ModuleInitializer.java create mode 100644 impactor/src/main/java/net/impactdev/impactor/core/permissions/PermissionsModule.java create mode 100644 impactor/src/main/java/net/impactdev/impactor/core/permissions/register/PermissionsRegistrationProvider.java create mode 100644 impactor/src/main/java/net/impactdev/impactor/core/permissions/register/SuggestPermissionServiceEventImpl.java diff --git a/api b/api index 952140c2..dc51423f 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit 952140c2cee5b0b257f540b1ad1628cc86a57f53 +Subproject commit dc51423f39f1b32769d61e4c6ae889c5406e44d5 diff --git a/impactor/build.gradle.kts b/impactor/build.gradle.kts index 19fa11ea..e14f0b50 100644 --- a/impactor/build.gradle.kts +++ b/impactor/build.gradle.kts @@ -24,13 +24,13 @@ dependencies { } // Databases - api("com.zaxxer:HikariCP:4.0.3") + api("com.zaxxer:HikariCP:5.0.1") api("com.h2database:h2:2.1.214") - api("mysql:mysql-connector-java:8.0.32") + api("mysql:mysql-connector-java:8.0.33") api("org.mariadb.jdbc:mariadb-java-client:3.1.2") - api("org.mongodb:mongo-java-driver:3.12.2") + api("org.mongodb:mongo-java-driver:3.12.12") - api("com.github.ben-manes.caffeine:caffeine:2.9.3") + api("com.github.ben-manes.caffeine:caffeine:3.1.5") implementation("io.github.classgraph:classgraph:4.8.157") implementation("net.luckperms:api:5.4") implementation("me.lucko:spark-api:0.1-SNAPSHOT") @@ -44,8 +44,8 @@ dependencies { testImplementation("net.kyori:adventure-text-serializer-ansi:4.14.0") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2") - testImplementation("org.mockito:mockito-core:4.7.0") - testRuntimeOnly("org.apache.logging.log4j:log4j-core:2.19.0") + testImplementation("org.mockito:mockito-core:5.2.0") + testRuntimeOnly("org.apache.logging.log4j:log4j-core:2.20.0") } tasks.withType(Test::class) { diff --git a/impactor/src/main/java/net/impactdev/impactor/core/commands/CommandsModule.java b/impactor/src/main/java/net/impactdev/impactor/core/commands/CommandsModule.java index dc52b524..ceefc796 100644 --- a/impactor/src/main/java/net/impactdev/impactor/core/commands/CommandsModule.java +++ b/impactor/src/main/java/net/impactdev/impactor/core/commands/CommandsModule.java @@ -31,6 +31,7 @@ import net.impactdev.impactor.core.commands.pagination.PaginationCommands; import net.impactdev.impactor.core.commands.translations.TranslationCommands; import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.platform.commands.PlatformCommands; import net.kyori.event.EventBus; public final class CommandsModule implements ImpactorModule { @@ -41,6 +42,7 @@ public void subscribe(EventBus bus) { event.register(EconomyCommands.class); event.register(PaginationCommands.class); event.register(TranslationCommands.class); + event.register(PlatformCommands.class); }); } } diff --git a/impactor/src/main/java/net/impactdev/impactor/core/modules/ModuleInitializer.java b/impactor/src/main/java/net/impactdev/impactor/core/modules/ModuleInitializer.java new file mode 100644 index 00000000..37086e2d --- /dev/null +++ b/impactor/src/main/java/net/impactdev/impactor/core/modules/ModuleInitializer.java @@ -0,0 +1,106 @@ +/* + * This file is part of Impactor, licensed under the MIT License (MIT). + * + * Copyright (c) 2018-2022 NickImpact + * + * 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 net.impactdev.impactor.core.modules; + +import io.github.classgraph.ClassGraph; +import io.github.classgraph.ClassInfoList; +import io.github.classgraph.ScanResult; +import net.impactdev.impactor.api.Impactor; +import net.impactdev.impactor.api.logging.PluginLogger; +import net.impactdev.impactor.api.utility.ExceptionPrinter; + +import java.util.LinkedList; +import java.util.Queue; + +public final class ModuleInitializer { + + public Queue> definitions = new LinkedList<>(); + public Queue modules = new LinkedList<>(); + + public ModuleInitializer with(Class module) { + this.definitions.add(module); + return this; + } + + public void construct(Impactor service) throws Exception { + while(!this.definitions.isEmpty()) { + Class type = this.definitions.poll(); + ImpactorModule module = type.getConstructor().newInstance(); + + module.factories(service.factories()); + module.builders(service.builders()); + module.services(service.services()); + module.subscribe(service.events()); + + this.modules.add(module); + } + } + + public void initialize(Impactor service, PluginLogger logger) throws Exception { + while(!this.modules.isEmpty()) { + ImpactorModule module = this.modules.poll(); + module.init(service, logger); + } + } + + /** + * For 1.16.5, this code works perfectly in a non-forge environment. However, with forge, there's + * a discrepancy with the TransformingClassLoader which prevents this tool from finding + * the class file assets. Per forums, this should be fixed with 1.17.1+ due to forge switching + * to the java module system. This code will be reactivated then, but for now, we are stuck with a + * manual solution. + *

+ * This problem affects sponge and forge only (SpongeForge, SpongeVanilla, Forge). + */ + private void initializeModules(Impactor service) { + ClassGraph graph = new ClassGraph() + .acceptPackages("net.impactdev.impactor") + .overrideClassLoaders(this.getClass().getClassLoader()); + + try (ScanResult scan = graph.scan()) { + ClassInfoList list = scan.getClassesImplementing(ImpactorModule.class); + //this.bootstrapper.logger().info("Scan complete, found " + list.size() + " modules, now loading..."); + list.stream() + .map(info -> info.loadClass(ImpactorModule.class)) + .map(type -> { + try { + return type.getConstructor().newInstance(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }) + .forEach(module -> { + module.factories(service.factories()); + module.builders(service.builders()); + module.services(service.services()); + }); + //this.bootstrapper.logger().info("Module loading complete!"); + } catch (Exception e) { + //ExceptionPrinter.print(this.logger(), e); + } + } +} diff --git a/impactor/src/main/java/net/impactdev/impactor/core/permissions/PermissionsModule.java b/impactor/src/main/java/net/impactdev/impactor/core/permissions/PermissionsModule.java new file mode 100644 index 00000000..cfd3d591 --- /dev/null +++ b/impactor/src/main/java/net/impactdev/impactor/core/permissions/PermissionsModule.java @@ -0,0 +1,68 @@ +/* + * This file is part of Impactor, licensed under the MIT License (MIT). + * + * Copyright (c) 2018-2022 NickImpact + * + * 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 net.impactdev.impactor.core.permissions; + +import net.impactdev.impactor.api.Impactor; +import net.impactdev.impactor.api.events.ImpactorEvent; +import net.impactdev.impactor.api.logging.PluginLogger; +import net.impactdev.impactor.api.platform.plugins.PluginMetadata; +import net.impactdev.impactor.api.services.permissions.PermissionsService; +import net.impactdev.impactor.api.services.permissions.SuggestPermissionServiceEvent; +import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.permissions.register.PermissionsRegistrationProvider; +import net.impactdev.impactor.core.permissions.register.SuggestPermissionServiceEventImpl; +import net.impactdev.impactor.core.plugin.BaseImpactorPlugin; +import net.kyori.event.EventBus; + +public final class PermissionsModule implements ImpactorModule { + + @Override + public void subscribe(EventBus bus) { + bus.subscribe(SuggestPermissionServiceEvent.class, event -> { + PluginMetadata metadata = BaseImpactorPlugin.instance().metadata(); + + event.suggest(metadata, ignore -> true, NoOpPermissionsService::new, 0); + event.suggest( + metadata, + info -> info.plugin("luckperms").isPresent(), + LuckPermsPermissionsService::new, + 10 + ); + }); + } + + @Override + public void init(Impactor impactor, PluginLogger logger) throws Exception { + logger.info("Calculating permissions service..."); + + SuggestPermissionServiceEventImpl event = new SuggestPermissionServiceEventImpl(); + impactor.events().post(event); + + PermissionsRegistrationProvider.PermissionServiceSuggestion suggestion = event.provider().suggestion(); + PermissionsService service = suggestion.supplier().get(); + logger.info("Permissions ยป Selected \"" + service.name() + "\" (Provider: " + suggestion.metadata().name().orElse(suggestion.metadata().id()) + ", Priority = " + suggestion.priority() + ")"); + } +} diff --git a/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/PermissionsRegistrationProvider.java b/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/PermissionsRegistrationProvider.java new file mode 100644 index 00000000..94145ed5 --- /dev/null +++ b/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/PermissionsRegistrationProvider.java @@ -0,0 +1,81 @@ +/* + * This file is part of Impactor, licensed under the MIT License (MIT). + * + * Copyright (c) 2018-2022 NickImpact + * + * 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 net.impactdev.impactor.core.permissions.register; + +import net.impactdev.impactor.api.platform.plugins.PluginMetadata; +import net.impactdev.impactor.api.services.permissions.PermissionsService; + +import java.util.Optional; +import java.util.function.Supplier; + +public final class PermissionsRegistrationProvider { + + private PermissionServiceSuggestion suggestion; + + public PermissionServiceSuggestion suggestion() { + return Optional.ofNullable(this.suggestion).orElseThrow(() -> new IllegalStateException("No suggestions available")); + } + + public void suggest(PluginMetadata metadata, int priority, Supplier supplier) { + if(this.suggestion == null || this.suggestion.priority() < priority) { + this.suggestion = this.createSuggestion(metadata, priority, supplier); + } + } + + private PermissionServiceSuggestion createSuggestion(PluginMetadata metadata, int priority, Supplier supplier) { + return new PermissionServiceSuggestion( + metadata, + priority, + supplier + ); + } + + public static final class PermissionServiceSuggestion { + + private final PluginMetadata metadata; + private final int priority; + private final Supplier supplier; + + private PermissionServiceSuggestion(PluginMetadata metadata, int priority, Supplier supplier) { + this.metadata = metadata; + this.priority = priority; + this.supplier = supplier; + } + + public PluginMetadata metadata() { + return this.metadata; + } + + public int priority() { + return this.priority; + } + + public Supplier supplier() { + return this.supplier; + } + } + +} diff --git a/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/SuggestPermissionServiceEventImpl.java b/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/SuggestPermissionServiceEventImpl.java new file mode 100644 index 00000000..7645cf40 --- /dev/null +++ b/impactor/src/main/java/net/impactdev/impactor/core/permissions/register/SuggestPermissionServiceEventImpl.java @@ -0,0 +1,60 @@ +/* + * This file is part of Impactor, licensed under the MIT License (MIT). + * + * Copyright (c) 2018-2022 NickImpact + * + * 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 net.impactdev.impactor.core.permissions.register; + +import net.impactdev.impactor.api.Impactor; +import net.impactdev.impactor.api.platform.PlatformInfo; +import net.impactdev.impactor.api.platform.plugins.PluginMetadata; +import net.impactdev.impactor.api.services.permissions.PermissionsService; +import net.impactdev.impactor.api.services.permissions.SuggestPermissionServiceEvent; +import net.impactdev.impactor.core.plugin.BaseImpactorPlugin; +import org.jetbrains.annotations.Range; + +import java.util.function.Predicate; +import java.util.function.Supplier; + +public final class SuggestPermissionServiceEventImpl implements SuggestPermissionServiceEvent { + + private final PermissionsRegistrationProvider provider = new PermissionsRegistrationProvider(); + + public PermissionsRegistrationProvider provider() { + return this.provider; + } + + @SuppressWarnings("ConstantValue") + @Override + public void suggest(PluginMetadata suggestor, Predicate filter, Supplier service, @Range(from = 0, to = Integer.MAX_VALUE) int priority) { + if(priority < 0) { + BaseImpactorPlugin.instance().logger().warn(suggestor.name() + " attempted to suggest their permissions service" + + "with a priority lower than 0 (" + priority + "), this suggestion has been ignored!"); + return; + } + + if(filter.test(Impactor.instance().platform().info())) { + this.provider.suggest(suggestor, priority, service); + } + } +} diff --git a/impactor/src/main/java/net/impactdev/impactor/core/plugin/BaseImpactorPlugin.java b/impactor/src/main/java/net/impactdev/impactor/core/plugin/BaseImpactorPlugin.java index 14c00841..62b35b4d 100644 --- a/impactor/src/main/java/net/impactdev/impactor/core/plugin/BaseImpactorPlugin.java +++ b/impactor/src/main/java/net/impactdev/impactor/core/plugin/BaseImpactorPlugin.java @@ -25,11 +25,6 @@ package net.impactdev.impactor.core.plugin; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import io.github.classgraph.ClassGraph; -import io.github.classgraph.ClassInfoList; -import io.github.classgraph.ScanResult; import net.impactdev.impactor.api.Impactor; import net.impactdev.impactor.api.scheduler.AbstractJavaScheduler; import net.impactdev.impactor.core.commands.CommandsModule; @@ -45,24 +40,21 @@ import net.impactdev.impactor.api.utility.ExceptionPrinter; import net.impactdev.impactor.core.api.APIRegister; import net.impactdev.impactor.core.api.ImpactorService; +import net.impactdev.impactor.core.modules.ModuleInitializer; import net.impactdev.impactor.core.permissions.LuckPermsPermissionsService; import net.impactdev.impactor.core.permissions.NoOpPermissionsService; import net.impactdev.impactor.core.economy.EconomyModule; -import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.permissions.PermissionsModule; import net.impactdev.impactor.core.text.TextModule; import net.impactdev.impactor.core.translations.TranslationsModule; import net.impactdev.impactor.core.utility.future.Futures; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import java.io.InputStream; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; public abstract class BaseImpactorPlugin implements ImpactorPlugin, Configurable { @@ -75,7 +67,8 @@ public abstract class BaseImpactorPlugin implements ImpactorPlugin, Configurable .version("@version@") .build(); - private final Set modules = Sets.newHashSet(); + @MonotonicNonNull + private ModuleInitializer initializer; public BaseImpactorPlugin(ImpactorBootstrapper bootstrapper) { instance = this; @@ -106,6 +99,16 @@ public ImpactorConfig configuration() { return null; } + protected ModuleInitializer registerModules() { + ModuleInitializer initializer = new ModuleInitializer(); + return initializer.with(ConfigModule.class) + .with(CommandsModule.class) + .with(EconomyModule.class) + .with(PermissionsModule.class) + .with(TextModule.class) + .with(TranslationsModule.class); + } + @Override public void construct() { this.bootstrapper.logger().info("Initializing API..."); @@ -113,39 +116,13 @@ public void construct() { APIRegister.register(service); this.bootstrapper.logger().info("Registering modules..."); - Set> modules = new LinkedHashSet<>(Lists.newArrayList( - ConfigModule.class, - CommandsModule.class, - EconomyModule.class, - TextModule.class, - TranslationsModule.class - )); - - modules.addAll(Optional.ofNullable(this.modules()).orElse(Collections.emptySet())); - Set collection = modules.stream().map(type -> { - try { - return type.getConstructor().newInstance(); - } catch (Exception e) { - throw new RuntimeException("Failed to load class module", e); - } - }).peek(module -> { - module.factories(service.factories()); - module.builders(service.builders()); - module.services(service.services()); - module.subscribe(service.events()); - }).collect(Collectors.toSet()); - - Platform platform = Impactor.instance().platform(); - if(platform.info().plugin("luckperms").isPresent()) { - this.logger().info("LuckPerms detected, initializing luckperms integration..."); - service.services().register(PermissionsService.class, new LuckPermsPermissionsService()); - } else { - this.logger().info("No particular permissions service located, all permissions are now allowed!"); - service.services().register(PermissionsService.class, new NoOpPermissionsService()); + this.initializer = this.registerModules(); + try { + this.initializer.construct(service); + } catch (Exception e) { + ExceptionPrinter.print(this.logger(), e); } - this.modules.addAll(collection); - this.logger().info("Registering commands..."); ImpactorCommandRegistry registry = new ImpactorCommandRegistry(); registry.registerArgumentParsers(); @@ -156,14 +133,11 @@ public void setup() { this.bootstrapper.logger().info("Initializing modules..."); Impactor service = Impactor.instance(); - this.modules.forEach(module -> { - try { - module.init(service, this.logger()); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }); + try { + this.initializer.initialize(service, this.logger()); + } catch (Exception e) { + ExceptionPrinter.print(this.logger(), e); + } } @Override @@ -188,46 +162,6 @@ public void shutdown() { this.logger().info("Scheduler shutdown successfully!"); } - protected abstract Set> modules(); - - /** - * For 1.16.5, this code works perfectly in a non-forge environment. However, with forge, there's - * a discrepancy with the TransformingClassLoader which prevents this tool from finding - * the class file assets. Per forums, this should be fixed with 1.17.1+ due to forge switching - * to the java module system. This code will be reactivated then, but for now, we are stuck with a - * manual solution. - *

- * This problem affects sponge and forge only (SpongeForge, SpongeVanilla, Forge). - */ - private void initializeModules(Impactor service) { - ClassGraph graph = new ClassGraph() - .acceptPackages("net.impactdev.impactor") - .overrideClassLoaders(this.getClass().getClassLoader()); - - try (ScanResult scan = graph.scan()) { - ClassInfoList list = scan.getClassesImplementing(ImpactorModule.class); - this.bootstrapper.logger().info("Scan complete, found " + list.size() + " modules, now loading..."); - list.stream() - .map(info -> info.loadClass(ImpactorModule.class)) - .map(type -> { - try { - return type.getConstructor().newInstance(); - } - catch (Exception e) { - throw new RuntimeException(e); - } - }) - .forEach(module -> { - module.factories(service.factories()); - module.builders(service.builders()); - module.services(service.services()); - }); - this.bootstrapper.logger().info("Module loading complete!"); - } catch (Exception e) { - ExceptionPrinter.print(this.logger(), e); - } - } - public InputStream resource(Function target) { Path path = target.apply(Paths.get("impactor").resolve("assets")); return Optional.ofNullable(this.getClass().getClassLoader().getResourceAsStream(path.toString().replace("\\", "/"))) diff --git a/impactor/src/test/java/net/impactdev/impactor/test/TestPlugin.java b/impactor/src/test/java/net/impactdev/impactor/test/TestPlugin.java index d342d74c..b95b9e2c 100644 --- a/impactor/src/test/java/net/impactdev/impactor/test/TestPlugin.java +++ b/impactor/src/test/java/net/impactdev/impactor/test/TestPlugin.java @@ -25,17 +25,13 @@ package net.impactdev.impactor.test; -import com.google.common.collect.Sets; -import net.impactdev.impactor.core.commands.ImpactorCommandRegistry; -import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.modules.ModuleInitializer; import net.impactdev.impactor.core.plugin.BaseImpactorPlugin; import net.impactdev.impactor.core.plugin.ImpactorBootstrapper; import net.impactdev.impactor.test.dummies.TestCommandsModule; import net.impactdev.impactor.test.dummies.TestPlatform; import net.impactdev.impactor.test.dummies.TestScheduler; -import java.util.Set; - public class TestPlugin extends BaseImpactorPlugin { public TestPlugin(ImpactorBootstrapper bootstrapper) { @@ -43,12 +39,11 @@ public TestPlugin(ImpactorBootstrapper bootstrapper) { } @Override - protected Set> modules() { - return Sets.newHashSet( - TestPlatform.TestPlatformModule.class, - TestScheduler.TestSchedulerModule.class, - TestCommandsModule.class - ); + protected ModuleInitializer registerModules() { + return super.registerModules() + .with(TestPlatform.TestPlatformModule.class) + .with(TestScheduler.TestSchedulerModule.class) + .with(TestCommandsModule.class); } } diff --git a/integrations/vault/build.gradle.kts b/integrations/vault/build.gradle.kts index bd561839..ee986722 100644 --- a/integrations/vault/build.gradle.kts +++ b/integrations/vault/build.gradle.kts @@ -13,4 +13,10 @@ dependencies { implementation(project(":api:config")) implementation(project(":api:economy")) +} + +tasks { + jar { + archiveClassifier.set("") + } } \ No newline at end of file diff --git a/launchers/fabric/src/main/java/net/impactdev/impactor/fabric/FabricImpactorPlugin.java b/launchers/fabric/src/main/java/net/impactdev/impactor/fabric/FabricImpactorPlugin.java index 735c378a..e7213216 100644 --- a/launchers/fabric/src/main/java/net/impactdev/impactor/fabric/FabricImpactorPlugin.java +++ b/launchers/fabric/src/main/java/net/impactdev/impactor/fabric/FabricImpactorPlugin.java @@ -30,6 +30,7 @@ import net.impactdev.impactor.api.platform.Platform; import net.impactdev.impactor.api.plugin.ImpactorPlugin; import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.modules.ModuleInitializer; import net.impactdev.impactor.core.plugin.ImpactorBootstrapper; import net.impactdev.impactor.fabric.commands.FabricCommandModule; import net.impactdev.impactor.fabric.integrations.PlaceholderAPIIntegration; @@ -58,13 +59,11 @@ public void construct() { } @Override - protected Set> modules() { - Set> parent = super.modules(); - parent.add(FabricSchedulerModule.class); - parent.add(FabricUIModule.class); - parent.add(FabricPlatformModule.class); - parent.add(FabricCommandModule.class); - - return parent; + protected ModuleInitializer registerModules() { + return super.registerModules() + .with(FabricSchedulerModule.class) + .with(FabricUIModule.class) + .with(FabricPlatformModule.class) + .with(FabricCommandModule.class); } } diff --git a/launchers/forge/src/main/java/net/impactdev/impactor/forge/ForgeImpactorPlugin.java b/launchers/forge/src/main/java/net/impactdev/impactor/forge/ForgeImpactorPlugin.java index 30abe4a8..31d68905 100644 --- a/launchers/forge/src/main/java/net/impactdev/impactor/forge/ForgeImpactorPlugin.java +++ b/launchers/forge/src/main/java/net/impactdev/impactor/forge/ForgeImpactorPlugin.java @@ -27,6 +27,7 @@ import net.impactdev.impactor.api.plugin.ImpactorPlugin; import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.modules.ModuleInitializer; import net.impactdev.impactor.core.plugin.ImpactorBootstrapper; import net.impactdev.impactor.forge.commands.ForgeCommandModule; import net.impactdev.impactor.forge.platform.ForgePlatformModule; @@ -48,14 +49,12 @@ public void construct() { } @Override - protected Set> modules() { - Set> parent = super.modules(); - parent.add(ForgeSchedulerModule.class); - parent.add(ForgeUIModule.class); - parent.add(ForgePlatformModule.class); - parent.add(ForgeCommandModule.class); - - return parent; + protected ModuleInitializer registerModules() { + return super.registerModules() + .with(ForgeSchedulerModule.class) + .with(ForgeUIModule.class) + .with(ForgePlatformModule.class) + .with(ForgeCommandModule.class); } } diff --git a/launchers/forge/src/main/java/net/impactdev/impactor/forge/platform/ForgePlatformModule.java b/launchers/forge/src/main/java/net/impactdev/impactor/forge/platform/ForgePlatformModule.java index 9e0b3879..c26ee782 100644 --- a/launchers/forge/src/main/java/net/impactdev/impactor/forge/platform/ForgePlatformModule.java +++ b/launchers/forge/src/main/java/net/impactdev/impactor/forge/platform/ForgePlatformModule.java @@ -34,14 +34,11 @@ import net.impactdev.impactor.api.platform.sources.metadata.MetadataKey; import net.impactdev.impactor.api.providers.FactoryProvider; import net.impactdev.impactor.api.providers.ServiceProvider; -import net.impactdev.impactor.core.commands.events.RegisterCommandsEvent; import net.impactdev.impactor.core.modules.ImpactorModule; -import net.impactdev.impactor.core.platform.commands.PlatformCommands; import net.impactdev.impactor.core.platform.sources.metadata.MetadataKeyFactory; import net.impactdev.impactor.forge.platform.performance.ForgePerformanceMonitorFactory; import net.impactdev.impactor.forge.platform.sources.ForgePlatformFactory; import net.impactdev.impactor.forge.platform.sources.ForgePlatformPlayerService; -import net.kyori.event.EventBus; @SuppressWarnings("unused") public class ForgePlatformModule implements ImpactorModule { diff --git a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/plugin/GameImpactorPlugin.java b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/plugin/GameImpactorPlugin.java index 9618741d..6fb31542 100644 --- a/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/plugin/GameImpactorPlugin.java +++ b/minecraft/impl/src/main/java/net/impactdev/impactor/minecraft/plugin/GameImpactorPlugin.java @@ -25,15 +25,12 @@ package net.impactdev.impactor.minecraft.plugin; -import com.google.common.collect.Sets; -import net.impactdev.impactor.core.modules.ImpactorModule; +import net.impactdev.impactor.core.modules.ModuleInitializer; import net.impactdev.impactor.core.plugin.BaseImpactorPlugin; import net.impactdev.impactor.core.plugin.ImpactorBootstrapper; import net.impactdev.impactor.minecraft.items.ItemsModule; import net.impactdev.impactor.minecraft.ui.UIModule; -import java.util.Set; - public abstract class GameImpactorPlugin extends BaseImpactorPlugin { public GameImpactorPlugin(ImpactorBootstrapper bootstrapper) { @@ -41,11 +38,10 @@ public GameImpactorPlugin(ImpactorBootstrapper bootstrapper) { } @Override - protected Set> modules() { - return Sets.newHashSet( - ItemsModule.class, - UIModule.class - ); + protected ModuleInitializer registerModules() { + return super.registerModules() + .with(ItemsModule.class) + .with(UIModule.class); } @Override