-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
48 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ From: syldium <[email protected]> | |
Date: Fri, 9 Jul 2021 18:50:40 +0200 | ||
Subject: [PATCH] Add more advancement API | ||
|
||
== AT == | ||
public net.minecraft.advancements.Advancement decorateName(Lnet/minecraft/advancements/DisplayInfo;)Lnet/minecraft/network/chat/Component; | ||
|
||
Co-authored-by: Jake Potrebic <[email protected]> | ||
|
||
diff --git a/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java | ||
|
@@ -80,43 +83,11 @@ index 0000000000000000000000000000000000000000..b9c24b8d83b96d8c66cdf879650027f4 | |
+ }; | ||
+ } | ||
+} | ||
diff --git a/src/main/java/net/minecraft/advancements/Advancement.java b/src/main/java/net/minecraft/advancements/Advancement.java | ||
index 72e09d3472af376b1b7aa50c3d9ab3d837a2bed3..81359be381fc9bcb56a9cc83e70a6afa6e838c6a 100644 | ||
--- a/src/main/java/net/minecraft/advancements/Advancement.java | ||
+++ b/src/main/java/net/minecraft/advancements/Advancement.java | ||
@@ -55,8 +55,16 @@ public class Advancement { | ||
parent.addChild(this); | ||
} | ||
|
||
- if (display == null) { | ||
- this.chatComponent = Component.literal(id.toString()); | ||
+ // Paper start - moved to static method | ||
+ this.chatComponent = constructDisplayComponent(this.id, this.display); | ||
+ } | ||
+ | ||
+ public static Component constructDisplayComponent(final @Nullable ResourceLocation id, final @Nullable DisplayInfo display) { | ||
+ if (id == null && display == null) { | ||
+ throw new IllegalArgumentException("can't both be null"); | ||
+ } else if (display == null) { | ||
+ return Component.literal(id.toString()); | ||
+ // Paper end | ||
} else { | ||
Component ichatbasecomponent = display.getTitle(); | ||
ChatFormatting enumchatformat = display.getFrame().getChatColor(); | ||
@@ -65,7 +73,7 @@ public class Advancement { | ||
return chatmodifier.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ichatmutablecomponent)); | ||
}); | ||
|
||
- this.chatComponent = ComponentUtils.wrapInSquareBrackets(ichatmutablecomponent1).withStyle(enumchatformat); | ||
+ return ComponentUtils.wrapInSquareBrackets(ichatmutablecomponent1).withStyle(enumchatformat); // Paper | ||
} | ||
|
||
} | ||
diff --git a/src/main/java/net/minecraft/advancements/DisplayInfo.java b/src/main/java/net/minecraft/advancements/DisplayInfo.java | ||
index 2e9e8b1f391a223cfb0fed9a100ae78004ad2f48..7909ba26bb7a883c74eda1ffd2d3e2bad286bc8b 100644 | ||
index a6ea13198a2de14d57472681b5a2b30baf3c4280..11b26d14b863075d776884544629cdd23f219298 100644 | ||
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java | ||
+++ b/src/main/java/net/minecraft/advancements/DisplayInfo.java | ||
@@ -28,6 +28,7 @@ public class DisplayInfo { | ||
@@ -29,6 +29,7 @@ public class DisplayInfo { | ||
private final boolean hidden; | ||
private float x; | ||
private float y; | ||
|
@@ -125,54 +96,60 @@ index 2e9e8b1f391a223cfb0fed9a100ae78004ad2f48..7909ba26bb7a883c74eda1ffd2d3e2ba | |
public DisplayInfo(ItemStack icon, Component title, Component description, @Nullable ResourceLocation background, FrameType frame, boolean showToast, boolean announceToChat, boolean hidden) { | ||
this.title = title; | ||
diff --git a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java | ||
index c47cae84f3b6970247d78382f48ae8ddbc202b59..1435251a4fb721b800e6a1f07b50c5f743e04081 100644 | ||
index 52baf818579a6841b77ff80e42f4f1b9f635ea08..3321445645514769ff494f90090f22241fffbc44 100644 | ||
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java | ||
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java | ||
@@ -29,12 +29,43 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement { | ||
return Collections.unmodifiableCollection(this.handle.getCriteria().keySet()); | ||
@@ -29,12 +29,49 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement { | ||
return Collections.unmodifiableCollection(this.handle.value().criteria().keySet()); | ||
} | ||
|
||
+ // Paper start | ||
@Override | ||
- public AdvancementDisplay getDisplay() { | ||
- if (this.handle.getDisplay() == null) { | ||
- if (this.handle.value().display().isEmpty()) { | ||
- return null; | ||
+ public io.papermc.paper.advancement.AdvancementDisplay getDisplay() { | ||
+ return this.handle.getDisplay() == null ? null : this.handle.getDisplay().paper; | ||
+ return this.handle.value().display().map(d -> d.paper).orElse(null); | ||
+ } | ||
+ | ||
+ @Deprecated @io.papermc.paper.annotation.DoNotUse | ||
+ @Deprecated | ||
+ @io.papermc.paper.annotation.DoNotUse | ||
+ public AdvancementDisplay getDisplay0() { // May be called by plugins via Commodore | ||
+ return this.handle.getDisplay() == null ? null : new CraftAdvancementDisplay(this.handle.getDisplay()); | ||
+ return this.handle.value().display().map(CraftAdvancementDisplay::new).orElse(null); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public net.kyori.adventure.text.Component displayName() { | ||
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(Advancement.constructDisplayComponent(this.handle.getId(), this.handle.getDisplay())); | ||
+ return this.handle.value().display() | ||
+ .map(d -> io.papermc.paper.adventure.PaperAdventure.asAdventure(net.minecraft.advancements.Advancement.decorateName(d))) | ||
+ .orElseGet(() -> net.kyori.adventure.text.Component.text(this.handle.id().toString())); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public org.bukkit.advancement.Advancement getParent() { | ||
+ return this.handle.getParent() == null ? null : this.handle.getParent().bukkit; | ||
+ return this.handle.value().parent() | ||
+ .map(net.minecraft.server.MinecraftServer.getServer().getAdvancements()::get) | ||
+ .map(AdvancementHolder::toBukkit) | ||
+ .orElse(null); | ||
+ } | ||
+ | ||
+ @Override | ||
+ public Collection<org.bukkit.advancement.Advancement> getChildren() { | ||
+ final var children = com.google.common.collect.ImmutableList.<org.bukkit.advancement.Advancement>builder(); | ||
+ for (Advancement advancement : this.handle.getChildren()) { | ||
+ children.add(advancement.bukkit); | ||
+ final var advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle); | ||
+ if (advancementNode != null) { | ||
+ for (final var child : advancementNode.children()) { | ||
+ children.add(child.holder().toBukkit()); | ||
+ } | ||
} | ||
+ return children.build(); | ||
+ } | ||
|
||
- return new CraftAdvancementDisplay(this.handle.getDisplay()); | ||
- return new CraftAdvancementDisplay(this.handle.value().display().get()); | ||
+ @Override | ||
+ public org.bukkit.advancement.Advancement getRoot() { | ||
+ Advancement advancement = this.handle; | ||
+ while (advancement.getParent() != null) { | ||
+ advancement = advancement.getParent(); | ||
+ } | ||
+ return advancement.bukkit; | ||
+ final var advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle); | ||
+ return java.util.Objects.requireNonNull(advancementNode, "could not find internal advancement node for advancement " + this.handle.id()).root().holder().toBukkit(); | ||
} | ||
+ // Paper end | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters