From a96a30ce10e894620877892c93ac8289e7fe20db Mon Sep 17 00:00:00 2001 From: Kono Tyran Date: Wed, 31 Jul 2024 11:30:29 -0700 Subject: [PATCH] Add missing item info to NetworkItem sent in printjson packets. add a helper method to get plain text of printjson packets. clean up some of the bitflags. --- pom.xml | 2 +- .../java/dev/koifysh/archipelago/Client.java | 6 ++--- ...ItemFlags.java => ItemsHandlingFlags.java} | 2 +- .../koifysh/archipelago/NetworkItemFlags.java | 18 +++++++++++++ .../archipelago/NetworkPlayerFlags.java | 24 +++++++++++++++++ .../koifysh/archipelago/Print/APPrint.java | 8 ++++++ .../dev/koifysh/archipelago/WebSocket.java | 8 +++++- .../archipelago/parts/NetworkItem.java | 5 ++-- .../archipelago/parts/NetworkSlot.java | 26 ------------------- 9 files changed, 64 insertions(+), 35 deletions(-) rename src/main/java/dev/koifysh/archipelago/{ItemFlags.java => ItemsHandlingFlags.java} (95%) create mode 100644 src/main/java/dev/koifysh/archipelago/NetworkItemFlags.java create mode 100644 src/main/java/dev/koifysh/archipelago/NetworkPlayerFlags.java diff --git a/pom.xml b/pom.xml index 4522bb5..c3b180f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.koifysh archipelago-client - 0.1.18 + 0.1.19 Archipelago Java Library Library to connect to an Archipelago Server diff --git a/src/main/java/dev/koifysh/archipelago/Client.java b/src/main/java/dev/koifysh/archipelago/Client.java index d093885..5e45a40 100644 --- a/src/main/java/dev/koifysh/archipelago/Client.java +++ b/src/main/java/dev/koifysh/archipelago/Client.java @@ -1,11 +1,9 @@ package dev.koifysh.archipelago; -import dev.koifysh.archipelago.Print.APPrint; import dev.koifysh.archipelago.events.RetrievedEvent; import dev.koifysh.archipelago.network.server.ConnectUpdatePacket; import dev.koifysh.archipelago.network.server.RoomInfoPacket; import dev.koifysh.archipelago.parts.DataPackage; -import dev.koifysh.archipelago.parts.NetworkItem; import dev.koifysh.archipelago.parts.NetworkSlot; import dev.koifysh.archipelago.parts.Version; import dev.koifysh.archipelago.network.client.*; @@ -450,7 +448,7 @@ public Set getTags() { } /** - * fetch the itemflags that have been set, bitwise Or against {@link ItemFlags} to read. + * fetch the itemflags that have been set, bitwise Or against {@link ItemsHandlingFlags} to read. * @return items handling int. */ public int getItemsHandlingFlags() { @@ -458,7 +456,7 @@ public int getItemsHandlingFlags() { } /** - * fetch the itemflags that have been set, bitwise Or against {@link ItemFlags} to read. + * fetch the itemflags that have been set, bitwise Or against {@link ItemsHandlingFlags} to read. */ public void setItemsHandlingFlags(int itemsHandlingFlags) { this.itemsHandlingFlags = itemsHandlingFlags; diff --git a/src/main/java/dev/koifysh/archipelago/ItemFlags.java b/src/main/java/dev/koifysh/archipelago/ItemsHandlingFlags.java similarity index 95% rename from src/main/java/dev/koifysh/archipelago/ItemFlags.java rename to src/main/java/dev/koifysh/archipelago/ItemsHandlingFlags.java index 2c8260e..d634c1c 100644 --- a/src/main/java/dev/koifysh/archipelago/ItemFlags.java +++ b/src/main/java/dev/koifysh/archipelago/ItemsHandlingFlags.java @@ -5,7 +5,7 @@ *
* Current item flags: {@link #SEND_ITEMS} {@link #SEND_OWN_ITEMS} {@link #SEND_STARTING_INVENTORY} */ -public class ItemFlags { +public class ItemsHandlingFlags { /** * Tells the server to send you items from other worlds. diff --git a/src/main/java/dev/koifysh/archipelago/NetworkItemFlags.java b/src/main/java/dev/koifysh/archipelago/NetworkItemFlags.java new file mode 100644 index 0000000..4f9b6da --- /dev/null +++ b/src/main/java/dev/koifysh/archipelago/NetworkItemFlags.java @@ -0,0 +1,18 @@ +package dev.koifysh.archipelago; + +public class NetworkItemFlags { + /** + * If set, indicates the item can unlock logical advancement + */ + public final static int ADVANCEMENT = 0b001; + + /** + * If set, indicates the item is important but not in a way that unlocks advancement + */ + public final static int USEFUL = 0b010; + + /** + * If set, indicates the item is a trap + */ + public final static int TRAP = 0b100; +} diff --git a/src/main/java/dev/koifysh/archipelago/NetworkPlayerFlags.java b/src/main/java/dev/koifysh/archipelago/NetworkPlayerFlags.java new file mode 100644 index 0000000..812b07f --- /dev/null +++ b/src/main/java/dev/koifysh/archipelago/NetworkPlayerFlags.java @@ -0,0 +1,24 @@ +package dev.koifysh.archipelago; + +/** + * Flags that will tell you more about the slot type.
+ * {@link #SPECTATOR}, + * {@link #PLAYER}, + * {@link #GROUP} + */ +public class NetworkPlayerFlags { + /** + * If set, indicates the slot is a spectator + */ + public final static int SPECTATOR = 0b001; + + /** + * If set, indicates the slot is a player + */ + public final static int PLAYER = 0b010; + + /** + * If set, indicates the slot is a group. + */ + public final static int GROUP = 0b100; +} diff --git a/src/main/java/dev/koifysh/archipelago/Print/APPrint.java b/src/main/java/dev/koifysh/archipelago/Print/APPrint.java index 9462b11..ceca8f6 100644 --- a/src/main/java/dev/koifysh/archipelago/Print/APPrint.java +++ b/src/main/java/dev/koifysh/archipelago/Print/APPrint.java @@ -35,4 +35,12 @@ public class APPrint { @SerializedName("countdown") public int countdown; + public String getPlainText() { + StringBuilder sb = new StringBuilder(); + for (APPrintPart part : parts) { + sb.append(part.text); + } + return sb.toString(); + } + } diff --git a/src/main/java/dev/koifysh/archipelago/WebSocket.java b/src/main/java/dev/koifysh/archipelago/WebSocket.java index a66c191..40f9142 100644 --- a/src/main/java/dev/koifysh/archipelago/WebSocket.java +++ b/src/main/java/dev/koifysh/archipelago/WebSocket.java @@ -105,7 +105,7 @@ public void onMessage(String message) { client.setTeam(connectedPacket.team); client.setSlot(connectedPacket.slot); - connectedPacket.slotInfo.put(0, new NetworkSlot("Archipelago", "Archipelago", NetworkSlot.flags.SPECTATOR)); + connectedPacket.slotInfo.put(0, new NetworkSlot("Archipelago", "Archipelago", NetworkPlayerFlags.SPECTATOR)); client.setSlotInfo(connectedPacket.slotInfo); client.getRoomInfo().networkPlayers.addAll(connectedPacket.players); @@ -174,6 +174,12 @@ else if (part.type == APPrintType.locationID) { } } + if (print.item != null) { + print.item.itemName = client.getDataPackage().getItem(print.item.itemID, client.getSlotInfo().get(print.item.playerID).game); + print.item.locationName = client.getDataPackage().getLocation(print.item.locationID, client.getSlotInfo().get(print.item.playerID).game); + print.item.playerName = client.getRoomInfo().getPlayer(client.getTeam(), print.item.playerID).alias; + } + client.getEventManager().callEvent(new PrintJSONEvent(print, print.type, print.receiving, print.item)); break; diff --git a/src/main/java/dev/koifysh/archipelago/parts/NetworkItem.java b/src/main/java/dev/koifysh/archipelago/parts/NetworkItem.java index cdbcffe..71a4dbd 100644 --- a/src/main/java/dev/koifysh/archipelago/parts/NetworkItem.java +++ b/src/main/java/dev/koifysh/archipelago/parts/NetworkItem.java @@ -1,6 +1,7 @@ package dev.koifysh.archipelago.parts; import com.google.gson.annotations.SerializedName; +import dev.koifysh.archipelago.NetworkItemFlags; public class NetworkItem { @@ -14,7 +15,7 @@ public class NetworkItem { public int playerID; /** - * Bit flags that tell you information about the item. bitwise OR them with {@link flags} to read. + * Bit flags that tell you information about the item. bitwise AND them with {@link NetworkItemFlags} to read. */ @SerializedName("flags") public int flags; @@ -30,7 +31,7 @@ public class NetworkItem { * {@link #USEFUL}, * {@link #TRAP} */ - public static class flags { + public static class Flags { /** * If set, indicates the item can unlock logical advancement diff --git a/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java b/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java index 813d210..c812f94 100644 --- a/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java +++ b/src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java @@ -13,32 +13,6 @@ public class NetworkSlot { @SerializedName("type") public int type; - - /** - * Flags that will tell you more about the slot type.
- * {@link #SPECTATOR}, - * {@link #PLAYER}, - * {@link #GROUP} - */ - public static class flags { - - /** - * If set, indicates the slot is a spectator - */ - public final static int SPECTATOR = 0b001; - - /** - * If set, indicates the slot is a player - */ - public final static int PLAYER = 0b010; - - /** - * If set, indicates the slot is a group. - */ - public final static int GROUP = 0b100; - - } - public NetworkSlot(String name, String game, int type) { this.name = name; this.game = game;