diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java index 04e0a3ad..f987a3e6 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java @@ -33,7 +33,7 @@ import com.discordsrv.bukkit.scheduler.BukkitScheduler; import com.discordsrv.common.config.manager.ConnectionConfigManager; import com.discordsrv.common.config.manager.MainConfigManager; import com.discordsrv.common.logging.Logger; -import com.discordsrv.common.module.ModuleInitializationFunction; +import com.discordsrv.common.messageforwarding.game.MinecraftToDiscordChatModule; import com.discordsrv.common.server.ServerDiscordSRV; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Server; @@ -140,15 +140,8 @@ public class BukkitDiscordSRV extends ServerDiscordSRV {} - } diff --git a/common/proxy/src/main/java/com/discordsrv/proxy/ProxyDiscordSRV.java b/common/proxy/src/main/java/com/discordsrv/proxy/ProxyDiscordSRV.java index e3def1da..2d20b5a6 100644 --- a/common/proxy/src/main/java/com/discordsrv/proxy/ProxyDiscordSRV.java +++ b/common/proxy/src/main/java/com/discordsrv/proxy/ProxyDiscordSRV.java @@ -21,7 +21,6 @@ package com.discordsrv.proxy; import com.discordsrv.common.AbstractDiscordSRV; import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.main.MainConfig; -import com.discordsrv.common.module.ModuleInitializationFunction; import com.discordsrv.proxy.modules.ServerSwitchMessageModule; public abstract class ProxyDiscordSRV extends AbstractDiscordSRV { @@ -30,12 +29,6 @@ public abstract class ProxyDiscordSRV> {} - public final CompletableFuture invokeServerStarted() { return invokeLifecycle(this::serverStarted, "Failed to enable", true); } diff --git a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java index d5b48a91..34bf090f 100644 --- a/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java +++ b/common/src/main/java/com/discordsrv/common/AbstractDiscordSRV.java @@ -22,7 +22,6 @@ import com.discordsrv.api.discord.connection.DiscordConnectionDetails; import com.discordsrv.api.event.bus.EventBus; import com.discordsrv.api.event.events.lifecycle.DiscordSRVReloadEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent; -import com.discordsrv.common.discord.api.DiscordAPIEventModule; import com.discordsrv.common.api.util.ApiInstanceUtil; import com.discordsrv.common.channel.ChannelConfigHelper; import com.discordsrv.common.channel.ChannelUpdaterModule; @@ -32,23 +31,23 @@ import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.manager.ConnectionConfigManager; import com.discordsrv.common.config.manager.MainConfigManager; +import com.discordsrv.common.discord.api.DiscordAPIEventModule; import com.discordsrv.common.discord.api.DiscordAPIImpl; import com.discordsrv.common.discord.connection.DiscordConnectionManager; import com.discordsrv.common.discord.connection.jda.JDAConnectionManager; import com.discordsrv.common.discord.details.DiscordConnectionDetailsImpl; import com.discordsrv.common.event.bus.EventBusImpl; +import com.discordsrv.common.function.CheckedFunction; import com.discordsrv.common.function.CheckedRunnable; import com.discordsrv.common.integration.LuckPermsIntegration; -import com.discordsrv.common.logging.impl.DiscordSRVLogger; import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.adapter.DependencyLoggerAdapter; import com.discordsrv.common.logging.impl.DependencyLoggingHandler; +import com.discordsrv.common.logging.impl.DiscordSRVLogger; import com.discordsrv.common.messageforwarding.discord.DiscordChatMessageModule; import com.discordsrv.common.messageforwarding.discord.DiscordMessageMirroringModule; import com.discordsrv.common.messageforwarding.game.JoinMessageModule; import com.discordsrv.common.messageforwarding.game.LeaveMessageModule; -import com.discordsrv.common.messageforwarding.game.MinecraftToDiscordChatModule; -import com.discordsrv.common.module.ModuleInitializationFunction; import com.discordsrv.common.module.ModuleManager; import com.discordsrv.common.module.type.AbstractModule; import com.discordsrv.common.module.type.Module; @@ -187,6 +186,13 @@ public abstract class AbstractDiscordSRV void registerModule(CheckedFunction> function) { + try { + registerModule(function.apply((T) this)); + } catch (Throwable ignored) {} + } + @Override public void unregisterModule(AbstractModule module) { moduleManager.unregister(module); @@ -302,29 +308,17 @@ public abstract class AbstractDiscordSRV {} - @OverridingMethodsMustInvokeSuper protected void disable() { Status status = this.status.get(); diff --git a/common/src/main/java/com/discordsrv/common/channel/ChannelUpdaterModule.java b/common/src/main/java/com/discordsrv/common/channel/ChannelUpdaterModule.java index 91815da0..772d20f2 100644 --- a/common/src/main/java/com/discordsrv/common/channel/ChannelUpdaterModule.java +++ b/common/src/main/java/com/discordsrv/common/channel/ChannelUpdaterModule.java @@ -34,7 +34,7 @@ import java.util.Set; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -public class ChannelUpdaterModule extends AbstractModule { +public class ChannelUpdaterModule extends AbstractModule { private final Set> futures = new LinkedHashSet<>(); private boolean firstReload = true; diff --git a/common/src/main/java/com/discordsrv/common/channel/GlobalChannelLookupModule.java b/common/src/main/java/com/discordsrv/common/channel/GlobalChannelLookupModule.java index 988810de..463e77be 100644 --- a/common/src/main/java/com/discordsrv/common/channel/GlobalChannelLookupModule.java +++ b/common/src/main/java/com/discordsrv/common/channel/GlobalChannelLookupModule.java @@ -24,7 +24,7 @@ import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.module.type.AbstractModule; -public class GlobalChannelLookupModule extends AbstractModule { +public class GlobalChannelLookupModule extends AbstractModule { private final DefaultGlobalChannel defaultGlobalChannel; diff --git a/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIEventModule.java b/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIEventModule.java index 393e6ddd..7f49ebfd 100644 --- a/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIEventModule.java +++ b/common/src/main/java/com/discordsrv/common/discord/api/DiscordAPIEventModule.java @@ -30,7 +30,7 @@ import net.dv8tion.jda.api.events.message.MessageDeleteEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageUpdateEvent; -public class DiscordAPIEventModule extends AbstractModule { +public class DiscordAPIEventModule extends AbstractModule { public DiscordAPIEventModule(DiscordSRV discordSRV) { super(discordSRV); diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordChatMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordChatMessageModule.java index 11612a18..0acb4759 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordChatMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordChatMessageModule.java @@ -41,7 +41,7 @@ import net.kyori.adventure.text.Component; import java.util.Map; -public class DiscordChatMessageModule extends AbstractModule { +public class DiscordChatMessageModule extends AbstractModule { public DiscordChatMessageModule(DiscordSRV discordSRV) { super(discordSRV); diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordMessageMirroringModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordMessageMirroringModule.java index 15fa952a..9c735ccd 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordMessageMirroringModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/discord/DiscordMessageMirroringModule.java @@ -44,7 +44,7 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -public class DiscordMessageMirroringModule extends AbstractModule { +public class DiscordMessageMirroringModule extends AbstractModule { private final Cache> mapping; diff --git a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java index 7db9aa85..df8cc936 100644 --- a/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java +++ b/common/src/main/java/com/discordsrv/common/messageforwarding/game/AbstractGameMessageModule.java @@ -48,7 +48,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.CopyOnWriteArrayList; -public abstract class AbstractGameMessageModule extends AbstractModule { +public abstract class AbstractGameMessageModule extends AbstractModule { public AbstractGameMessageModule(DiscordSRV discordSRV) { super(discordSRV); diff --git a/common/src/main/java/com/discordsrv/common/module/ModuleInitializationFunction.java b/common/src/main/java/com/discordsrv/common/module/ModuleInitializationFunction.java deleted file mode 100644 index b991587d..00000000 --- a/common/src/main/java/com/discordsrv/common/module/ModuleInitializationFunction.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of DiscordSRV, licensed under the GPLv3 License - * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.discordsrv.common.module; - -import com.discordsrv.common.DiscordSRV; -import com.discordsrv.common.module.type.AbstractModule; - -@FunctionalInterface -public interface ModuleInitializationFunction
{ - - AbstractModule
initialize(DT discordSRV) throws Throwable; - -}