diff --git a/patches/api/Add-more-advancement-API.patch b/patches/api/Add-more-advancement-API.patch index 98b782b61f..27753aceae 100644 --- a/patches/api/Add-more-advancement-API.patch +++ b/patches/api/Add-more-advancement-API.patch @@ -3,6 +3,7 @@ From: syldium Date: Fri, 9 Jul 2021 18:49:40 +0200 Subject: [PATCH] Add more advancement API +Co-authored-by: Jake Potrebic diff --git a/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java b/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java new file mode 100644 @@ -107,6 +108,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + NamespacedKey backgroundPath(); + + /** ++ * Gets the formatted display name for this display. This ++ * is a part of the component that would be shown in chat when a player ++ * completes the advancement. ++ * ++ * @return the display name ++ * @see org.bukkit.advancement.Advancement#displayName() ++ */ ++ @NotNull Component displayName(); ++ ++ /** + * Defines how the {@link #icon()} appears in the advancements screen and + * the color used with the {@link #title() advancement name}. + */ @@ -189,6 +200,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + io.papermc.paper.advancement.AdvancementDisplay getDisplay(); + + /** ++ * Gets the formatted display name for this display. This ++ * is part of the component that would be shown in chat when a player ++ * completes the advancement. Will return the same as ++ * {@link io.papermc.paper.advancement.AdvancementDisplay#displayName()} when an ++ * {@link io.papermc.paper.advancement.AdvancementDisplay} is present. + * +- * @return a AdvancementDisplay object, or null if not set. ++ * @return the display name ++ * @see io.papermc.paper.advancement.AdvancementDisplay#displayName() + */ +- @Nullable +- AdvancementDisplay getDisplay(); ++ @NotNull net.kyori.adventure.text.Component displayName(); ++ ++ /** + * Gets the parent advancement, if any. + * + * @return the parent advancement @@ -198,12 +224,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + /** + * Gets all the direct children advancements. - * -- * @return a AdvancementDisplay object, or null if not set. ++ * + * @return the children advancements - */ -- @Nullable -- AdvancementDisplay getDisplay(); ++ */ + @NotNull + @org.jetbrains.annotations.Unmodifiable + Collection getChildren(); diff --git a/patches/server/Add-more-advancement-API.patch b/patches/server/Add-more-advancement-API.patch index 2d394b3f8f..8b795d59e5 100644 --- a/patches/server/Add-more-advancement-API.patch +++ b/patches/server/Add-more-advancement-API.patch @@ -3,6 +3,7 @@ From: syldium Date: Fri, 9 Jul 2021 18:50:40 +0200 Subject: [PATCH] Add more advancement API +Co-authored-by: Jake Potrebic diff --git a/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java new file mode 100644 @@ -14,6 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +import io.papermc.paper.adventure.PaperAdventure; +import net.kyori.adventure.text.Component; ++import net.minecraft.advancements.Advancement; +import net.minecraft.advancements.DisplayInfo; +import net.minecraft.advancements.FrameType; +import org.bukkit.NamespacedKey; @@ -65,6 +67,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return this.handle.getBackground() == null ? null : CraftNamespacedKey.fromMinecraft(this.handle.getBackground()); + } + ++ @Override ++ public @NotNull Component displayName() { ++ return PaperAdventure.asAdventure(Advancement.constructDisplayComponent(null, this.handle)); ++ } ++ + public static @NotNull Frame asPaperFrame(@NotNull FrameType frameType) { + return switch (frameType) { + case TASK -> Frame.TASK; @@ -73,6 +80,38 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + }; + } +} +diff --git a/src/main/java/net/minecraft/advancements/Advancement.java b/src/main/java/net/minecraft/advancements/Advancement.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/advancements/Advancement.java ++++ b/src/main/java/net/minecraft/advancements/Advancement.java +@@ -0,0 +0,0 @@ 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(); +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/advancements/DisplayInfo.java @@ -108,6 +147,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + @Override ++ public net.kyori.adventure.text.Component displayName() { ++ return io.papermc.paper.adventure.PaperAdventure.asAdventure(Advancement.constructDisplayComponent(this.handle.getId(), this.handle.getDisplay())); ++ } ++ ++ @Override + public org.bukkit.advancement.Advancement getParent() { + return this.handle.getParent() == null ? null : this.handle.getParent().bukkit; + }