From 649e7a6367bb4228d4a8fb3b8a1ddfbe810e8b2c Mon Sep 17 00:00:00 2001 From: Charlesfire Date: Wed, 17 Jan 2024 12:32:30 -0500 Subject: [PATCH 1/2] Fixed locations missing from locationIdToName --- .../archipelago/client/parts/DataPackage.java | 61 +++++++++---------- .../gg/archipelago/client/parts/Game.java | 18 +++++- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/main/java/gg/archipelago/client/parts/DataPackage.java b/src/main/java/gg/archipelago/client/parts/DataPackage.java index 4f7da0b..27a6af3 100644 --- a/src/main/java/gg/archipelago/client/parts/DataPackage.java +++ b/src/main/java/gg/archipelago/client/parts/DataPackage.java @@ -23,27 +23,18 @@ public class DataPackage implements Serializable { public String uuid = UUID.randomUUID().toString(); public String getItem(long itemID) { - for (Map.Entry game : games.entrySet()) { - for (Map.Entry item : game.getValue().itemNameToId.entrySet()) { - if(item.getValue() == itemID) - return item.getKey(); - } + if(!itemIdToName.containsKey(itemID)) { + return String.format("Unknown Item [%d]", itemID); } - return String.format("Unknown Item [%d]", itemID); + + return itemIdToName.get(itemID); } public String getLocation(long locationID) { - if(locationIdToName.containsKey(locationID)) - return locationIdToName.get(locationID); - for (Map.Entry game : games.entrySet()) { - for (Map.Entry location : game.getValue().locationNameToId.entrySet()) { - if(location.getValue() == locationID) { - locationIdToName.put(locationID, location.getKey()); - return location.getKey(); - } - } - } - return String.format("Unknown Location [%d]", locationID); + if(!locationIdToName.containsKey(locationID)) + return String.format("Unknown Location [%d]", locationID); + + return locationIdToName.get(locationID); } public Map getVersions() { @@ -57,13 +48,6 @@ public HashMap getGames() { } public HashMap getItems() { - if(itemIdToName.isEmpty()) { - for (Map.Entry gameEntry : games.entrySet()) { - for (Map.Entry items : gameEntry.getValue().itemNameToId.entrySet()) { - itemIdToName.put(items.getValue(), items.getKey()); - } - } - } return itemIdToName; } @@ -79,14 +63,7 @@ public HashMap getItemsForGame(String game) { } public HashMap getLocations() { - if(locationIdToName.isEmpty()) { - for (Map.Entry gameEntry : games.entrySet()) { - for (Map.Entry locations : gameEntry.getValue().locationNameToId.entrySet()) { - itemIdToName.put(locations.getValue(), locations.getKey()); - } - } - } - return itemIdToName; + return locationIdToName; } public HashMap getLocationsForGame(String game) { @@ -110,6 +87,26 @@ public String getUUID() { public void update(DataPackage newData) { games.putAll(newData.getGames()); + buildItemsMap(); + buildLocationsMap(); version = newData.version; } + + private void buildItemsMap() { + for (Map.Entry gameEntry : games.entrySet()) { + for (Map.Entry items : gameEntry.getValue().itemNameToId.entrySet()) { + itemIdToName.put(items.getValue(), items.getKey()); + } + } + } + + private void buildLocationsMap() { + locationIdToName.clear(); + + for (Map.Entry gameEntry : games.entrySet()) { + for (Map.Entry locations : gameEntry.getValue().locationNameToId.entrySet()) { + locationIdToName.put(locations.getValue(), locations.getKey()); + } + } + } } diff --git a/src/main/java/gg/archipelago/client/parts/Game.java b/src/main/java/gg/archipelago/client/parts/Game.java index 1c4a62c..8294d60 100644 --- a/src/main/java/gg/archipelago/client/parts/Game.java +++ b/src/main/java/gg/archipelago/client/parts/Game.java @@ -5,7 +5,7 @@ import java.io.Serializable; import java.util.HashMap; -public class Game implements Serializable { +public class Game implements Serializable, Cloneable { @SerializedName("version") public int version; @@ -18,4 +18,20 @@ public class Game implements Serializable { @SerializedName("location_name_to_id") public HashMap locationNameToId = new HashMap<>(); + + @Override + public Game clone() { + try { + Game clone = (Game) super.clone(); + + clone.version = this.version; + clone.hash = this.hash; + clone.itemNameToId = (HashMap) this.itemNameToId.clone(); + clone.locationNameToId = (HashMap) this.locationNameToId.clone(); + + return clone; + } catch (CloneNotSupportedException e) { + throw new AssertionError(); + } + } } From 7d947ac17008aa8ccfa0f005030ce8dd40bb1dd5 Mon Sep 17 00:00:00 2001 From: Charlesfire Date: Wed, 17 Jan 2024 17:15:40 -0500 Subject: [PATCH 2/2] Removed unused method clone() --- .../java/gg/archipelago/client/parts/Game.java | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/main/java/gg/archipelago/client/parts/Game.java b/src/main/java/gg/archipelago/client/parts/Game.java index 8294d60..1c4a62c 100644 --- a/src/main/java/gg/archipelago/client/parts/Game.java +++ b/src/main/java/gg/archipelago/client/parts/Game.java @@ -5,7 +5,7 @@ import java.io.Serializable; import java.util.HashMap; -public class Game implements Serializable, Cloneable { +public class Game implements Serializable { @SerializedName("version") public int version; @@ -18,20 +18,4 @@ public class Game implements Serializable, Cloneable { @SerializedName("location_name_to_id") public HashMap locationNameToId = new HashMap<>(); - - @Override - public Game clone() { - try { - Game clone = (Game) super.clone(); - - clone.version = this.version; - clone.hash = this.hash; - clone.itemNameToId = (HashMap) this.itemNameToId.clone(); - clone.locationNameToId = (HashMap) this.locationNameToId.clone(); - - return clone; - } catch (CloneNotSupportedException e) { - throw new AssertionError(); - } - } }