From ac4895823e497ab6a7f94947e30330c5c23f1f45 Mon Sep 17 00:00:00 2001 From: Brady Date: Fri, 4 Oct 2019 15:52:08 -0500 Subject: [PATCH] Remove comms --- .../cabaletta/comms/BufferedConnection.java | 98 ---------- .../comms/ConstructingDeserializer.java | 60 ------ .../java/cabaletta/comms/IConnection.java | 28 --- .../cabaletta/comms/IMessageListener.java | 56 ------ .../cabaletta/comms/MessageDeserializer.java | 25 --- src/comms/java/cabaletta/comms/Pipe.java | 99 ---------- .../cabaletta/comms/SerializedConnection.java | 59 ------ .../cabaletta/comms/SocketConnection.java | 27 --- .../cabaletta/comms/downward/MessageChat.java | 48 ----- .../comms/downward/MessageClickSlot.java | 59 ------ .../downward/MessageComputationRequest.java | 62 ------- src/comms/java/cabaletta/comms/iMessage.java | 44 ----- .../upward/MessageComputationResponse.java | 72 ------- .../comms/upward/MessageEchestConfirmed.java | 51 ----- .../cabaletta/comms/upward/MessageStatus.java | 175 ------------------ 15 files changed, 963 deletions(-) delete mode 100644 src/comms/java/cabaletta/comms/BufferedConnection.java delete mode 100644 src/comms/java/cabaletta/comms/ConstructingDeserializer.java delete mode 100644 src/comms/java/cabaletta/comms/IConnection.java delete mode 100644 src/comms/java/cabaletta/comms/IMessageListener.java delete mode 100644 src/comms/java/cabaletta/comms/MessageDeserializer.java delete mode 100644 src/comms/java/cabaletta/comms/Pipe.java delete mode 100644 src/comms/java/cabaletta/comms/SerializedConnection.java delete mode 100644 src/comms/java/cabaletta/comms/SocketConnection.java delete mode 100644 src/comms/java/cabaletta/comms/downward/MessageChat.java delete mode 100644 src/comms/java/cabaletta/comms/downward/MessageClickSlot.java delete mode 100644 src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java delete mode 100644 src/comms/java/cabaletta/comms/iMessage.java delete mode 100644 src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java delete mode 100644 src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java delete mode 100644 src/comms/java/cabaletta/comms/upward/MessageStatus.java diff --git a/src/comms/java/cabaletta/comms/BufferedConnection.java b/src/comms/java/cabaletta/comms/BufferedConnection.java deleted file mode 100644 index f21a684c..00000000 --- a/src/comms/java/cabaletta/comms/BufferedConnection.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.EOFException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * Do you not like having a blocking "receiveMessage" thingy? - *

- * Do you prefer just being able to get a list of all messages received since the last tick? - *

- * If so, this class is for you! - * - * @author leijurv - */ -public class BufferedConnection implements IConnection { - private final IConnection wrapped; - private final LinkedBlockingQueue queue; - private volatile transient IOException thrownOnRead; - - public BufferedConnection(IConnection wrapped) { - this(wrapped, Integer.MAX_VALUE); // LinkedBlockingQueue accepts this as "no limit" - } - - public BufferedConnection(IConnection wrapped, int maxInternalQueueSize) { - this.wrapped = wrapped; - this.queue = new LinkedBlockingQueue<>(); - this.thrownOnRead = null; - new Thread(() -> { - try { - while (thrownOnRead == null) { - queue.put(wrapped.receiveMessage()); - } - } catch (IOException e) { - thrownOnRead = e; - } catch (InterruptedException e) { - thrownOnRead = new IOException("Interrupted while enqueueing", e); - } - }).start(); - } - - @Override - public void sendMessage(iMessage message) throws IOException { - wrapped.sendMessage(message); - } - - @Override - public iMessage receiveMessage() { - throw new UnsupportedOperationException("BufferedConnection can only be read from non-blockingly"); - } - - @Override - public void close() { - wrapped.close(); - thrownOnRead = new EOFException("Closed"); - } - - public List receiveMessagesNonBlocking() throws IOException { - ArrayList msgs = new ArrayList<>(); - queue.drainTo(msgs); // preserves order -- first message received will be first in this arraylist - if (msgs.isEmpty() && thrownOnRead != null) { - IOException up = new IOException("BufferedConnection wrapped", thrownOnRead); - throw up; - } - 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; - } else { - return new BufferedConnection(conn); - } - } -} diff --git a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java b/src/comms/java/cabaletta/comms/ConstructingDeserializer.java deleted file mode 100644 index fe7a3bf2..00000000 --- a/src/comms/java/cabaletta/comms/ConstructingDeserializer.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import cabaletta.comms.downward.MessageChat; -import cabaletta.comms.downward.MessageClickSlot; -import cabaletta.comms.downward.MessageComputationRequest; -import cabaletta.comms.upward.MessageComputationResponse; -import cabaletta.comms.upward.MessageEchestConfirmed; -import cabaletta.comms.upward.MessageStatus; - -import java.io.DataInputStream; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -public enum ConstructingDeserializer implements MessageDeserializer { - INSTANCE; - private final List> MSGS; - - ConstructingDeserializer() { - MSGS = new ArrayList<>(); - MSGS.add(MessageStatus.class); - MSGS.add(MessageChat.class); - MSGS.add(MessageComputationRequest.class); - MSGS.add(MessageComputationResponse.class); - MSGS.add(MessageEchestConfirmed.class); - MSGS.add(MessageClickSlot.class); - } - - @Override - public synchronized iMessage deserialize(DataInputStream in) throws IOException { - int type = ((int) in.readByte()) & 0xff; - try { - return MSGS.get(type).getConstructor(DataInputStream.class).newInstance(in); - } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException ex) { - throw new IOException("Unknown message type " + type, ex); - } - } - - public byte getHeader(Class klass) { - return (byte) MSGS.indexOf(klass); - } -} diff --git a/src/comms/java/cabaletta/comms/IConnection.java b/src/comms/java/cabaletta/comms/IConnection.java deleted file mode 100644 index 02046fe3..00000000 --- a/src/comms/java/cabaletta/comms/IConnection.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.IOException; - -public interface IConnection { - void sendMessage(iMessage message) throws IOException; - - iMessage receiveMessage() throws IOException; - - void close(); -} diff --git a/src/comms/java/cabaletta/comms/IMessageListener.java b/src/comms/java/cabaletta/comms/IMessageListener.java deleted file mode 100644 index 7d6b09c9..00000000 --- a/src/comms/java/cabaletta/comms/IMessageListener.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import cabaletta.comms.downward.MessageChat; -import cabaletta.comms.downward.MessageClickSlot; -import cabaletta.comms.downward.MessageComputationRequest; -import cabaletta.comms.upward.MessageComputationResponse; -import cabaletta.comms.upward.MessageEchestConfirmed; -import cabaletta.comms.upward.MessageStatus; - -public interface IMessageListener { - default void handle(MessageStatus message) { - unhandled(message); - } - - default void handle(MessageChat message) { - unhandled(message); - } - - default void handle(MessageComputationRequest message) { - unhandled(message); - } - - default void handle(MessageComputationResponse message) { - unhandled(message); - } - - default void handle(MessageEchestConfirmed message) { - unhandled(message); - } - - default void handle(MessageClickSlot message) { - unhandled(message); - } - - default void unhandled(iMessage msg) { - // can override this to throw UnsupportedOperationException, if you want to make sure you're handling everything - // default is to silently ignore messages without handlers - } -} \ No newline at end of file diff --git a/src/comms/java/cabaletta/comms/MessageDeserializer.java b/src/comms/java/cabaletta/comms/MessageDeserializer.java deleted file mode 100644 index 264a753d..00000000 --- a/src/comms/java/cabaletta/comms/MessageDeserializer.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.DataInputStream; -import java.io.IOException; - -public interface MessageDeserializer { - iMessage deserialize(DataInputStream in) throws IOException; -} diff --git a/src/comms/java/cabaletta/comms/Pipe.java b/src/comms/java/cabaletta/comms/Pipe.java deleted file mode 100644 index 42e28899..00000000 --- a/src/comms/java/cabaletta/comms/Pipe.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.EOFException; -import java.io.IOException; -import java.util.Optional; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * Do you want a socket to localhost without actually making a gross real socket to localhost? - */ -public class Pipe { - private final LinkedBlockingQueue> AtoB; - private final LinkedBlockingQueue> BtoA; - private final PipedConnection A; - private final PipedConnection B; - private volatile boolean closed; - - public Pipe() { - this.AtoB = new LinkedBlockingQueue<>(); - this.BtoA = new LinkedBlockingQueue<>(); - this.A = new PipedConnection(BtoA, AtoB); - this.B = new PipedConnection(AtoB, BtoA); - } - - public PipedConnection getA() { - return A; - } - - public PipedConnection getB() { - return B; - } - - public class PipedConnection implements IConnection { - private final LinkedBlockingQueue> in; - private final LinkedBlockingQueue> out; - - private PipedConnection(LinkedBlockingQueue> in, LinkedBlockingQueue> out) { - this.in = in; - this.out = out; - } - - @Override - public void sendMessage(iMessage message) throws IOException { - if (closed) { - throw new EOFException("Closed"); - } - try { - out.put(Optional.of(message)); - } catch (InterruptedException e) { - // this can never happen since the LinkedBlockingQueues are not constructed with a maximum capacity, see above - } - } - - @Override - public iMessage receiveMessage() throws IOException { - if (closed) { - throw new EOFException("Closed"); - } - try { - Optional t = in.take(); - if (!t.isPresent()) { - throw new EOFException("Closed"); - } - return t.get(); - } catch (InterruptedException e) { - // again, cannot happen - // but we have to throw something - throw new IllegalStateException(e); - } - } - - @Override - public void close() { - closed = true; - try { - AtoB.put(Optional.empty()); // unstick threads - BtoA.put(Optional.empty()); - } catch (InterruptedException e) { - } - } - } -} diff --git a/src/comms/java/cabaletta/comms/SerializedConnection.java b/src/comms/java/cabaletta/comms/SerializedConnection.java deleted file mode 100644 index 5ac482a9..00000000 --- a/src/comms/java/cabaletta/comms/SerializedConnection.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.*; - -public class SerializedConnection implements IConnection { - private final DataInputStream in; - private final DataOutputStream out; - private final MessageDeserializer deserializer; - - public SerializedConnection(InputStream in, OutputStream out) { - this(ConstructingDeserializer.INSTANCE, in, out); - } - - public SerializedConnection(MessageDeserializer d, InputStream in, OutputStream out) { - this.in = new DataInputStream(in); - this.out = new DataOutputStream(out); - this.deserializer = d; - } - - @Override - public synchronized void sendMessage(iMessage message) throws IOException { - message.writeHeader(out); - message.write(out); - } - - @Override - public iMessage receiveMessage() throws IOException { - return deserializer.deserialize(in); - } - - @Override - public void close() { - try { - in.close(); - } catch (IOException e) { - } - try { - out.close(); - } catch (IOException e) { - } - } -} \ No newline at end of file diff --git a/src/comms/java/cabaletta/comms/SocketConnection.java b/src/comms/java/cabaletta/comms/SocketConnection.java deleted file mode 100644 index 95bb83d5..00000000 --- a/src/comms/java/cabaletta/comms/SocketConnection.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.IOException; -import java.net.Socket; - -public class SocketConnection extends SerializedConnection { - public SocketConnection(Socket s) throws IOException { - super(s.getInputStream(), s.getOutputStream()); - } -} diff --git a/src/comms/java/cabaletta/comms/downward/MessageChat.java b/src/comms/java/cabaletta/comms/downward/MessageChat.java deleted file mode 100644 index be6b0f3b..00000000 --- a/src/comms/java/cabaletta/comms/downward/MessageChat.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.downward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class MessageChat implements iMessage { - - public final String msg; - - public MessageChat(DataInputStream in) throws IOException { - this.msg = in.readUTF(); - } - - public MessageChat(String msg) { - this.msg = msg; - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeUTF(msg); - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -} diff --git a/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java b/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java deleted file mode 100644 index 5357cee5..00000000 --- a/src/comms/java/cabaletta/comms/downward/MessageClickSlot.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.downward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class MessageClickSlot implements iMessage { - public final int windowId; - public final int slotId; - public final int mouseButton; - public final int clickType; // index into ClickType.values() - - public MessageClickSlot(DataInputStream in) throws IOException { - this.windowId = in.readInt(); - this.slotId = in.readInt(); - this.mouseButton = in.readInt(); - this.clickType = in.readInt(); - } - - public MessageClickSlot(int windowId, int slotId, int mouseButton, int clickType) { - this.windowId = windowId; - this.slotId = slotId; - this.mouseButton = mouseButton; - this.clickType = clickType; - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeInt(windowId); - out.writeInt(slotId); - out.writeInt(mouseButton); - out.writeInt(clickType); - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -} diff --git a/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java b/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java deleted file mode 100644 index c1e4f51a..00000000 --- a/src/comms/java/cabaletta/comms/downward/MessageComputationRequest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.downward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class MessageComputationRequest implements iMessage { - public final long computationID; - public final int startX; - public final int startY; - public final int startZ; - public final String goal; // TODO find a better way to do this lol - - public MessageComputationRequest(DataInputStream in) throws IOException { - this.computationID = in.readLong(); - this.startX = in.readInt(); - this.startY = in.readInt(); - this.startZ = in.readInt(); - this.goal = in.readUTF(); - } - - public MessageComputationRequest(long computationID, int startX, int startY, int startZ, String goal) { - this.computationID = computationID; - this.startX = startX; - this.startY = startY; - this.startZ = startZ; - this.goal = goal; - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeLong(computationID); - out.writeInt(startX); - out.writeInt(startY); - out.writeUTF(goal); - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -} diff --git a/src/comms/java/cabaletta/comms/iMessage.java b/src/comms/java/cabaletta/comms/iMessage.java deleted file mode 100644 index 7d00ab4c..00000000 --- a/src/comms/java/cabaletta/comms/iMessage.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms; - -import java.io.DataOutputStream; -import java.io.IOException; - -/** - * hell yeah - *

- *

- * dumb android users cant read this file - *

- * - * @author leijurv - */ -public interface iMessage { - void write(DataOutputStream out) throws IOException; - - default void writeHeader(DataOutputStream out) throws IOException { - out.writeByte(getHeader()); - } - - default byte getHeader() { - return ConstructingDeserializer.INSTANCE.getHeader(getClass()); - } - - void handle(IMessageListener listener); -} diff --git a/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java b/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java deleted file mode 100644 index a6d7ac1b..00000000 --- a/src/comms/java/cabaletta/comms/upward/MessageComputationResponse.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.upward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class MessageComputationResponse implements iMessage { - public final long computationID; - public final int pathLength; - public final double pathCost; - public final boolean endsInGoal; - public final int endX; - public final int endY; - public final int endZ; - - public MessageComputationResponse(DataInputStream in) throws IOException { - this.computationID = in.readLong(); - this.pathLength = in.readInt(); - this.pathCost = in.readDouble(); - this.endsInGoal = in.readBoolean(); - this.endX = in.readInt(); - this.endY = in.readInt(); - this.endZ = in.readInt(); - } - - public MessageComputationResponse(long computationID, int pathLength, double pathCost, boolean endsInGoal, int endX, int endY, int endZ) { - this.computationID = computationID; - this.pathLength = pathLength; - this.pathCost = pathCost; - this.endsInGoal = endsInGoal; - this.endX = endX; - this.endY = endY; - this.endZ = endZ; - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeLong(computationID); - out.writeInt(pathLength); - out.writeDouble(pathCost); - out.writeBoolean(endsInGoal); - out.writeInt(endX); - out.writeInt(endY); - out.writeInt(endZ); - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -} - diff --git a/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java b/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java deleted file mode 100644 index 8dc3797a..00000000 --- a/src/comms/java/cabaletta/comms/upward/MessageEchestConfirmed.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.upward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class MessageEchestConfirmed implements iMessage { - public final int slot; - public final String item; - - public MessageEchestConfirmed(DataInputStream in) throws IOException { - this.slot = in.readInt(); - this.item = in.readUTF(); - } - - public MessageEchestConfirmed(int slot, String item) { - this.slot = slot; - this.item = item; - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeInt(slot); - out.writeUTF(item); - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -} diff --git a/src/comms/java/cabaletta/comms/upward/MessageStatus.java b/src/comms/java/cabaletta/comms/upward/MessageStatus.java deleted file mode 100644 index a8ea5e3a..00000000 --- a/src/comms/java/cabaletta/comms/upward/MessageStatus.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package cabaletta.comms.upward; - -import cabaletta.comms.IMessageListener; -import cabaletta.comms.iMessage; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class MessageStatus implements iMessage { - - public final String playerUUID; - public final String serverIP; - public final double x; - public final double y; - public final double z; - public final float yaw; - public final float pitch; - public final boolean onGround; - public final float health; - public final float saturation; - public final int foodLevel; - public final int dimension; - public final int pathStartX; - public final int pathStartY; - public final int pathStartZ; - public final boolean hasCurrentSegment; - public final boolean hasNextSegment; - public final boolean calcInProgress; - public final double ticksRemainingInCurrent; - public final boolean calcFailedLastTick; - public final boolean safeToCancel; - public final String currentGoal; - public final String currentProcess; - public final List mainInventory; - public final List armor; - public final String offHand; - public final int windowId; - public final boolean eChestOpen; - - public MessageStatus(DataInputStream in) throws IOException { - this.playerUUID = in.readUTF(); - this.serverIP = in.readUTF(); - this.x = in.readDouble(); - this.y = in.readDouble(); - this.z = in.readDouble(); - this.yaw = in.readFloat(); - this.pitch = in.readFloat(); - this.onGround = in.readBoolean(); - this.health = in.readFloat(); - this.saturation = in.readFloat(); - this.foodLevel = in.readInt(); - this.dimension = in.readInt(); - this.pathStartX = in.readInt(); - this.pathStartY = in.readInt(); - this.pathStartZ = in.readInt(); - this.hasCurrentSegment = in.readBoolean(); - this.hasNextSegment = in.readBoolean(); - this.calcInProgress = in.readBoolean(); - this.ticksRemainingInCurrent = in.readDouble(); - this.calcFailedLastTick = in.readBoolean(); - this.safeToCancel = in.readBoolean(); - this.currentGoal = in.readUTF(); - this.currentProcess = in.readUTF(); - this.mainInventory = readList(36, in); - this.armor = readList(4, in); - this.offHand = in.readUTF(); - this.windowId = in.readInt(); - this.eChestOpen = in.readBoolean(); - } - - public MessageStatus(String playerUUID, String serverIP, double x, double y, double z, float yaw, float pitch, boolean onGround, float health, float saturation, int foodLevel, int dimension, int pathStartX, int pathStartY, int pathStartZ, boolean hasCurrentSegment, boolean hasNextSegment, boolean calcInProgress, double ticksRemainingInCurrent, boolean calcFailedLastTick, boolean safeToCancel, String currentGoal, String currentProcess, List mainInventory, List armor, String offHand, int windowId, boolean eChestOpen) { - this.playerUUID = playerUUID; - this.serverIP = serverIP; - this.x = x; - this.y = y; - this.z = z; - this.yaw = yaw; - this.pitch = pitch; - this.onGround = onGround; - this.health = health; - this.saturation = saturation; - this.foodLevel = foodLevel; - this.dimension = dimension; - this.pathStartX = pathStartX; - this.pathStartY = pathStartY; - this.pathStartZ = pathStartZ; - this.hasCurrentSegment = hasCurrentSegment; - this.hasNextSegment = hasNextSegment; - this.calcInProgress = calcInProgress; - this.ticksRemainingInCurrent = ticksRemainingInCurrent; - this.calcFailedLastTick = calcFailedLastTick; - this.safeToCancel = safeToCancel; - this.currentGoal = currentGoal; - this.currentProcess = currentProcess; - this.mainInventory = mainInventory; - this.armor = armor; - this.offHand = offHand; - this.windowId = windowId; - this.eChestOpen = eChestOpen; - if (mainInventory.size() != 36 || armor.size() != 4) { - throw new IllegalStateException(); - } - } - - @Override - public void write(DataOutputStream out) throws IOException { - out.writeUTF(playerUUID); - out.writeUTF(serverIP); - out.writeDouble(x); - out.writeDouble(y); - out.writeDouble(z); - out.writeFloat(yaw); - out.writeFloat(pitch); - out.writeBoolean(onGround); - out.writeFloat(health); - out.writeFloat(saturation); - out.writeInt(foodLevel); - out.writeInt(dimension); - out.writeInt(pathStartX); - out.writeInt(pathStartY); - out.writeInt(pathStartZ); - out.writeBoolean(hasCurrentSegment); - out.writeBoolean(hasNextSegment); - out.writeBoolean(calcInProgress); - out.writeDouble(ticksRemainingInCurrent); - out.writeBoolean(calcFailedLastTick); - out.writeBoolean(safeToCancel); - out.writeUTF(currentGoal); - out.writeUTF(currentProcess); - write(mainInventory, out); - write(armor, out); - out.writeUTF(offHand); - out.writeInt(windowId); - out.writeBoolean(eChestOpen); - } - - private static List readList(int length, DataInputStream in) throws IOException { - ArrayList result = new ArrayList<>(); - for (int i = 0; i < length; i++) { - result.add(in.readUTF()); - } - return result; - } - - private static void write(List list, DataOutputStream out) throws IOException { - for (String str : list) { - out.writeUTF(str); - } - } - - @Override - public void handle(IMessageListener listener) { - listener.handle(this); - } -}