Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-20 06:50:08 +01:00
Add runnable list to be executed before the full init
Dieser Commit ist enthalten in:
Ursprung
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.protocols.protocol1_9to1_8.ViaIdleThread;
|
||||||
import us.myles.ViaVersion.update.UpdateUtil;
|
import us.myles.ViaVersion.update.UpdateUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -28,6 +30,7 @@ public class ViaManager {
|
|||||||
private final ViaCommandHandler commandHandler;
|
private final ViaCommandHandler commandHandler;
|
||||||
private final ViaPlatformLoader loader;
|
private final ViaPlatformLoader loader;
|
||||||
private final Set<String> subPlatforms = new HashSet<>();
|
private final Set<String> subPlatforms = new HashSet<>();
|
||||||
|
private List<Runnable> enableListeners = new ArrayList<>();
|
||||||
private TaskId mappingLoadingTask;
|
private TaskId mappingLoadingTask;
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
|
|
||||||
@ -48,10 +51,13 @@ public class ViaManager {
|
|||||||
platform.onReload();
|
platform.onReload();
|
||||||
}
|
}
|
||||||
// Check for updates
|
// Check for updates
|
||||||
if (platform.getConf().isCheckForUpdates())
|
if (platform.getConf().isCheckForUpdates()) {
|
||||||
UpdateUtil.sendUpdateMessage();
|
UpdateUtil.sendUpdateMessage();
|
||||||
|
}
|
||||||
|
|
||||||
// Force class load
|
// Force class load
|
||||||
ProtocolRegistry.init();
|
ProtocolRegistry.init();
|
||||||
|
|
||||||
// Inject
|
// Inject
|
||||||
try {
|
try {
|
||||||
injector.inject();
|
injector.inject();
|
||||||
@ -60,11 +66,17 @@ public class ViaManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark as injected
|
// Mark as injected
|
||||||
System.setProperty("ViaVersion", platform.getPluginVersion());
|
System.setProperty("ViaVersion", platform.getPluginVersion());
|
||||||
|
|
||||||
|
for (Runnable listener : enableListeners) {
|
||||||
|
listener.run();
|
||||||
|
}
|
||||||
|
enableListeners = null;
|
||||||
|
|
||||||
// If successful
|
// If successful
|
||||||
platform.runSync(this::onServerLoaded);
|
platform.runSync(this::onServerLoaded);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onServerLoaded() {
|
public void onServerLoaded() {
|
||||||
@ -195,6 +207,15 @@ public class ViaManager {
|
|||||||
return platform.getConnectionManager().getConnectedClient(playerUUID);
|
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 {
|
public static final class ViaManagerBuilder {
|
||||||
private ViaPlatform<?> platform;
|
private ViaPlatform<?> platform;
|
||||||
private ViaInjector injector;
|
private ViaInjector injector;
|
||||||
|
@ -5,7 +5,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class InformativeException extends Exception {
|
public class InformativeException extends Exception {
|
||||||
private final Map<String, Object> info = new HashMap<>();
|
private final Map<String, Object> info = new HashMap<>();
|
||||||
private int sources = 0;
|
private int sources;
|
||||||
|
|
||||||
public InformativeException(Throwable cause) {
|
public InformativeException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
@ -82,7 +83,10 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
|||||||
if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
|
if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
|
||||||
MappingDataLoader.enableMappingsCache();
|
MappingDataLoader.enableMappingsCache();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(order = PostOrder.LAST)
|
||||||
|
public void onProxyLateInit(ProxyInitializeEvent e) {
|
||||||
Via.getManager().init();
|
Via.getManager().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren