From 11e44acf65d6abb7697130195f1dff4f240ab0fa Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 23 Nov 2018 16:35:03 -0800 Subject: [PATCH] helper to handle pending msgs --- src/comms/java/cabaletta/comms/BufferedConnection.java | 4 ++++ src/main/java/baritone/behavior/ControllerBehavior.java | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/comms/java/cabaletta/comms/BufferedConnection.java b/src/comms/java/cabaletta/comms/BufferedConnection.java index 6fb07998..f21a684c 100644 --- a/src/comms/java/cabaletta/comms/BufferedConnection.java +++ b/src/comms/java/cabaletta/comms/BufferedConnection.java @@ -84,6 +84,10 @@ public class BufferedConnection implements IConnection { return msgs; } + public void handleAllPendingMessages(IMessageListener listener) throws IOException { + receiveMessagesNonBlocking().forEach(msg -> msg.handle(listener)); + } + public static BufferedConnection makeBuffered(IConnection conn) { if (conn instanceof BufferedConnection) { return (BufferedConnection) conn; diff --git a/src/main/java/baritone/behavior/ControllerBehavior.java b/src/main/java/baritone/behavior/ControllerBehavior.java index 1c18bf07..90247834 100644 --- a/src/main/java/baritone/behavior/ControllerBehavior.java +++ b/src/main/java/baritone/behavior/ControllerBehavior.java @@ -31,7 +31,6 @@ import cabaletta.comms.upward.MessageStatus; import net.minecraft.util.math.BlockPos; import java.io.IOException; -import java.util.List; public class ControllerBehavior extends Behavior implements IMessageListener { public ControllerBehavior(Baritone baritone) { @@ -82,8 +81,7 @@ public class ControllerBehavior extends Behavior implements IMessageListener { return; } try { - List msgs = conn.receiveMessagesNonBlocking(); - msgs.forEach(msg -> msg.handle(this)); + conn.handleAllPendingMessages(this); } catch (IOException e) { e.printStackTrace(); disconnect();