Skip to content

Commit

Permalink
Add missing item info to NetworkItem sent in printjson packets.
Browse files Browse the repository at this point in the history
add a helper method to get plain text of printjson packets.
clean up some of the bitflags.
  • Loading branch information
KonoTyran committed Jul 31, 2024
1 parent 2bed5a9 commit a96a30c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.koifysh</groupId>
<artifactId>archipelago-client</artifactId>
<version>0.1.18</version>
<version>0.1.19</version>

<name>Archipelago Java Library</name>
<description>Library to connect to an Archipelago Server</description>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/dev/koifysh/archipelago/Client.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -450,15 +448,15 @@ public Set<String> 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() {
return itemsHandlingFlags;
}

/**
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* <br>
* 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.
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/dev/koifysh/archipelago/NetworkItemFlags.java
Original file line number Diff line number Diff line change
@@ -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;
}
24 changes: 24 additions & 0 deletions src/main/java/dev/koifysh/archipelago/NetworkPlayerFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.koifysh.archipelago;

/**
* Flags that will tell you more about the slot type.<br>
* {@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;
}
8 changes: 8 additions & 0 deletions src/main/java/dev/koifysh/archipelago/Print/APPrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
8 changes: 7 additions & 1 deletion src/main/java/dev/koifysh/archipelago/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/koifysh/archipelago/parts/NetworkItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.koifysh.archipelago.parts;

import com.google.gson.annotations.SerializedName;
import dev.koifysh.archipelago.NetworkItemFlags;

public class NetworkItem {

Expand All @@ -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;
Expand All @@ -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
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/dev/koifysh/archipelago/parts/NetworkSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,6 @@ public class NetworkSlot {
@SerializedName("type")
public int type;


/**
* Flags that will tell you more about the slot type.<br>
* {@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;
Expand Down

0 comments on commit a96a30c

Please sign in to comment.