Add displayName methods for advancements (#8584)
This commit is contained in:
parent
414ea80d74
commit
d98c370fb5
|
@ -3,13 +3,14 @@ From: syldium <syldium@mailo.com>
|
||||||
Date: Fri, 9 Jul 2021 18:49:40 +0200
|
Date: Fri, 9 Jul 2021 18:49:40 +0200
|
||||||
Subject: [PATCH] Add more advancement API
|
Subject: [PATCH] Add more advancement API
|
||||||
|
|
||||||
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
|
|
||||||
diff --git a/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java b/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..67341bb70762a2326030abd2548372b92474f544
|
index 0000000000000000000000000000000000000000..19202e17f362fdffca472178b102d1336349590c
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java
|
+++ b/src/main/java/io/papermc/paper/advancement/AdvancementDisplay.java
|
||||||
@@ -0,0 +1,156 @@
|
@@ -0,0 +1,166 @@
|
||||||
+package io.papermc.paper.advancement;
|
+package io.papermc.paper.advancement;
|
||||||
+
|
+
|
||||||
+import net.kyori.adventure.text.Component;
|
+import net.kyori.adventure.text.Component;
|
||||||
|
@ -107,6 +108,16 @@ index 0000000000000000000000000000000000000000..67341bb70762a2326030abd2548372b9
|
||||||
+ NamespacedKey backgroundPath();
|
+ 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
|
+ * Defines how the {@link #icon()} appears in the advancements screen and
|
||||||
+ * the color used with the {@link #title() advancement name}.
|
+ * the color used with the {@link #title() advancement name}.
|
||||||
+ */
|
+ */
|
||||||
|
@ -167,10 +178,10 @@ index 0000000000000000000000000000000000000000..67341bb70762a2326030abd2548372b9
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/org/bukkit/advancement/Advancement.java b/src/main/java/org/bukkit/advancement/Advancement.java
|
diff --git a/src/main/java/org/bukkit/advancement/Advancement.java b/src/main/java/org/bukkit/advancement/Advancement.java
|
||||||
index 17527c2f7bd5b8a5528388a53f2472bc1869c7f3..792d5ab90e9252b4f660434f72f004fade14a84c 100644
|
index 17527c2f7bd5b8a5528388a53f2472bc1869c7f3..3f6b9e59c2ea38031ca74962e02d710fde61fb1f 100644
|
||||||
--- a/src/main/java/org/bukkit/advancement/Advancement.java
|
--- a/src/main/java/org/bukkit/advancement/Advancement.java
|
||||||
+++ b/src/main/java/org/bukkit/advancement/Advancement.java
|
+++ b/src/main/java/org/bukkit/advancement/Advancement.java
|
||||||
@@ -19,13 +19,41 @@ public interface Advancement extends Keyed {
|
@@ -19,13 +19,53 @@ public interface Advancement extends Keyed {
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<String> getCriteria();
|
Collection<String> getCriteria();
|
||||||
|
|
||||||
|
@ -189,6 +200,21 @@ index 17527c2f7bd5b8a5528388a53f2472bc1869c7f3..792d5ab90e9252b4f660434f72f004fa
|
||||||
+ io.papermc.paper.advancement.AdvancementDisplay getDisplay();
|
+ 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.
|
+ * Gets the parent advancement, if any.
|
||||||
+ *
|
+ *
|
||||||
+ * @return the parent advancement
|
+ * @return the parent advancement
|
||||||
|
@ -198,12 +224,9 @@ index 17527c2f7bd5b8a5528388a53f2472bc1869c7f3..792d5ab90e9252b4f660434f72f004fa
|
||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
+ * Gets all the direct children advancements.
|
+ * Gets all the direct children advancements.
|
||||||
*
|
+ *
|
||||||
- * @return a AdvancementDisplay object, or null if not set.
|
|
||||||
+ * @return the children advancements
|
+ * @return the children advancements
|
||||||
*/
|
+ */
|
||||||
- @Nullable
|
|
||||||
- AdvancementDisplay getDisplay();
|
|
||||||
+ @NotNull
|
+ @NotNull
|
||||||
+ @org.jetbrains.annotations.Unmodifiable
|
+ @org.jetbrains.annotations.Unmodifiable
|
||||||
+ Collection<Advancement> getChildren();
|
+ Collection<Advancement> getChildren();
|
||||||
|
|
|
@ -3,17 +3,19 @@ From: syldium <syldium@mailo.com>
|
||||||
Date: Fri, 9 Jul 2021 18:50:40 +0200
|
Date: Fri, 9 Jul 2021 18:50:40 +0200
|
||||||
Subject: [PATCH] Add more advancement API
|
Subject: [PATCH] Add more advancement API
|
||||||
|
|
||||||
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||||
|
|
||||||
diff --git a/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java
|
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
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..0567e500c40d3d424ddc19062c4f6da902e8586e
|
index 0000000000000000000000000000000000000000..b9c24b8d83b96d8c66cdf879650027f40eafb274
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java
|
+++ b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java
|
||||||
@@ -0,0 +1,63 @@
|
@@ -0,0 +1,69 @@
|
||||||
+package io.papermc.paper.advancement;
|
+package io.papermc.paper.advancement;
|
||||||
+
|
+
|
||||||
+import io.papermc.paper.adventure.PaperAdventure;
|
+import io.papermc.paper.adventure.PaperAdventure;
|
||||||
+import net.kyori.adventure.text.Component;
|
+import net.kyori.adventure.text.Component;
|
||||||
|
+import net.minecraft.advancements.Advancement;
|
||||||
+import net.minecraft.advancements.DisplayInfo;
|
+import net.minecraft.advancements.DisplayInfo;
|
||||||
+import net.minecraft.advancements.FrameType;
|
+import net.minecraft.advancements.FrameType;
|
||||||
+import org.bukkit.NamespacedKey;
|
+import org.bukkit.NamespacedKey;
|
||||||
|
@ -65,6 +67,11 @@ index 0000000000000000000000000000000000000000..0567e500c40d3d424ddc19062c4f6da9
|
||||||
+ return this.handle.getBackground() == null ? null : CraftNamespacedKey.fromMinecraft(this.handle.getBackground());
|
+ 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) {
|
+ public static @NotNull Frame asPaperFrame(@NotNull FrameType frameType) {
|
||||||
+ return switch (frameType) {
|
+ return switch (frameType) {
|
||||||
+ case TASK -> Frame.TASK;
|
+ case TASK -> Frame.TASK;
|
||||||
|
@ -73,6 +80,38 @@ index 0000000000000000000000000000000000000000..0567e500c40d3d424ddc19062c4f6da9
|
||||||
+ };
|
+ };
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
|
diff --git a/src/main/java/net/minecraft/advancements/Advancement.java b/src/main/java/net/minecraft/advancements/Advancement.java
|
||||||
|
index 2c01231dcfbb992c9d2f034fcfd4af52fe8ac265..dd4409790524293be07483f00df05d8a8743e3d9 100644
|
||||||
|
--- a/src/main/java/net/minecraft/advancements/Advancement.java
|
||||||
|
+++ b/src/main/java/net/minecraft/advancements/Advancement.java
|
||||||
|
@@ -53,8 +53,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();
|
||||||
|
@@ -63,7 +71,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
|
diff --git a/src/main/java/net/minecraft/advancements/DisplayInfo.java b/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
||||||
index db939a754e9308ad68f1b09a970f7a1b00a673bf..538f19f15b553d14ad95f09b1c81359f4c68b17f 100644
|
index db939a754e9308ad68f1b09a970f7a1b00a673bf..538f19f15b553d14ad95f09b1c81359f4c68b17f 100644
|
||||||
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
||||||
|
@ -86,10 +125,10 @@ index db939a754e9308ad68f1b09a970f7a1b00a673bf..538f19f15b553d14ad95f09b1c81359f
|
||||||
public DisplayInfo(ItemStack icon, Component title, Component description, @Nullable ResourceLocation background, FrameType frame, boolean showToast, boolean announceToChat, boolean hidden) {
|
public DisplayInfo(ItemStack icon, Component title, Component description, @Nullable ResourceLocation background, FrameType frame, boolean showToast, boolean announceToChat, boolean hidden) {
|
||||||
this.title = title;
|
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
|
diff --git a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
||||||
index c47cae84f3b6970247d78382f48ae8ddbc202b59..77fe2fbec4902317b9d2a959ff8cfd00fe18b60b 100644
|
index c47cae84f3b6970247d78382f48ae8ddbc202b59..1435251a4fb721b800e6a1f07b50c5f743e04081 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
||||||
@@ -29,12 +29,38 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
|
@@ -29,12 +29,43 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
|
||||||
return Collections.unmodifiableCollection(this.handle.getCriteria().keySet());
|
return Collections.unmodifiableCollection(this.handle.getCriteria().keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +147,11 @@ index c47cae84f3b6970247d78382f48ae8ddbc202b59..77fe2fbec4902317b9d2a959ff8cfd00
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @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() {
|
+ public org.bukkit.advancement.Advancement getParent() {
|
||||||
+ return this.handle.getParent() == null ? null : this.handle.getParent().bukkit;
|
+ return this.handle.getParent() == null ? null : this.handle.getParent().bukkit;
|
||||||
+ }
|
+ }
|
||||||
|
|
Loading…
Reference in New Issue