fix UnsafeValues#loadAdvancement doesn't recalculate position (#9846)

This commit is contained in:
caramel 2023-10-29 08:13:33 +09:00 committed by GitHub
parent 8b1ac39e89
commit c6fac381ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,7 +8,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/
index 4d66a9f24d718de4c6862b20ccb7240332523db4..6b31f88803041c75023a2c99bdc1efd902f0205c 100644 index 4d66a9f24d718de4c6862b20ccb7240332523db4..6b31f88803041c75023a2c99bdc1efd902f0205c 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -319,7 +319,17 @@ public final class CraftMagicNumbers implements UnsafeValues { @@ -319,7 +319,27 @@ public final class CraftMagicNumbers implements UnsafeValues {
JsonObject jsonobject = GsonHelper.convertToJsonObject(jsonelement, "advancement"); JsonObject jsonobject = GsonHelper.convertToJsonObject(jsonelement, "advancement");
net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.fromJson(jsonobject, new DeserializationContext(minecraftkey, MinecraftServer.getServer().getLootData())); net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.fromJson(jsonobject, new DeserializationContext(minecraftkey, MinecraftServer.getServer().getLootData()));
if (nms != null) { if (nms != null) {
@ -22,7 +22,17 @@ index 4d66a9f24d718de4c6862b20ccb7240332523db4..6b31f88803041c75023a2c99bdc1efd9
+ mapBuilder.put(minecraftkey, holder); + mapBuilder.put(minecraftkey, holder);
+ +
+ MinecraftServer.getServer().getAdvancements().advancements = mapBuilder.build(); + MinecraftServer.getServer().getAdvancements().advancements = mapBuilder.build();
+ MinecraftServer.getServer().getAdvancements().tree().addAll(List.of(holder)); + final net.minecraft.advancements.AdvancementTree tree = MinecraftServer.getServer().getAdvancements().tree();
+ tree.addAll(List.of(holder));
+
+ // recalculate advancement position
+ final net.minecraft.advancements.AdvancementNode node = tree.get(minecraftkey);
+ if (node != null) {
+ final net.minecraft.advancements.AdvancementNode root = node.root();
+ if (root.holder().value().display().isPresent()) {
+ net.minecraft.advancements.TreeNodePosition.run(root);
+ }
+ }
+ // Paper end - Fix throw UnsupportedOperationException + // Paper end - Fix throw UnsupportedOperationException
Advancement bukkit = Bukkit.getAdvancement(key); Advancement bukkit = Bukkit.getAdvancement(key);