mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 18:15:39 +01:00
Add runnable list to be executed before the full init
This commit is contained in:
parent
045c35243f
commit
25d54ae229
@ -15,7 +15,9 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.TabCompleteThread;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||
import us.myles.ViaVersion.update.UpdateUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -28,6 +30,7 @@ public class ViaManager {
|
||||
private final ViaCommandHandler commandHandler;
|
||||
private final ViaPlatformLoader loader;
|
||||
private final Set<String> subPlatforms = new HashSet<>();
|
||||
private List<Runnable> enableListeners = new ArrayList<>();
|
||||
private TaskId mappingLoadingTask;
|
||||
private boolean debug;
|
||||
|
||||
@ -48,10 +51,13 @@ public class ViaManager {
|
||||
platform.onReload();
|
||||
}
|
||||
// Check for updates
|
||||
if (platform.getConf().isCheckForUpdates())
|
||||
if (platform.getConf().isCheckForUpdates()) {
|
||||
UpdateUtil.sendUpdateMessage();
|
||||
}
|
||||
|
||||
// Force class load
|
||||
ProtocolRegistry.init();
|
||||
|
||||
// Inject
|
||||
try {
|
||||
injector.inject();
|
||||
@ -60,11 +66,17 @@ public class ViaManager {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark as injected
|
||||
System.setProperty("ViaVersion", platform.getPluginVersion());
|
||||
|
||||
for (Runnable listener : enableListeners) {
|
||||
listener.run();
|
||||
}
|
||||
enableListeners = null;
|
||||
|
||||
// If successful
|
||||
platform.runSync(this::onServerLoaded);
|
||||
|
||||
}
|
||||
|
||||
public void onServerLoaded() {
|
||||
@ -195,6 +207,15 @@ public class ViaManager {
|
||||
return platform.getConnectionManager().getConnectedClient(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a runnable to be executed when ViaVersion has finished its init before the full server load.
|
||||
*
|
||||
* @param runnable runnable to be executed
|
||||
*/
|
||||
public void addEnableListener(Runnable runnable) {
|
||||
enableListeners.add(runnable);
|
||||
}
|
||||
|
||||
public static final class ViaManagerBuilder {
|
||||
private ViaPlatform<?> platform;
|
||||
private ViaInjector injector;
|
||||
|
@ -5,7 +5,7 @@ import java.util.Map;
|
||||
|
||||
public class InformativeException extends Exception {
|
||||
private final Map<String, Object> info = new HashMap<>();
|
||||
private int sources = 0;
|
||||
private int sources;
|
||||
|
||||
public InformativeException(Throwable cause) {
|
||||
super(cause);
|
||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
@ -82,7 +83,10 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
|
||||
MappingDataLoader.enableMappingsCache();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onProxyLateInit(ProxyInitializeEvent e) {
|
||||
Via.getManager().init();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user