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;
|
if (reconnectDelay < 0) return;
|
||||||
|
|
||||||
|
Timer timer = new Timer();
|
||||||
TimerTask task = new TimerTask() {
|
TimerTask task = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
reconnect();
|
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>();
|
CompletableFuture<CompoundTag> future = new CompletableFuture<CompoundTag>();
|
||||||
|
|
||||||
|
final Timer timer = new Timer();
|
||||||
final TimerTask queryTask = new TimerTask() {
|
final TimerTask queryTask = new TimerTask() {
|
||||||
public void run () {
|
public void run () {
|
||||||
client.query().block(currentBlock)
|
client.query().block(currentBlock)
|
||||||
.thenApply(tag -> { future.complete(tag); return tag; });
|
.thenApply(tag -> { future.complete(tag); return tag; });
|
||||||
|
|
||||||
|
timer.purge();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new Timer().schedule(queryTask, 50);
|
timer.schedule(queryTask, 50);
|
||||||
|
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,9 @@ public class QueryPlugin extends SessionAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (Session session, ClientboundTagQueryPacket packet) {
|
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) {
|
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