forked from chipmunkmc/chipmunkbot
Optimize stuff
This commit is contained in:
parent
1eb1bbba08
commit
c0b4fb1a7e
4 changed files with 16 additions and 4 deletions
|
@ -61,14 +61,17 @@ public class Client {
|
|||
|
||||
if (reconnectDelay < 0) return;
|
||||
|
||||
Timer timer = new Timer();
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run () {
|
||||
reconnect();
|
||||
|
||||
timer.purge();
|
||||
}
|
||||
};
|
||||
|
||||
new Timer().schedule(task, reconnectDelay);
|
||||
timer.schedule(task, reconnectDelay);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -157,14 +157,17 @@ public class CommandCore extends SessionAdapter {
|
|||
|
||||
CompletableFuture<CompoundTag> future = new CompletableFuture<CompoundTag>();
|
||||
|
||||
final Timer timer = new Timer();
|
||||
final TimerTask queryTask = new TimerTask() {
|
||||
public void run () {
|
||||
client.query().block(currentBlock)
|
||||
.thenApply(tag -> { future.complete(tag); return tag; });
|
||||
|
||||
timer.purge();
|
||||
}
|
||||
};
|
||||
|
||||
new Timer().schedule(queryTask, 50);
|
||||
timer.schedule(queryTask, 50);
|
||||
|
||||
return future;
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ public class QueryPlugin extends SessionAdapter {
|
|||
}
|
||||
|
||||
public void packetReceived (Session session, ClientboundTagQueryPacket packet) {
|
||||
transactions.get(packet.getTransactionId()).complete(packet.getNbt());
|
||||
final CompletableFuture<CompoundTag> future = transactions.get(packet.getTransactionId());
|
||||
if (future == null) return;
|
||||
future.complete(packet.getNbt());
|
||||
transactions.remove(future);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ public class TabCompletePlugin extends SessionAdapter {
|
|||
}
|
||||
|
||||
public void packetReceived (Session session, ClientboundCommandSuggestionsPacket packet) {
|
||||
transactions.get(packet.getTransactionId()).complete(packet);
|
||||
final CompletableFuture<ClientboundCommandSuggestionsPacket> future = transactions.get(packet.getTransactionId());
|
||||
if (future == null) return;
|
||||
future.complete(packet);
|
||||
transactions.remove(future);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue