From 7a6c51331bc5f8159bbe89abfdb3b2ec921d89c6 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Tue, 13 Feb 2024 23:37:00 +0100 Subject: [PATCH] Move config load after platform creation --- .../viaversion/viaversion/ViaVersionPlugin.java | 14 ++++---------- .../bukkit/platform/BukkitViaConfig.java | 7 ++----- .../com/viaversion/viaversion/BungeePlugin.java | 2 ++ .../bungee/platform/BungeeViaConfig.java | 5 ++--- .../viaversion/common/dummy/TestConfig.java | 4 ++-- .../com/viaversion/viaversion/SpongePlugin.java | 1 + .../sponge/platform/SpongeViaConfig.java | 5 ++--- .../com/viaversion/viaversion/VelocityPlugin.java | 1 + .../velocity/platform/VelocityViaConfig.java | 5 ++--- 9 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java index 87c67b684..0110c623c 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/ViaVersionPlugin.java @@ -56,8 +56,8 @@ import org.bukkit.plugin.java.JavaPlugin; public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform { private static final boolean FOLIA = PaperViaInjector.hasClass("io.papermc.paper.threadedregions.RegionizedServer"); private static ViaVersionPlugin instance; - private final BukkitCommandHandler commandHandler; - private final BukkitViaConfig conf; + private final BukkitCommandHandler commandHandler = new BukkitCommandHandler(); + private final BukkitViaConfig conf = new BukkitViaConfig(getDataFolder()); private final ViaAPI api = new BukkitViaAPI(this); private boolean protocolSupport; private boolean lateBind; @@ -65,20 +65,14 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform public ViaVersionPlugin() { instance = this; - // Command handler - commandHandler = new BukkitCommandHandler(); - - // Init platform - BukkitViaInjector injector = new BukkitViaInjector(); Via.init(ViaManagerImpl.builder() .platform(this) .commandHandler(commandHandler) - .injector(injector) + .injector(new BukkitViaInjector()) .loader(new BukkitViaLoader(this)) .build()); - // Config magic - conf = new BukkitViaConfig(); + conf.reload(); } @Override diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java index 4ed72e7ad..b7a1075eb 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaConfig.java @@ -17,13 +17,11 @@ */ package com.viaversion.viaversion.bukkit.platform; -import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.configuration.AbstractViaConfig; import java.io.File; import java.util.Arrays; import java.util.List; import java.util.Map; -import org.bukkit.plugin.Plugin; public class BukkitViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("bungee-ping-interval", "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers"); @@ -34,9 +32,8 @@ public class BukkitViaConfig extends AbstractViaConfig { private boolean armorToggleFix; private boolean registerUserConnectionOnJoin; - public BukkitViaConfig() { - super(new File(((Plugin) Via.getPlatform()).getDataFolder(), "config.yml")); - reload(); + public BukkitViaConfig(final File folder) { + super(new File(folder, "config.yml")); } @Override diff --git a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java index 251ffd638..c55c61459 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java +++ b/bungee/src/main/java/com/viaversion/viaversion/BungeePlugin.java @@ -80,6 +80,8 @@ public class BungeePlugin extends Plugin implements ViaServerProxyPlatform bungeeServerProtocols; - public BungeeViaConfig(File configFile) { - super(new File(configFile, "config.yml")); - reload(); + public BungeeViaConfig(File folder) { + super(new File(folder, "config.yml")); } @Override diff --git a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestConfig.java b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestConfig.java index ba30e34dd..1002dd884 100644 --- a/common/src/test/java/com/viaversion/viaversion/common/dummy/TestConfig.java +++ b/common/src/test/java/com/viaversion/viaversion/common/dummy/TestConfig.java @@ -26,8 +26,8 @@ import java.util.Map; public final class TestConfig extends AbstractViaConfig { - public TestConfig(File configFile) { - super(configFile); + public TestConfig(File file) { + super(file); } @Override diff --git a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java index abb4008c7..80d006580 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java +++ b/sponge/src/main/java/com/viaversion/viaversion/SpongePlugin.java @@ -95,6 +95,7 @@ public class SpongePlugin implements ViaPlatform { .injector(new SpongeViaInjector()) .loader(new SpongeViaLoader(this)) .build()); + conf.reload(); } @Listener diff --git a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java index b0416c761..c5b1f66b9 100644 --- a/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java +++ b/sponge/src/main/java/com/viaversion/viaversion/sponge/platform/SpongeViaConfig.java @@ -28,9 +28,8 @@ public class SpongeViaConfig extends AbstractViaConfig { "bungee-ping-save", "bungee-servers", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "quick-move-action-fix", "change-1_9-hitbox", "change-1_14-hitbox", "blockconnection-method"); - public SpongeViaConfig(File configFile) { - super(new File(configFile, "config.yml")); - reload(); + public SpongeViaConfig(File folder) { + super(new File(folder, "config.yml")); } @Override diff --git a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java index 32b7b9bfd..820c23a37 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java +++ b/velocity/src/main/java/com/viaversion/viaversion/VelocityPlugin.java @@ -103,6 +103,7 @@ public class VelocityPlugin implements ViaServerProxyPlatform { .commandHandler(commandHandler) .loader(new VelocityViaLoader()) .injector(new VelocityViaInjector()).build()); + conf.reload(); } @Subscribe(order = PostOrder.LAST) diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java index 731a21acd..ad2dd29da 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaConfig.java @@ -32,9 +32,8 @@ public class VelocityViaConfig extends AbstractViaConfig { private boolean velocityPingSave; private Map velocityServerProtocols; - public VelocityViaConfig(File configFile) { - super(new File(configFile, "config.yml")); - reload(); + public VelocityViaConfig(File folder) { + super(new File(folder, "config.yml")); } @Override