Skip to content

Commit

Permalink
修复PlayerDataUtils在NKMOT字符串物品兼容问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Dec 30, 2023
1 parent 50fc130 commit f37ff93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
<dependency>
<groupId>cn.nukkit</groupId>
<artifactId>Nukkit</artifactId>
<version>PM1E_1.20.40.3355</version>
<version>MOT-java8-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/cn/lanink/gamecore/utils/PlayerDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ public static LinkedHashMap<String, List<?>> inventoryToLinkedHashMap(@NotNull M
for (Map.Entry<Integer, Item> entry : inventoryContents.entrySet()) {
LinkedList<String> list = new LinkedList<>();
if (entry.getValue() != null) {
list.add(entry.getValue().getId() + ":" + entry.getValue().getDamage()); //0
if (NukkitTypeUtils.getNukkitType() == NukkitTypeUtils.NukkitType.MOT) {
list.add(entry.getValue().getNamespaceId()); //0
} else {
list.add(entry.getValue().getId() + ":" + entry.getValue().getDamage()); //0
}
list.add(String.valueOf(entry.getValue().getCount())); //1
list.add(bytesToBase64(entry.getValue().getCompoundTag())); //2
list.add(String.valueOf(entry.getValue().getDamage())); //3 为了兼容之前的版本放在后面
}

linkedHashMap.put(entry.getKey() + "", list);
Expand Down Expand Up @@ -89,6 +94,9 @@ public static Map<Integer, Item> linkedHashMapToInventory(Map<String, List<?>> i
if (!"not".equals(String.valueOf(list.get(2)))) {
item.setNamedTag(Item.parseCompoundTag(base64ToBytes(list.get(2))));
}
if (list.size() >= 4) {
item.setDamage(Integer.parseInt(list.get(3)));
}
map.put(Integer.parseInt(entry.getKey()), item);
}
return map;
Expand Down

0 comments on commit f37ff93

Please sign in to comment.