From 24d0ae76072197d3e0da680e439b6f9cc17a4bac Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Mon, 22 Jul 2024 18:24:06 +0200 Subject: [PATCH] Add ViaManager#addPostEnableListener (#4038) --- .../viaversion/viaversion/api/ViaManager.java | 7 ++++++ .../viaversion/viaversion/ViaManagerImpl.java | 24 ++++++++++--------- .../velocity/platform/VelocityViaLoader.java | 6 +---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java index 0143cd2b2..4e82c9ef8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java @@ -140,6 +140,13 @@ public interface ViaManager { */ void addEnableListener(Runnable runnable); + /** + * Adds a runnable to be executed when ViaVersion has finished its init after the full server load. + * + * @param runnable runnable to be executed + */ + void addPostEnableListener(Runnable runnable); + /** * Returns whether the manager has been initialized (and protocols have been loaded). * diff --git a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java index da130a7e3..1c67e8f2d 100644 --- a/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/ViaManagerImpl.java @@ -67,6 +67,7 @@ public class ViaManagerImpl implements ViaManager { private final ViaPlatformLoader loader; private final Set subPlatforms = new HashSet<>(); private List enableListeners = new ArrayList<>(); + private List postEnableListeners = new ArrayList<>(); private PlatformTask mappingLoadingTask; private boolean initialized; @@ -184,6 +185,11 @@ public class ViaManagerImpl implements ViaManager { // Refresh Versions protocolManager.refreshVersions(); + + for (final Runnable listener : postEnableListeners) { + listener.run(); + } + postEnableListeners = null; } private void loadServerProtocol() { @@ -317,25 +323,21 @@ public class ViaManagerImpl implements ViaManager { return configurationProvider; } - /** - * Returns a mutable set of self-added subplatform version strings. - * This set is expanded by the subplatform itself (e.g. ViaBackwards), and may not contain all running ones. - * - * @return mutable set of subplatform versions - */ + @Override public Set getSubPlatforms() { return subPlatforms; } - /** - * Adds a runnable to be executed when ViaVersion has finished its init before the full server load. - * - * @param runnable runnable to be executed - */ + @Override public void addEnableListener(Runnable runnable) { enableListeners.add(runnable); } + @Override + public void addPostEnableListener(final Runnable runnable) { + postEnableListeners.add(runnable); + } + @Override public boolean isInitialized() { return initialized; diff --git a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaLoader.java b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaLoader.java index 50fa665f8..394c047ea 100644 --- a/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaLoader.java +++ b/velocity/src/main/java/com/viaversion/viaversion/velocity/platform/VelocityViaLoader.java @@ -24,7 +24,6 @@ import com.viaversion.viaversion.api.platform.ViaPlatformLoader; import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.VersionProvider; -import com.viaversion.viaversion.protocol.version.BaseVersionProvider; import com.viaversion.viaversion.protocols.v1_8to1_9.provider.BossBarProvider; import com.viaversion.viaversion.velocity.listeners.UpdateListener; import com.viaversion.viaversion.velocity.providers.VelocityBossBarProvider; @@ -44,10 +43,7 @@ public class VelocityViaLoader implements ViaPlatformLoader { providers.use(BossBarProvider.class, new VelocityBossBarProvider()); } - // Allow platforms to override the version provider - if (providers.get(VersionProvider.class) instanceof BaseVersionProvider) { - providers.use(VersionProvider.class, new VelocityVersionProvider()); - } + providers.use(VersionProvider.class, new VelocityVersionProvider()); // We probably don't need a EntityIdProvider because velocity sends a Join packet on server change // We don't need main hand patch because Join Game packet makes client send hand data again