13
0
geforkt von Mirrors/Paper

More more more (more ??) more work

Dieser Commit ist enthalten in:
Bjarne Koll 2023-09-22 15:15:57 +02:00
Ursprung 42b9f5a66d
Commit f865f927a0
7 geänderte Dateien mit 24 neuen und 47 gelöschten Zeilen

Datei anzeigen

@ -3,6 +3,9 @@ From: syldium <syldium@mailo.com>
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 <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
@ -80,38 +83,6 @@ 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
@ -129,50 +100,56 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
@@ -0,0 +0,0 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
return Collections.unmodifiableCollection(this.handle.getCriteria().keySet());
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
}