mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-02 23:32:37 +01:00
Implement ApplicationDependencyManager
This commit is contained in:
parent
e82f03cd21
commit
4a492a7392
@ -1,5 +1,17 @@
|
||||
import dev.vankka.dependencydownload.task.GenerateDependencyDownloadResourceTask
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'bukkit.jarinjar'
|
||||
|
||||
[
|
||||
'net.kyori',
|
||||
'me.lucko.commodore'
|
||||
].each {
|
||||
relocate it, 'com.discordsrv.dependencies.' + it
|
||||
}
|
||||
// More relocations in buildscript/relocations.gradle
|
||||
}
|
||||
|
||||
apply from: rootProject.file('buildscript/runtime.gradle')
|
||||
|
||||
configurations {
|
||||
@ -13,18 +25,6 @@ task generateResourceForCommodore(type: GenerateDependencyDownloadResourceTask)
|
||||
file = 'dependencies/' + conf.name + '.txt'
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'bukkit.jarinjar'
|
||||
|
||||
[
|
||||
'net.kyori',
|
||||
'me.lucko.commodore'
|
||||
].each {
|
||||
relocate it, 'com.discordsrv.dependencies.' + it
|
||||
}
|
||||
// More relocations in buildscript/relocations.gradle
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
exclusiveContent {
|
||||
|
@ -37,12 +37,10 @@ import com.discordsrv.common.component.translation.Translation;
|
||||
import com.discordsrv.common.config.manager.ConnectionConfigManager;
|
||||
import com.discordsrv.common.config.manager.MainConfigManager;
|
||||
import com.discordsrv.common.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.messageforwarding.game.MinecraftToDiscordChatModule;
|
||||
import com.discordsrv.common.plugin.PluginManager;
|
||||
import com.discordsrv.common.server.ServerDiscordSRV;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
@ -52,19 +50,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConnectionConfig> {
|
||||
public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap, BukkitConfig, BukkitConnectionConfig> {
|
||||
|
||||
private final DiscordSRVBukkitBootstrap bootstrap;
|
||||
private BukkitAudiences audiences;
|
||||
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final BukkitScheduler scheduler;
|
||||
private final BukkitConsole console;
|
||||
private final BukkitPlayerProvider playerProvider;
|
||||
@ -74,11 +68,9 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
||||
private final BukkitConnectionConfigManager connectionConfigManager;
|
||||
private final BukkitConfigManager configManager;
|
||||
|
||||
public BukkitDiscordSRV(DiscordSRVBukkitBootstrap bootstrap, Logger logger) {
|
||||
this.bootstrap = bootstrap;
|
||||
this.logger = logger;
|
||||
public BukkitDiscordSRV(DiscordSRVBukkitBootstrap bootstrap) {
|
||||
super(bootstrap);
|
||||
|
||||
this.dataDirectory = bootstrap.getPlugin().getDataFolder().toPath();
|
||||
this.scheduler = new BukkitScheduler(this);
|
||||
this.console = new BukkitConsole(this);
|
||||
this.playerProvider = new BukkitPlayerProvider(this);
|
||||
@ -103,16 +95,6 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
||||
return audiences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitScheduler scheduler() {
|
||||
return scheduler;
|
||||
@ -157,11 +139,6 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
|
||||
return OnlineMode.of(server().getOnlineMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return bootstrap.getClasspathAppender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return commandHandler;
|
||||
|
@ -18,28 +18,31 @@
|
||||
|
||||
package com.discordsrv.bukkit;
|
||||
|
||||
import com.discordsrv.common.dependency.InitialDependencyLoader;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader;
|
||||
import dev.vankka.mcdependencydownload.bukkit.bootstrap.BukkitBootstrap;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiscordSRVBukkitBootstrap extends BukkitBootstrap {
|
||||
public class DiscordSRVBukkitBootstrap extends BukkitBootstrap implements IBootstrap {
|
||||
|
||||
private final Logger logger;
|
||||
private final InitialDependencyLoader dependencies;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
private BukkitDiscordSRV discordSRV;
|
||||
|
||||
public DiscordSRVBukkitBootstrap(JarInJarClassLoader classLoader, JavaPlugin plugin) throws IOException {
|
||||
// Don't change these parameters
|
||||
super(classLoader, plugin);
|
||||
this.logger = new JavaLoggerImpl(plugin.getLogger());
|
||||
this.dependencies = new InitialDependencyLoader(
|
||||
this.lifecycleManager = new LifecycleManager(
|
||||
logger,
|
||||
plugin.getDataFolder().toPath(),
|
||||
getDependencyResources(),
|
||||
@ -63,12 +66,32 @@ public class DiscordSRVBukkitBootstrap extends BukkitBootstrap {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
dependencies.loadAndEnable(() -> this.discordSRV = new BukkitDiscordSRV(this, logger));
|
||||
lifecycleManager.loadAndEnable(() -> this.discordSRV = new BukkitDiscordSRV(this));
|
||||
getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> discordSRV.invokeServerStarted(), 1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
dependencies.disable(discordSRV);
|
||||
lifecycleManager.disable(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return getClasspathAppender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return lifecycleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return getPlugin().getDataFolder().toPath();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
apply from: rootProject.file('buildscript/runtime.gradle')
|
||||
|
||||
shadowJar {
|
||||
archiveFileName = 'bungee.jarinjar'
|
||||
|
||||
@ -11,6 +9,8 @@ shadowJar {
|
||||
// More relocations in buildscript/relocations.gradle
|
||||
}
|
||||
|
||||
apply from: rootProject.file('buildscript/runtime.gradle')
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
exclusiveContent {
|
||||
|
@ -28,36 +28,27 @@ 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.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.plugin.PluginManager;
|
||||
import com.discordsrv.common.scheduler.StandardScheduler;
|
||||
import com.discordsrv.proxy.ProxyDiscordSRV;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.Path;
|
||||
public class BungeeDiscordSRV extends ProxyDiscordSRV<DiscordSRVBungeeBootstrap, MainConfig, ConnectionConfig> {
|
||||
|
||||
public class BungeeDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConfig> {
|
||||
|
||||
private final DiscordSRVBungeeBootstrap bootstrap;
|
||||
private BungeeAudiences audiences;
|
||||
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final StandardScheduler scheduler;
|
||||
private final BungeeConsole console;
|
||||
private final BungeePlayerProvider playerProvider;
|
||||
private final BungeePluginManager pluginManager;
|
||||
private BungeeCommandHandler commandHandler;
|
||||
|
||||
public BungeeDiscordSRV(DiscordSRVBungeeBootstrap bootstrap, Logger logger) {
|
||||
this.bootstrap = bootstrap;
|
||||
this.logger = logger;
|
||||
public BungeeDiscordSRV(DiscordSRVBungeeBootstrap bootstrap) {
|
||||
super(bootstrap);
|
||||
|
||||
this.dataDirectory = bootstrap.getPlugin().getDataFolder().toPath();
|
||||
this.scheduler = new StandardScheduler(this);
|
||||
this.console = new BungeeConsole(this);
|
||||
this.playerProvider = new BungeePlayerProvider(this);
|
||||
@ -78,16 +69,6 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConf
|
||||
return audiences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StandardScheduler scheduler() {
|
||||
return scheduler;
|
||||
@ -113,11 +94,6 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConf
|
||||
return OnlineMode.of(proxy().getConfig().isOnlineMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return bootstrap.getClasspathAppender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return commandHandler;
|
||||
|
@ -18,26 +18,29 @@
|
||||
|
||||
package com.discordsrv.bungee;
|
||||
|
||||
import com.discordsrv.common.dependency.InitialDependencyLoader;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader;
|
||||
import dev.vankka.mcdependencydownload.bungee.bootstrap.BungeeBootstrap;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DiscordSRVBungeeBootstrap extends BungeeBootstrap {
|
||||
public class DiscordSRVBungeeBootstrap extends BungeeBootstrap implements IBootstrap {
|
||||
|
||||
private final Logger logger;
|
||||
private final InitialDependencyLoader dependencies;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
private BungeeDiscordSRV discordSRV;
|
||||
|
||||
public DiscordSRVBungeeBootstrap(JarInJarClassLoader classLoader, Plugin plugin) throws IOException {
|
||||
// Don't change these parameters
|
||||
super(classLoader, plugin);
|
||||
this.logger = new JavaLoggerImpl(plugin.getLogger());
|
||||
this.dependencies = new InitialDependencyLoader(
|
||||
this.lifecycleManager = new LifecycleManager(
|
||||
logger,
|
||||
plugin.getDataFolder().toPath(),
|
||||
new String[] {"dependencies/runtimeDownload-bungee.txt"},
|
||||
@ -47,11 +50,31 @@ public class DiscordSRVBungeeBootstrap extends BungeeBootstrap {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
dependencies.loadAndEnable(() -> this.discordSRV = new BungeeDiscordSRV(this, logger));
|
||||
lifecycleManager.loadAndEnable(() -> this.discordSRV = new BungeeDiscordSRV(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
dependencies.disable(discordSRV);
|
||||
lifecycleManager.disable(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return getClasspathAppender();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return lifecycleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return getPlugin().getDataFolder().toPath();
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,16 @@
|
||||
package com.discordsrv.proxy;
|
||||
|
||||
import com.discordsrv.common.AbstractDiscordSRV;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.config.connection.ConnectionConfig;
|
||||
import com.discordsrv.common.config.main.MainConfig;
|
||||
import com.discordsrv.proxy.modules.ServerSwitchMessageModule;
|
||||
|
||||
public abstract class ProxyDiscordSRV<C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<C, CC> {
|
||||
public abstract class ProxyDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<B, C, CC> {
|
||||
|
||||
public ProxyDiscordSRV(B bootstrap) {
|
||||
super(bootstrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() throws Throwable {
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.discordsrv.common.server;
|
||||
|
||||
import com.discordsrv.common.AbstractDiscordSRV;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.config.connection.ConnectionConfig;
|
||||
import com.discordsrv.common.config.main.MainConfig;
|
||||
import com.discordsrv.common.server.modules.DeathMessageModule;
|
||||
@ -29,7 +30,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.OverridingMethodsMustInvokeSuper;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class ServerDiscordSRV<C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<C, CC> {
|
||||
public abstract class ServerDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<B, C, CC> {
|
||||
|
||||
public ServerDiscordSRV(B bootstrap) {
|
||||
super(bootstrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract ServerScheduler scheduler();
|
||||
|
@ -25,6 +25,7 @@ import com.discordsrv.api.event.events.lifecycle.DiscordSRVReloadedEvent;
|
||||
import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent;
|
||||
import com.discordsrv.api.module.type.Module;
|
||||
import com.discordsrv.common.api.util.ApiInstanceUtil;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.channel.ChannelConfigHelper;
|
||||
import com.discordsrv.common.channel.ChannelShutdownBehaviourModule;
|
||||
import com.discordsrv.common.channel.ChannelUpdaterModule;
|
||||
@ -36,7 +37,7 @@ import com.discordsrv.common.config.main.LinkedAccountConfig;
|
||||
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.dependency.DependencyLoader;
|
||||
import com.discordsrv.common.dependency.DiscordSRVDependencyManager;
|
||||
import com.discordsrv.common.discord.api.DiscordAPIEventModule;
|
||||
import com.discordsrv.common.discord.api.DiscordAPIImpl;
|
||||
import com.discordsrv.common.discord.connection.DiscordConnectionManager;
|
||||
@ -51,6 +52,7 @@ import com.discordsrv.common.invite.DiscordInviteModule;
|
||||
import com.discordsrv.common.linking.LinkProvider;
|
||||
import com.discordsrv.common.linking.impl.MemoryLinker;
|
||||
import com.discordsrv.common.linking.impl.StorageLinker;
|
||||
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;
|
||||
@ -62,9 +64,9 @@ import com.discordsrv.common.messageforwarding.game.StartMessageModule;
|
||||
import com.discordsrv.common.messageforwarding.game.StopMessageModule;
|
||||
import com.discordsrv.common.module.ModuleManager;
|
||||
import com.discordsrv.common.module.type.AbstractModule;
|
||||
import com.discordsrv.common.placeholder.result.ComponentResultStringifier;
|
||||
import com.discordsrv.common.placeholder.PlaceholderServiceImpl;
|
||||
import com.discordsrv.common.placeholder.context.GlobalTextHandlingContext;
|
||||
import com.discordsrv.common.placeholder.result.ComponentResultStringifier;
|
||||
import com.discordsrv.common.profile.ProfileManager;
|
||||
import com.discordsrv.common.storage.Storage;
|
||||
import com.discordsrv.common.storage.StorageType;
|
||||
@ -81,6 +83,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@ -99,7 +102,7 @@ import java.util.jar.Manifest;
|
||||
* @param <C> the config type
|
||||
* @param <CC> the connections config type
|
||||
*/
|
||||
public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends ConnectionConfig> implements DiscordSRV {
|
||||
public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> implements DiscordSRV {
|
||||
|
||||
private final AtomicReference<Status> status = new AtomicReference<>(Status.INITIALIZED);
|
||||
private CompletableFuture<Void> enableFuture;
|
||||
@ -113,13 +116,16 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
private DiscordConnectionDetails discordConnectionDetails;
|
||||
|
||||
// DiscordSRV
|
||||
protected final B bootstrap;
|
||||
private final Logger platformLogger;
|
||||
private final Path dataDirectory;
|
||||
private DiscordSRVDependencyManager dependencyManager;
|
||||
private DiscordSRVLogger logger;
|
||||
private ModuleManager moduleManager;
|
||||
private JDAConnectionManager discordConnectionManager;
|
||||
private ChannelConfigHelper channelConfig;
|
||||
|
||||
private Storage storage;
|
||||
private boolean hikariLoaded = false;
|
||||
private LinkProvider linkProvider;
|
||||
|
||||
// Version
|
||||
@ -144,14 +150,18 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
// Internal
|
||||
private final ReentrantLock lifecycleLock = new ReentrantLock();
|
||||
|
||||
public AbstractDiscordSRV() {
|
||||
public AbstractDiscordSRV(B bootstrap) {
|
||||
ApiInstanceUtil.setInstance(this);
|
||||
this.bootstrap = bootstrap;
|
||||
this.platformLogger = bootstrap.logger();
|
||||
this.dataDirectory = bootstrap.dataDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that should be called at the end of implementors constructors.
|
||||
*/
|
||||
protected final void load() {
|
||||
this.dependencyManager = new DiscordSRVDependencyManager(this, bootstrap.lifecycleManager() != null ? bootstrap.lifecycleManager().getDependencyLoader() : null);
|
||||
this.logger = new DiscordSRVLogger(this);
|
||||
this.eventBus = new EventBusImpl(this);
|
||||
this.moduleManager = new ModuleManager(this);
|
||||
@ -199,85 +209,105 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
// DiscordSRVApi
|
||||
|
||||
@Override
|
||||
public @NotNull Status status() {
|
||||
public final @NotNull Status status() {
|
||||
return status.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EventBusImpl eventBus() {
|
||||
public final @NotNull EventBusImpl eventBus() {
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ProfileManager profileManager() {
|
||||
public final @NotNull ProfileManager profileManager() {
|
||||
return profileManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PlaceholderServiceImpl placeholderService() {
|
||||
public final @NotNull PlaceholderServiceImpl placeholderService() {
|
||||
return placeholderService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ComponentFactory componentFactory() {
|
||||
public final @NotNull ComponentFactory componentFactory() {
|
||||
return componentFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DiscordAPIImpl discordAPI() {
|
||||
public final @NotNull DiscordAPIImpl discordAPI() {
|
||||
return discordAPI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<JDA> jda() {
|
||||
public final @NotNull Optional<JDA> jda() {
|
||||
return Optional.ofNullable(discordConnectionManager)
|
||||
.map(DiscordConnectionManager::instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DiscordConnectionDetails discordConnectionDetails() {
|
||||
public final @NotNull DiscordConnectionDetails discordConnectionDetails() {
|
||||
return discordConnectionDetails;
|
||||
}
|
||||
|
||||
// DiscordSRV
|
||||
|
||||
@Override
|
||||
public DiscordSRVLogger logger() {
|
||||
public final IBootstrap bootstrap() {
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Logger platformLogger() {
|
||||
return platformLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DiscordSRVDependencyManager dependencyManager() {
|
||||
return dependencyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final DiscordSRVLogger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage storage() {
|
||||
public final Storage storage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkProvider linkProvider() {
|
||||
public final LinkProvider linkProvider() {
|
||||
return linkProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String version() {
|
||||
public final @NotNull String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String gitRevision() {
|
||||
public final @Nullable String gitRevision() {
|
||||
return gitRevision;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String gitBranch() {
|
||||
public final @Nullable String gitBranch() {
|
||||
return gitBranch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelConfigHelper channelConfig() {
|
||||
public final ChannelConfigHelper channelConfig() {
|
||||
return channelConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JDAConnectionManager discordConnectionManager() {
|
||||
public final JDAConnectionManager discordConnectionManager() {
|
||||
return discordConnectionManager;
|
||||
}
|
||||
|
||||
@ -568,9 +598,8 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
|
||||
try {
|
||||
StorageType storageType = getStorageType();
|
||||
logger().info("Using " + storageType.prettyName() + " as storage");
|
||||
if (storageType.hikari() && !hikariLoaded) {
|
||||
hikariLoaded = true;
|
||||
DependencyLoader.hikari(this).process(classpathAppender()).get();
|
||||
if (storageType.hikari()) {
|
||||
dependencyManager().hikari().download().get();
|
||||
}
|
||||
storage = storageType.storageFunction().apply(this);
|
||||
storage.initialize();
|
||||
|
@ -20,6 +20,7 @@ package com.discordsrv.common;
|
||||
|
||||
import com.discordsrv.api.DiscordSRVApi;
|
||||
import com.discordsrv.api.module.type.Module;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.channel.ChannelConfigHelper;
|
||||
import com.discordsrv.common.command.game.handler.ICommandHandler;
|
||||
import com.discordsrv.common.component.ComponentFactory;
|
||||
@ -29,6 +30,7 @@ import com.discordsrv.common.config.manager.ConnectionConfigManager;
|
||||
import com.discordsrv.common.config.manager.MainConfigManager;
|
||||
import com.discordsrv.common.console.Console;
|
||||
import com.discordsrv.common.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.dependency.DiscordSRVDependencyManager;
|
||||
import com.discordsrv.common.discord.api.DiscordAPIImpl;
|
||||
import com.discordsrv.common.discord.connection.jda.JDAConnectionManager;
|
||||
import com.discordsrv.common.linking.LinkProvider;
|
||||
@ -43,7 +45,6 @@ import com.discordsrv.common.scheduler.Scheduler;
|
||||
import com.discordsrv.common.storage.Storage;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import okhttp3.OkHttpClient;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -58,13 +59,14 @@ import java.util.concurrent.TimeUnit;
|
||||
public interface DiscordSRV extends DiscordSRVApi {
|
||||
|
||||
// Platform
|
||||
IBootstrap bootstrap();
|
||||
Logger platformLogger();
|
||||
Path dataDirectory();
|
||||
Scheduler scheduler();
|
||||
Console console();
|
||||
PluginManager pluginManager();
|
||||
OnlineMode onlineMode();
|
||||
ClasspathAppender classpathAppender();
|
||||
DiscordSRVDependencyManager dependencyManager();
|
||||
ICommandHandler commandHandler();
|
||||
@NotNull AbstractPlayerProvider<?, ?> playerProvider();
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.common.bootstrap;
|
||||
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface IBootstrap {
|
||||
|
||||
Logger logger();
|
||||
ClasspathAppender classpathAppender();
|
||||
LifecycleManager lifecycleManager();
|
||||
Path dataDirectory();
|
||||
|
||||
}
|
@ -16,10 +16,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.common.dependency;
|
||||
package com.discordsrv.common.bootstrap;
|
||||
|
||||
import com.discordsrv.api.DiscordSRVApi;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.dependency.DependencyLoader;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.scheduler.threadfactory.CountingForkJoinWorkerThreadFactory;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
@ -30,16 +31,19 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class InitialDependencyLoader {
|
||||
public class LifecycleManager {
|
||||
|
||||
private final Logger logger;
|
||||
private final ForkJoinPool taskPool;
|
||||
private final DependencyLoader dependencyLoader;
|
||||
private final CompletableFuture<?> completableFuture;
|
||||
|
||||
public InitialDependencyLoader(
|
||||
public LifecycleManager(
|
||||
Logger logger,
|
||||
Path dataDirectory,
|
||||
String[] dependencyResources,
|
||||
@ -58,13 +62,14 @@ public class InitialDependencyLoader {
|
||||
));
|
||||
resourcePaths.addAll(Arrays.asList(dependencyResources));
|
||||
|
||||
DependencyLoader dependencyLoader = new DependencyLoader(
|
||||
this.dependencyLoader = new DependencyLoader(
|
||||
dataDirectory,
|
||||
taskPool,
|
||||
classpathAppender,
|
||||
resourcePaths.toArray(new String[0])
|
||||
);
|
||||
|
||||
this.completableFuture = dependencyLoader.process(classpathAppender);
|
||||
this.completableFuture = dependencyLoader.download();
|
||||
completableFuture.whenComplete((v, t) -> taskPool.shutdown());
|
||||
}
|
||||
|
||||
@ -112,4 +117,7 @@ public class InitialDependencyLoader {
|
||||
} catch (ExecutionException ignored) {}
|
||||
}
|
||||
|
||||
public DependencyLoader getDependencyLoader() {
|
||||
return dependencyLoader;
|
||||
}
|
||||
}
|
@ -22,79 +22,88 @@ import com.discordsrv.common.DiscordSRV;
|
||||
import dev.vankka.dependencydownload.DependencyManager;
|
||||
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import dev.vankka.dependencydownload.repository.Repository;
|
||||
import dev.vankka.dependencydownload.repository.StandardRepository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class DependencyLoader {
|
||||
|
||||
public static DependencyLoader hikari(DiscordSRV discordSRV) {
|
||||
return new DependencyLoader(discordSRV, new String[] {"dependencies/hikari.txt"});
|
||||
private static final List<Repository> REPOSITORIES = Arrays.asList(
|
||||
// TODO
|
||||
new StandardRepository("https://repo1.maven.org/maven2"),
|
||||
new StandardRepository("https://oss.sonatype.org/content/repositories/snapshots"),
|
||||
new StandardRepository("https://s01.oss.sonatype.org/content/repositories/snapshots")
|
||||
);
|
||||
|
||||
public static Path resolvePath(Path dataDirectory) {
|
||||
return dataDirectory.resolve("cache");
|
||||
}
|
||||
|
||||
public static DependencyLoader h2(DiscordSRV discordSRV) {
|
||||
return new DependencyLoader(discordSRV, new String[] {"dependencies/h2Driver.txt"});
|
||||
}
|
||||
|
||||
public static DependencyLoader mysql(DiscordSRV discordSRV) {
|
||||
return new DependencyLoader(discordSRV, new String[] {"dependencies/mysqlDriver.txt"});
|
||||
}
|
||||
|
||||
private final Path cacheDirectory;
|
||||
private final Executor executor;
|
||||
private final String[] dependencyResources;
|
||||
|
||||
public DependencyLoader(DiscordSRV discordSRV, String[] dependencyResources) {
|
||||
this(
|
||||
discordSRV.dataDirectory(),
|
||||
discordSRV.scheduler().forkJoinPool(),
|
||||
dependencyResources
|
||||
);
|
||||
}
|
||||
|
||||
public DependencyLoader(
|
||||
Path dataDirectory,
|
||||
Executor executor,
|
||||
String[] dependencyResources
|
||||
) {
|
||||
this.cacheDirectory = dataDirectory.resolve("cache");
|
||||
this.executor = executor;
|
||||
this.dependencyResources = dependencyResources;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> process(ClasspathAppender classpathAppender) throws IOException {
|
||||
DependencyManager dependencyManager = new DependencyManager(cacheDirectory);
|
||||
for (String dependencyResource : dependencyResources) {
|
||||
dependencyManager.loadFromResource(getClass().getClassLoader().getResource(dependencyResource));
|
||||
public static DependencyManager fromPaths(Path dataDirectory, String[] resources) throws IOException {
|
||||
DependencyManager dependencyManager = new DependencyManager(resolvePath(dataDirectory));
|
||||
for (String dependencyResource : resources) {
|
||||
URL resource = DependencyLoader.class.getClassLoader().getResource(dependencyResource);
|
||||
if (resource == null) {
|
||||
throw new IllegalArgumentException("Could not find resource with: " + dependencyResource);
|
||||
}
|
||||
dependencyManager.loadFromResource(resource);
|
||||
}
|
||||
return download(dependencyManager, classpathAppender);
|
||||
|
||||
return dependencyManager;
|
||||
}
|
||||
|
||||
private final DependencyManager dependencyManager;
|
||||
private final Executor executor;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
|
||||
|
||||
public DependencyLoader(DiscordSRV discordSRV, String[] paths) throws IOException {
|
||||
this(discordSRV, fromPaths(discordSRV.dataDirectory(), paths));
|
||||
}
|
||||
|
||||
public DependencyLoader(Path dataDirectory, Executor executor, ClasspathAppender classpathAppender, String[] paths) throws IOException {
|
||||
this(executor, classpathAppender, fromPaths(dataDirectory, paths));
|
||||
}
|
||||
|
||||
public DependencyLoader(DiscordSRV discordSRV, DependencyManager dependencyManager) {
|
||||
this(discordSRV.scheduler().executor(), discordSRV.bootstrap().classpathAppender(), dependencyManager);
|
||||
}
|
||||
|
||||
public DependencyLoader(Executor executor, ClasspathAppender classpathAppender, DependencyManager dependencyManager) {
|
||||
this.dependencyManager = dependencyManager;
|
||||
this.executor = executor;
|
||||
this.classpathAppender = classpathAppender;
|
||||
}
|
||||
|
||||
public DependencyManager getDependencyManager() {
|
||||
return dependencyManager;
|
||||
}
|
||||
|
||||
public IsolatedClassLoader loadIntoIsolated() throws IOException {
|
||||
IsolatedClassLoader classLoader = new IsolatedClassLoader();
|
||||
process(classLoader).join();
|
||||
download(classLoader).join();
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> download(DependencyManager manager,
|
||||
ClasspathAppender classpathAppender) {
|
||||
public CompletableFuture<Void> download() {
|
||||
return download(classpathAppender);
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> download(ClasspathAppender appender) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
manager.downloadAll(executor, Arrays.asList(
|
||||
// TODO
|
||||
new StandardRepository("https://repo1.maven.org/maven2"),
|
||||
new StandardRepository("https://m2.dv8tion.net/releases"),
|
||||
new StandardRepository("https://oss.sonatype.org/content/repositories/snapshots"),
|
||||
new StandardRepository("https://s01.oss.sonatype.org/content/repositories/snapshots")
|
||||
)).join();
|
||||
manager.relocateAll(executor).join();
|
||||
manager.loadAll(executor, classpathAppender).join();
|
||||
dependencyManager.downloadAll(executor, REPOSITORIES).join();
|
||||
dependencyManager.relocateAll(executor).join();
|
||||
dependencyManager.loadAll(executor, appender).join();
|
||||
|
||||
future.complete(null);
|
||||
} catch (CompletionException e) {
|
||||
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.discordsrv.common.dependency;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import dev.vankka.dependencydownload.ApplicationDependencyManager;
|
||||
import dev.vankka.dependencydownload.DependencyManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class DiscordSRVDependencyManager {
|
||||
|
||||
private final DiscordSRV discordSRV;
|
||||
private final ApplicationDependencyManager dependencyManager;
|
||||
|
||||
public DiscordSRVDependencyManager(DiscordSRV discordSRV, DependencyLoader initialLoader) {
|
||||
this.discordSRV = discordSRV;
|
||||
Path cacheDirectory = DependencyLoader.resolvePath(discordSRV.dataDirectory());
|
||||
this.dependencyManager = new ApplicationDependencyManager(cacheDirectory);
|
||||
|
||||
if (initialLoader != null) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
dependencyManager.include(initialLoader.getDependencyManager());
|
||||
}
|
||||
}
|
||||
|
||||
private DependencyLoader loader(DependencyManager manager) {
|
||||
return new DependencyLoader(discordSRV, dependencyManager.include(manager));
|
||||
}
|
||||
|
||||
private DependencyLoader loader(String[] paths) throws IOException {
|
||||
return loader(DependencyLoader.fromPaths(discordSRV.dataDirectory(), paths));
|
||||
}
|
||||
|
||||
public DependencyLoader hikari() throws IOException {
|
||||
return loader(new String[] {"dependencies/hikari.txt"});
|
||||
}
|
||||
|
||||
public DependencyLoader h2() throws IOException {
|
||||
return loader(new String[] {"dependencies/h2Driver.txt"});
|
||||
}
|
||||
|
||||
public DependencyLoader mysql() throws IOException {
|
||||
return loader(new String[] {"dependencies/mysqlDriver.txt"});
|
||||
}
|
||||
|
||||
}
|
@ -30,7 +30,9 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MemoryLinker implements LinkProvider, LinkStore {
|
||||
|
||||
private final BidiMap<UUID, Long> map = new DualHashBidiMap<>();
|
||||
private final BidiMap<UUID, Long> map = new DualHashBidiMap<UUID, Long>() {{
|
||||
put(UUID.fromString("6c983d46-0631-48b8-9baf-5e33eb5ffec4"), 185828288466255874L);
|
||||
}};
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<Long>> queryUserId(@NotNull UUID playerUUID) {
|
||||
|
@ -20,7 +20,6 @@ package com.discordsrv.common.storage.impl.sql.file;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.config.connection.StorageConfig;
|
||||
import com.discordsrv.common.dependency.DependencyLoader;
|
||||
import com.discordsrv.common.exception.StorageException;
|
||||
import com.discordsrv.common.storage.impl.sql.SQLStorage;
|
||||
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||
@ -44,7 +43,7 @@ public class H2Storage extends SQLStorage {
|
||||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
classLoader = DependencyLoader.h2(discordSRV).loadIntoIsolated();
|
||||
classLoader = discordSRV.dependencyManager().h2().loadIntoIsolated();
|
||||
} catch (IOException e) {
|
||||
throw new StorageException(e);
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ package com.discordsrv.common.storage.impl.sql.hikari;
|
||||
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.config.connection.StorageConfig;
|
||||
import com.discordsrv.common.dependency.DependencyLoader;
|
||||
import com.discordsrv.common.exception.StorageException;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import dev.vankka.dependencydownload.classloader.IsolatedClassLoader;
|
||||
@ -69,7 +68,7 @@ public class MySQLStorage extends HikariStorage {
|
||||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
initializeWithContext(classLoader = DependencyLoader.mysql(discordSRV).loadIntoIsolated());
|
||||
initializeWithContext(classLoader = discordSRV.dependencyManager().mysql().loadIntoIsolated());
|
||||
} catch (IOException e) {
|
||||
throw new StorageException(e);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
package com.discordsrv.common;
|
||||
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.command.game.handler.ICommandHandler;
|
||||
import com.discordsrv.common.config.connection.ConnectionConfig;
|
||||
import com.discordsrv.common.config.main.MainConfig;
|
||||
@ -40,12 +42,11 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionConfig> {
|
||||
public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig> {
|
||||
|
||||
public static final MockDiscordSRV INSTANCE = new MockDiscordSRV();
|
||||
|
||||
private final Scheduler scheduler = new StandardScheduler(this);
|
||||
private final Logger logger = JavaLoggerImpl.getRoot();
|
||||
private Path path;
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -53,12 +54,28 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
}
|
||||
|
||||
public MockDiscordSRV() {
|
||||
load();
|
||||
}
|
||||
super(new IBootstrap() {
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return JavaLoggerImpl.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return logger;
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,11 +101,6 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String version() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginManager pluginManager() {
|
||||
return null;
|
||||
@ -99,11 +111,6 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return null;
|
||||
@ -123,4 +130,9 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
public MainConfigManager<MainConfig> configManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForStatus(Status status) throws InterruptedException {
|
||||
super.waitForStatus(status);
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
package com.discordsrv.config;
|
||||
|
||||
import com.discordsrv.common.AbstractDiscordSRV;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.command.game.handler.ICommandHandler;
|
||||
import com.discordsrv.common.config.connection.ConnectionConfig;
|
||||
import com.discordsrv.common.config.main.MainConfig;
|
||||
@ -27,6 +29,7 @@ import com.discordsrv.common.config.manager.MainConfigManager;
|
||||
import com.discordsrv.common.console.Console;
|
||||
import com.discordsrv.common.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
|
||||
import com.discordsrv.common.player.provider.AbstractPlayerProvider;
|
||||
import com.discordsrv.common.plugin.PluginManager;
|
||||
import com.discordsrv.common.scheduler.Scheduler;
|
||||
@ -37,11 +40,30 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionConfig> {
|
||||
public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig> {
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return null;
|
||||
public MockDiscordSRV() {
|
||||
super(new IBootstrap() {
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return JavaLoggerImpl.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,11 +81,6 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String version() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginManager pluginManager() {
|
||||
return null;
|
||||
@ -74,11 +91,6 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return null;
|
||||
|
@ -42,9 +42,9 @@ dependencyResolutionManagement {
|
||||
// MinecraftDependencyDownload
|
||||
version('mcdependencydownload', '1.0.0-SNAPSHOT')
|
||||
library('mcdependencydownload-bukkit-bootstrap', 'dev.vankka', 'minecraftdependencydownload-bukkit').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-bukkit-loader', 'dev.vankka', 'minecraftdependencydownload-bukkit').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-bukkit-loader', 'dev.vankka', 'minecraftdependencydownload-bukkit-loader').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-bungee-bootstrap', 'dev.vankka', 'minecraftdependencydownload-bungee').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-bungee-loader', 'dev.vankka', 'minecraftdependencydownload-bungee').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-bungee-loader', 'dev.vankka', 'minecraftdependencydownload-bungee-loader').versionRef('mcdependencydownload')
|
||||
library('mcdependencydownload-velocity', 'dev.vankka', 'minecraftdependencydownload-velocity').versionRef('mcdependencydownload')
|
||||
|
||||
// Annotations
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
package com.discordsrv.sponge;
|
||||
|
||||
import com.discordsrv.common.dependency.InitialDependencyLoader;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
|
||||
import com.discordsrv.sponge.bootstrap.ISpongeBootstrap;
|
||||
@ -34,11 +35,11 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@SuppressWarnings("unused") // Reflection
|
||||
public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpongeBootstrap {
|
||||
public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpongeBootstrap, IBootstrap {
|
||||
|
||||
private final Logger logger;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
private final InitialDependencyLoader dependencies;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
private SpongeDiscordSRV discordSRV;
|
||||
private SpongeCommandHandler commandHandler;
|
||||
|
||||
@ -51,7 +52,7 @@ public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpo
|
||||
super(classLoader);
|
||||
this.logger = new Log4JLoggerImpl(pluginContainer.logger());
|
||||
this.classpathAppender = new JarInJarClasspathAppender(classLoader);
|
||||
this.dependencies = new InitialDependencyLoader(
|
||||
this.lifecycleManager = new LifecycleManager(
|
||||
logger,
|
||||
dataDirectory,
|
||||
new String[] {"dependencies/runtimeDownload-sponge.txt"},
|
||||
@ -64,7 +65,7 @@ public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpo
|
||||
|
||||
@Override
|
||||
public void onConstruct() {
|
||||
dependencies.load();
|
||||
lifecycleManager.load();
|
||||
|
||||
this.commandHandler = new SpongeCommandHandler(() -> discordSRV, pluginContainer);
|
||||
game.eventManager().registerListeners(pluginContainer, commandHandler);
|
||||
@ -72,7 +73,7 @@ public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpo
|
||||
|
||||
@Override
|
||||
public void onStarted() {
|
||||
dependencies.enable(() -> this.discordSRV = new SpongeDiscordSRV(logger, classpathAppender, dataDirectory, pluginContainer, game, commandHandler));
|
||||
lifecycleManager.enable(() -> this.discordSRV = new SpongeDiscordSRV(this));
|
||||
if (discordSRV != null) {
|
||||
discordSRV.invokeServerStarted();
|
||||
}
|
||||
@ -80,11 +81,43 @@ public class DiscordSRVSpongeBootstrap extends AbstractBootstrap implements ISpo
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
dependencies.reload(discordSRV);
|
||||
lifecycleManager.reload(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopping() {
|
||||
dependencies.disable(discordSRV);
|
||||
lifecycleManager.disable(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return classpathAppender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return lifecycleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
public PluginContainer pluginContainer() {
|
||||
return pluginContainer;
|
||||
}
|
||||
|
||||
public Game game() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public SpongeCommandHandler commandHandler() {
|
||||
return commandHandler;
|
||||
}
|
||||
}
|
||||
|
@ -25,76 +25,42 @@ 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.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.plugin.PluginManager;
|
||||
import com.discordsrv.common.server.ServerDiscordSRV;
|
||||
import com.discordsrv.sponge.command.game.handler.SpongeCommandHandler;
|
||||
import com.discordsrv.sponge.console.SpongeConsole;
|
||||
import com.discordsrv.sponge.player.SpongePlayerProvider;
|
||||
import com.discordsrv.sponge.plugin.SpongePluginManager;
|
||||
import com.discordsrv.sponge.scheduler.SpongeScheduler;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.lifecycle.ProvideServiceEvent;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
|
||||
import java.nio.file.Path;
|
||||
public class SpongeDiscordSRV extends ServerDiscordSRV<DiscordSRVSpongeBootstrap, MainConfig, ConnectionConfig> {
|
||||
|
||||
public class SpongeDiscordSRV extends ServerDiscordSRV<MainConfig, ConnectionConfig> {
|
||||
|
||||
private final PluginContainer pluginContainer;
|
||||
private final Game game;
|
||||
|
||||
private final Logger logger;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
private final Path dataDirectory;
|
||||
private final SpongeScheduler scheduler;
|
||||
private final SpongeConsole console;
|
||||
private final SpongePlayerProvider playerProvider;
|
||||
private final SpongePluginManager pluginManager;
|
||||
private final SpongeCommandHandler commandHandler;
|
||||
|
||||
public SpongeDiscordSRV(
|
||||
Logger logger,
|
||||
ClasspathAppender classpathAppender,
|
||||
Path dataDirectory,
|
||||
PluginContainer pluginContainer,
|
||||
Game game,
|
||||
SpongeCommandHandler commandHandler
|
||||
) {
|
||||
this.logger = logger;
|
||||
this.classpathAppender = classpathAppender;
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.pluginContainer = pluginContainer;
|
||||
this.game = game;
|
||||
public SpongeDiscordSRV(DiscordSRVSpongeBootstrap bootstrap) {
|
||||
super(bootstrap);
|
||||
|
||||
this.scheduler = new SpongeScheduler(this);
|
||||
this.console = new SpongeConsole(this);
|
||||
this.playerProvider = new SpongePlayerProvider(this);
|
||||
this.pluginManager = new SpongePluginManager(this);
|
||||
this.commandHandler = commandHandler;
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
public PluginContainer container() {
|
||||
return pluginContainer;
|
||||
return bootstrap.pluginContainer();
|
||||
}
|
||||
|
||||
public Game game() {
|
||||
return game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
return bootstrap.game();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,17 +87,12 @@ public class SpongeDiscordSRV extends ServerDiscordSRV<MainConfig, ConnectionCon
|
||||
public OnlineMode onlineMode() {
|
||||
// TODO: velocity / bungee
|
||||
|
||||
return OnlineMode.of(game.server().isOnlineModeEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return classpathAppender;
|
||||
return OnlineMode.of(game().server().isOnlineModeEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return commandHandler;
|
||||
return bootstrap.commandHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -147,7 +108,7 @@ public class SpongeDiscordSRV extends ServerDiscordSRV<MainConfig, ConnectionCon
|
||||
@Override
|
||||
protected void enable() throws Throwable {
|
||||
// Service provider
|
||||
game().eventManager().registerListeners(pluginContainer, this);
|
||||
game().eventManager().registerListeners(container(), this);
|
||||
|
||||
super.enable();
|
||||
}
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
package com.discordsrv.velocity;
|
||||
|
||||
import com.discordsrv.common.dependency.InitialDependencyLoader;
|
||||
import com.discordsrv.common.bootstrap.IBootstrap;
|
||||
import com.discordsrv.common.bootstrap.LifecycleManager;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.logging.backend.impl.SLF4JLoggerImpl;
|
||||
import com.google.inject.Inject;
|
||||
@ -44,11 +45,11 @@ import java.nio.file.Path;
|
||||
authors = {"Scarsz", "Vankka"},
|
||||
url = "https://discordsrv.com"
|
||||
)
|
||||
public class DiscordSRVVelocityBootstrap {
|
||||
public class DiscordSRVVelocityBootstrap implements IBootstrap {
|
||||
|
||||
private final Logger logger;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
private final InitialDependencyLoader dependencies;
|
||||
private final LifecycleManager lifecycleManager;
|
||||
private final ProxyServer proxyServer;
|
||||
private final PluginContainer pluginContainer;
|
||||
private final Path dataDirectory;
|
||||
@ -58,7 +59,7 @@ public class DiscordSRVVelocityBootstrap {
|
||||
public DiscordSRVVelocityBootstrap(com.discordsrv.x.slf4j.Logger logger, ProxyServer proxyServer, PluginContainer pluginContainer, @DataDirectory Path dataDirectory) throws IOException {
|
||||
this.logger = new SLF4JLoggerImpl(logger);
|
||||
this.classpathAppender = new VelocityClasspathAppender(this, proxyServer);
|
||||
this.dependencies = new InitialDependencyLoader(
|
||||
this.lifecycleManager = new LifecycleManager(
|
||||
this.logger,
|
||||
dataDirectory,
|
||||
new String[] {"dependencies/runtimeDownload-velocity.txt"},
|
||||
@ -71,17 +72,44 @@ public class DiscordSRVVelocityBootstrap {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||
dependencies.loadAndEnable(() -> this.discordSRV = new VelocityDiscordSRV(this, logger, classpathAppender, proxyServer, pluginContainer, dataDirectory));
|
||||
lifecycleManager.loadAndEnable(() -> this.discordSRV = new VelocityDiscordSRV(this));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyReload(ProxyReloadEvent event) {
|
||||
dependencies.reload(discordSRV);
|
||||
lifecycleManager.reload(discordSRV);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent event) {
|
||||
dependencies.disable(discordSRV);
|
||||
lifecycleManager.disable(discordSRV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return classpathAppender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleManager lifecycleManager() {
|
||||
return lifecycleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
}
|
||||
|
||||
public ProxyServer proxyServer() {
|
||||
return proxyServer;
|
||||
}
|
||||
|
||||
public PluginContainer pluginContainer() {
|
||||
return pluginContainer;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ 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.debug.data.OnlineMode;
|
||||
import com.discordsrv.common.logging.Logger;
|
||||
import com.discordsrv.common.plugin.PluginManager;
|
||||
import com.discordsrv.common.scheduler.StandardScheduler;
|
||||
import com.discordsrv.proxy.ProxyDiscordSRV;
|
||||
@ -34,36 +33,22 @@ import com.discordsrv.velocity.player.VelocityPlayerProvider;
|
||||
import com.discordsrv.velocity.plugin.VelocityPluginManager;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import dev.vankka.dependencydownload.classpath.ClasspathAppender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class VelocityDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConfig> {
|
||||
public class VelocityDiscordSRV extends ProxyDiscordSRV<DiscordSRVVelocityBootstrap, MainConfig, ConnectionConfig> {
|
||||
|
||||
private final Object plugin;
|
||||
private final ProxyServer proxyServer;
|
||||
private final PluginContainer pluginContainer;
|
||||
|
||||
private final Logger logger;
|
||||
private final ClasspathAppender classpathAppender;
|
||||
private final Path dataDirectory;
|
||||
private final StandardScheduler scheduler;
|
||||
private final VelocityConsole console;
|
||||
private final VelocityPlayerProvider playerProvider;
|
||||
private final VelocityPluginManager pluginManager;
|
||||
private final VelocityCommandHandler commandHandler;
|
||||
|
||||
public VelocityDiscordSRV(Object plugin, Logger logger, ClasspathAppender classpathAppender, ProxyServer proxyServer, PluginContainer pluginContainer, Path dataDirectory) {
|
||||
this.plugin = plugin;
|
||||
this.logger = logger;
|
||||
this.classpathAppender = classpathAppender;
|
||||
this.proxyServer = proxyServer;
|
||||
this.pluginContainer = pluginContainer;
|
||||
this.dataDirectory = dataDirectory;
|
||||
public VelocityDiscordSRV(DiscordSRVVelocityBootstrap bootstrap) {
|
||||
super(bootstrap);
|
||||
|
||||
this.scheduler = new StandardScheduler(this);
|
||||
this.console = new VelocityConsole(this);
|
||||
@ -85,25 +70,15 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionCo
|
||||
}
|
||||
|
||||
public Object plugin() {
|
||||
return plugin;
|
||||
return bootstrap;
|
||||
}
|
||||
|
||||
public PluginContainer container() {
|
||||
return pluginContainer;
|
||||
return bootstrap.pluginContainer();
|
||||
}
|
||||
|
||||
public ProxyServer proxy() {
|
||||
return proxyServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger platformLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return dataDirectory;
|
||||
return bootstrap.proxyServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -131,11 +106,6 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionCo
|
||||
return OnlineMode.of(proxy().getConfiguration().isOnlineMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClasspathAppender classpathAppender() {
|
||||
return classpathAppender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommandHandler commandHandler() {
|
||||
return commandHandler;
|
||||
|
Loading…
Reference in New Issue
Block a user