Skip to content

Commit c43e2bd

Browse files
authored
Fixed getlocations (#3)
* Fixed locations missing from locationIdToName * Removed unused method clone()
1 parent 9b8b5f8 commit c43e2bd

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

src/main/java/gg/archipelago/client/parts/DataPackage.java

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,18 @@ public class DataPackage implements Serializable {
2323
public String uuid = UUID.randomUUID().toString();
2424

2525
public String getItem(long itemID) {
26-
for (Map.Entry<String, Game> game : games.entrySet()) {
27-
for (Map.Entry<String, Long> item : game.getValue().itemNameToId.entrySet()) {
28-
if(item.getValue() == itemID)
29-
return item.getKey();
30-
}
26+
if(!itemIdToName.containsKey(itemID)) {
27+
return String.format("Unknown Item [%d]", itemID);
3128
}
32-
return String.format("Unknown Item [%d]", itemID);
29+
30+
return itemIdToName.get(itemID);
3331
}
3432

3533
public String getLocation(long locationID) {
36-
if(locationIdToName.containsKey(locationID))
37-
return locationIdToName.get(locationID);
38-
for (Map.Entry<String, Game> game : games.entrySet()) {
39-
for (Map.Entry<String, Long> location : game.getValue().locationNameToId.entrySet()) {
40-
if(location.getValue() == locationID) {
41-
locationIdToName.put(locationID, location.getKey());
42-
return location.getKey();
43-
}
44-
}
45-
}
46-
return String.format("Unknown Location [%d]", locationID);
34+
if(!locationIdToName.containsKey(locationID))
35+
return String.format("Unknown Location [%d]", locationID);
36+
37+
return locationIdToName.get(locationID);
4738
}
4839

4940
public Map<String, Integer> getVersions() {
@@ -57,13 +48,6 @@ public HashMap<String, Game> getGames() {
5748
}
5849

5950
public HashMap<Long, String> getItems() {
60-
if(itemIdToName.isEmpty()) {
61-
for (Map.Entry<String, Game> gameEntry : games.entrySet()) {
62-
for (Map.Entry<String, Long> items : gameEntry.getValue().itemNameToId.entrySet()) {
63-
itemIdToName.put(items.getValue(), items.getKey());
64-
}
65-
}
66-
}
6751
return itemIdToName;
6852
}
6953

@@ -79,14 +63,7 @@ public HashMap<Long, String> getItemsForGame(String game) {
7963
}
8064

8165
public HashMap<Long, String> getLocations() {
82-
if(locationIdToName.isEmpty()) {
83-
for (Map.Entry<String, Game> gameEntry : games.entrySet()) {
84-
for (Map.Entry<String, Long> locations : gameEntry.getValue().locationNameToId.entrySet()) {
85-
itemIdToName.put(locations.getValue(), locations.getKey());
86-
}
87-
}
88-
}
89-
return itemIdToName;
66+
return locationIdToName;
9067
}
9168

9269
public HashMap<Long, String> getLocationsForGame(String game) {
@@ -110,6 +87,26 @@ public String getUUID() {
11087

11188
public void update(DataPackage newData) {
11289
games.putAll(newData.getGames());
90+
buildItemsMap();
91+
buildLocationsMap();
11392
version = newData.version;
11493
}
94+
95+
private void buildItemsMap() {
96+
for (Map.Entry<String, Game> gameEntry : games.entrySet()) {
97+
for (Map.Entry<String, Long> items : gameEntry.getValue().itemNameToId.entrySet()) {
98+
itemIdToName.put(items.getValue(), items.getKey());
99+
}
100+
}
101+
}
102+
103+
private void buildLocationsMap() {
104+
locationIdToName.clear();
105+
106+
for (Map.Entry<String, Game> gameEntry : games.entrySet()) {
107+
for (Map.Entry<String, Long> locations : gameEntry.getValue().locationNameToId.entrySet()) {
108+
locationIdToName.put(locations.getValue(), locations.getKey());
109+
}
110+
}
111+
}
115112
}

0 commit comments

Comments
 (0)