mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-01 08:39:31 +01:00
Change integration registering to a safer method
This commit is contained in:
parent
9124c18d7a
commit
1f6cefebac
@ -25,7 +25,6 @@ import com.discordsrv.bukkit.config.main.BukkitConfig;
|
||||
import com.discordsrv.bukkit.config.manager.BukkitConfigManager;
|
||||
import com.discordsrv.bukkit.config.manager.BukkitConnectionConfigManager;
|
||||
import com.discordsrv.bukkit.console.BukkitConsole;
|
||||
import com.discordsrv.bukkit.integration.VaultIntegration;
|
||||
import com.discordsrv.bukkit.listener.BukkitChatListener;
|
||||
import com.discordsrv.bukkit.listener.BukkitConnectionListener;
|
||||
import com.discordsrv.bukkit.listener.BukkitDeathListener;
|
||||
@ -188,9 +187,11 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
||||
server().getPluginManager().registerEvents(new BukkitStatusMessageListener(this), plugin());
|
||||
|
||||
// Modules
|
||||
registerModule(VaultIntegration::new);
|
||||
registerModule(MinecraftToDiscordChatModule::new);
|
||||
|
||||
// Integrations
|
||||
registerIntegration("com.discordsrv.bukkit.integration.VaultIntegration");
|
||||
|
||||
super.enable();
|
||||
}
|
||||
|
||||
|
@ -69,13 +69,16 @@ import com.discordsrv.common.storage.Storage;
|
||||
import com.discordsrv.common.storage.StorageType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import okhttp3.*;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.OverridingMethodsMustInvokeSuper;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
@ -306,10 +309,27 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T extends DiscordSRV> void registerModule(CheckedFunction<T, AbstractModule<?>> function) {
|
||||
protected final <T extends DiscordSRV> void registerModule(CheckedFunction<T, AbstractModule<?>> function) {
|
||||
moduleManager.registerModule((T) this, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param className a class which has a constructor with {@link DiscordSRV} (or implementation specific) as the only parameter.
|
||||
*/
|
||||
protected final void registerIntegration(
|
||||
@Language(value = "JAVA", prefix = "class X{static{Class.forName(\"", suffix = "\");}}") String className
|
||||
) {
|
||||
Object module;
|
||||
try {
|
||||
Class<?> clazz = Class.forName(className);
|
||||
Constructor<?> constructor = clazz.getConstructor(getClass());
|
||||
module = constructor.newInstance(this);
|
||||
} catch (Throwable ignored) {
|
||||
return;
|
||||
}
|
||||
moduleManager.registerModule(this, d -> (AbstractModule<?>) module);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterModule(AbstractModule<?> module) {
|
||||
moduleManager.unregister(module);
|
||||
@ -440,6 +460,9 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
registerModule(LeaveMessageModule::new);
|
||||
registerModule(DiscordInviteModule::new);
|
||||
|
||||
// Integrations
|
||||
registerIntegration("com.discordsrv.common.integration.LuckPermsIntegration");
|
||||
|
||||
// Initial load
|
||||
try {
|
||||
invokeReload(ReloadFlag.ALL, true).get();
|
||||
|
Loading…
Reference in New Issue
Block a user