helper to handle pending msgs

This commit is contained in:
Leijurv 2018-11-23 16:35:03 -08:00
parent 16fec4a1a0
commit 11e44acf65
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
2 changed files with 5 additions and 3 deletions

View File

@ -84,6 +84,10 @@ public class BufferedConnection implements IConnection {
return msgs; return msgs;
} }
public void handleAllPendingMessages(IMessageListener listener) throws IOException {
receiveMessagesNonBlocking().forEach(msg -> msg.handle(listener));
}
public static BufferedConnection makeBuffered(IConnection conn) { public static BufferedConnection makeBuffered(IConnection conn) {
if (conn instanceof BufferedConnection) { if (conn instanceof BufferedConnection) {
return (BufferedConnection) conn; return (BufferedConnection) conn;

View File

@ -31,7 +31,6 @@ import cabaletta.comms.upward.MessageStatus;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.io.IOException; import java.io.IOException;
import java.util.List;
public class ControllerBehavior extends Behavior implements IMessageListener { public class ControllerBehavior extends Behavior implements IMessageListener {
public ControllerBehavior(Baritone baritone) { public ControllerBehavior(Baritone baritone) {
@ -82,8 +81,7 @@ public class ControllerBehavior extends Behavior implements IMessageListener {
return; return;
} }
try { try {
List<iMessage> msgs = conn.receiveMessagesNonBlocking(); conn.handleAllPendingMessages(this);
msgs.forEach(msg -> msg.handle(this));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
disconnect(); disconnect();