mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 19:46:33 +01:00
Retry again if the hack isn't ready.
This commit is contained in:
parent
b8b39b4785
commit
3ae10d9123
@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.sf.cglib.proxy.Factory;
|
||||
|
||||
@ -100,7 +101,7 @@ abstract class PlayerInjector {
|
||||
protected ErrorReporter reporter;
|
||||
|
||||
// Scheduled action on the next packet event
|
||||
protected Runnable scheduledAction;
|
||||
protected Callable<Boolean> scheduledAction;
|
||||
|
||||
// Whether or not the injector has been cleaned
|
||||
private boolean clean;
|
||||
@ -519,9 +520,16 @@ abstract class PlayerInjector {
|
||||
|
||||
// Hack #1: Handle a single scheduled action
|
||||
if (scheduledAction != null) {
|
||||
scheduledAction.run();
|
||||
scheduledAction = null;
|
||||
try {
|
||||
if (scheduledAction.call()) {
|
||||
scheduledAction = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
reporter.reportDetailed(this, "Cannot perform hack #1.", e, scheduledAction, packet);
|
||||
scheduledAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Hack #2
|
||||
if (updateOnLogin) {
|
||||
if (id == Packets.Server.LOGIN) {
|
||||
@ -595,9 +603,11 @@ abstract class PlayerInjector {
|
||||
|
||||
/**
|
||||
* Schedule an action to occur on the next sent packet.
|
||||
* <p>
|
||||
* If the callable returns TRUE, the action is removed.
|
||||
* @param action - action to execute.
|
||||
*/
|
||||
public void scheduleAction(Runnable action) {
|
||||
public void scheduleAction(Callable<Boolean> action) {
|
||||
scheduledAction = action;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.Server;
|
||||
@ -663,10 +664,17 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
||||
|
||||
// Update the DataInputStream
|
||||
if (injector != null) {
|
||||
injector.scheduleAction(new Runnable() {
|
||||
injector.scheduleAction(new Callable<Boolean>() {
|
||||
@Override
|
||||
public void run() {
|
||||
dataInputLookup.put(injector.getInputStream(false), injector);
|
||||
public Boolean call() throws Exception {
|
||||
DataInputStream inputStream = injector.getInputStream(false);
|
||||
|
||||
if (inputStream != null) {
|
||||
dataInputLookup.put(inputStream, injector);
|
||||
return true;
|
||||
}
|
||||
// Try again
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user