3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Merge pull request #1769 from KennyTV/abstraction

Add runnable list to be executed before the full init
Dieser Commit ist enthalten in:
Myles 2020-05-09 09:28:11 +01:00 committet von GitHub
Commit 3079663ba9
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 28 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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);

Datei anzeigen

@ -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();
}