mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 13:45:22 +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.lang.reflect.Method;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import net.sf.cglib.proxy.Factory;
|
import net.sf.cglib.proxy.Factory;
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ abstract class PlayerInjector {
|
|||||||
protected ErrorReporter reporter;
|
protected ErrorReporter reporter;
|
||||||
|
|
||||||
// Scheduled action on the next packet event
|
// Scheduled action on the next packet event
|
||||||
protected Runnable scheduledAction;
|
protected Callable<Boolean> scheduledAction;
|
||||||
|
|
||||||
// Whether or not the injector has been cleaned
|
// Whether or not the injector has been cleaned
|
||||||
private boolean clean;
|
private boolean clean;
|
||||||
@ -519,9 +520,16 @@ abstract class PlayerInjector {
|
|||||||
|
|
||||||
// Hack #1: Handle a single scheduled action
|
// Hack #1: Handle a single scheduled action
|
||||||
if (scheduledAction != null) {
|
if (scheduledAction != null) {
|
||||||
scheduledAction.run();
|
try {
|
||||||
scheduledAction = null;
|
if (scheduledAction.call()) {
|
||||||
|
scheduledAction = null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
reporter.reportDetailed(this, "Cannot perform hack #1.", e, scheduledAction, packet);
|
||||||
|
scheduledAction = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack #2
|
// Hack #2
|
||||||
if (updateOnLogin) {
|
if (updateOnLogin) {
|
||||||
if (id == Packets.Server.LOGIN) {
|
if (id == Packets.Server.LOGIN) {
|
||||||
@ -595,9 +603,11 @@ abstract class PlayerInjector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule an action to occur on the next sent packet.
|
* 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.
|
* @param action - action to execute.
|
||||||
*/
|
*/
|
||||||
public void scheduleAction(Runnable action) {
|
public void scheduleAction(Callable<Boolean> action) {
|
||||||
scheduledAction = action;
|
scheduledAction = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import java.net.Socket;
|
|||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -663,10 +664,17 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
|
|||||||
|
|
||||||
// Update the DataInputStream
|
// Update the DataInputStream
|
||||||
if (injector != null) {
|
if (injector != null) {
|
||||||
injector.scheduleAction(new Runnable() {
|
injector.scheduleAction(new Callable<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public Boolean call() throws Exception {
|
||||||
dataInputLookup.put(injector.getInputStream(false), injector);
|
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