mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 05:35:28 +01:00
Properly handle reloads on Spigot.
The code is getting uglier and uglier ...
This commit is contained in:
parent
a4f81e5e9f
commit
47a5382709
@ -22,6 +22,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -272,14 +273,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
delayed.setAsynchronousManager(asyncManager);
|
||||
asyncManager.setManager(delayed);
|
||||
|
||||
Futures.addCallback(BukkitFutures.nextEvent(library, WorldInitEvent.class), new FutureCallback<WorldInitEvent>() {
|
||||
final Callable<Object> registerSpigot = new Callable<Object>() {
|
||||
@Override
|
||||
public void onSuccess(WorldInitEvent event) {
|
||||
// Nevermind
|
||||
if (delayed.isClosed())
|
||||
return;
|
||||
|
||||
try {
|
||||
public Object call() throws Exception {
|
||||
// Now we are probably able to check for Netty
|
||||
InjectedServerConnection inspector = new InjectedServerConnection(reporter, null, server, null);
|
||||
Object connection = inspector.getServerConnection();
|
||||
@ -291,9 +287,24 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
delayed.setDelegate(new PacketFilterManager(
|
||||
classLoader, server, library, asyncManager, mcVersion, unhookTask, reporter, useNetty)
|
||||
);
|
||||
|
||||
// Reference this manager directly
|
||||
asyncManager.setManager(delayed.getDelegate());
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// If the server hasn't loaded yet - wait
|
||||
if (server.getWorlds().size() == 0) {
|
||||
Futures.addCallback(BukkitFutures.nextEvent(library, WorldInitEvent.class), new FutureCallback<WorldInitEvent>() {
|
||||
@Override
|
||||
public void onSuccess(WorldInitEvent event) {
|
||||
// Nevermind
|
||||
if (delayed.isClosed())
|
||||
return;
|
||||
|
||||
try {
|
||||
registerSpigot.call();
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
@ -305,6 +316,15 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// Do it now
|
||||
try {
|
||||
registerSpigot.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Let plugins use this version instead
|
||||
return delayed;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user