Don't run dependency download on a separate thread on bukkit

This commit is contained in:
Vankka 2024-06-07 17:07:15 +03:00
parent 00e80166b3
commit bd1f50c502
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
4 changed files with 15 additions and 9 deletions

View File

@ -47,7 +47,8 @@ public class DiscordSRVBukkitBootstrap extends BukkitBootstrap implements IBoots
logger,
plugin.getDataFolder().toPath(),
getDependencyResources(),
getClasspathAppender()
getClasspathAppender(),
false
);
}

View File

@ -44,7 +44,8 @@ public class DiscordSRVBungeeBootstrap extends BungeeBootstrap implements IBoots
logger,
plugin.getDataFolder().toPath(),
new String[] {"dependencies/runtimeDownload-bungee.txt"},
getClasspathAppender()
getClasspathAppender(),
true
);
}

View File

@ -41,16 +41,17 @@ public class LifecycleManager {
private final Logger logger;
private final ExecutorService taskPool;
private final DependencyLoader dependencyLoader;
private final CompletableFuture<?> completableFuture;
private CompletableFuture<?> completableFuture;
public LifecycleManager(
Logger logger,
Path dataDirectory,
String[] dependencyResources,
ClasspathAppender classpathAppender
ClasspathAppender classpathAppender,
boolean useExecutor
) throws IOException {
this.logger = logger;
this.taskPool = Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "DiscordSRV Initialization"));
this.taskPool = useExecutor ? Executors.newSingleThreadExecutor(runnable -> new Thread(runnable, "DiscordSRV Initialization")) : null;
List<String> resourcePaths = new ArrayList<>(Collections.singletonList(
"dependencies/runtimeDownload-common.txt"
@ -63,9 +64,6 @@ public class LifecycleManager {
classpathAppender,
resourcePaths.toArray(new String[0])
);
this.completableFuture = dependencyLoader.download();
completableFuture.whenComplete((v, t) -> taskPool.shutdown());
}
public void loadAndEnable(Supplier<DiscordSRV> discordSRVSupplier) {
@ -76,6 +74,11 @@ public class LifecycleManager {
private boolean load() {
try {
this.completableFuture = dependencyLoader.download();
if (taskPool != null) {
completableFuture.whenComplete((v, t) -> taskPool.shutdown());
}
completableFuture.get();
return true;
} catch (InterruptedException ignored) {

View File

@ -64,7 +64,8 @@ public class DiscordSRVVelocityBootstrap implements IBootstrap {
this.logger,
dataDirectory,
new String[] {"dependencies/runtimeDownload-velocity.txt"},
classpathAppender
classpathAppender,
true
);
this.proxyServer = proxyServer;
this.pluginContainer = pluginContainer;