geforkt von Mirrors/Paper
Add displayName methods for advancements (#8584)
Dieser Commit ist enthalten in:
Ursprung
26993f7801
Commit
06be0d0b4d
@ -3,6 +3,7 @@ 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
|
||||||
@ -107,6 +108,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ 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}.
|
||||||
+ */
|
+ */
|
||||||
@ -189,6 +200,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ 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 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
+ * 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,6 +3,7 @@ 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
|
||||||
@ -14,6 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+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..00000000000000000000000000000000
|
|||||||
+ 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..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
|
diff --git a/src/main/java/net/minecraft/advancements/DisplayInfo.java b/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
||||||
@ -108,6 +147,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @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;
|
||||||
+ }
|
+ }
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren