geforkt von Mirrors/Paper
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
220 Zeilen
10 KiB
Diff
220 Zeilen
10 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
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
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..adac21ce6db3ff7a56dbcd6bffc02143c2db4046
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/advancement/PaperAdvancementDisplay.java
|
|
@@ -0,0 +1,69 @@
|
|
+package io.papermc.paper.advancement;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.advancements.Advancement;
|
|
+import net.minecraft.advancements.AdvancementType;
|
|
+import net.minecraft.advancements.DisplayInfo;
|
|
+import org.bukkit.NamespacedKey;
|
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
|
+import org.bukkit.inventory.ItemStack;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public record PaperAdvancementDisplay(DisplayInfo handle) implements AdvancementDisplay {
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Frame frame() {
|
|
+ return asPaperFrame(this.handle.getType());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Component title() {
|
|
+ return PaperAdventure.asAdventure(this.handle.getTitle());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Component description() {
|
|
+ return PaperAdventure.asAdventure(this.handle.getDescription());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull ItemStack icon() {
|
|
+ return CraftItemStack.asBukkitCopy(this.handle.getIcon());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean doesShowToast() {
|
|
+ return this.handle.shouldShowToast();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean doesAnnounceToChat() {
|
|
+ return this.handle.shouldAnnounceChat();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isHidden() {
|
|
+ return this.handle.isHidden();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @Nullable NamespacedKey backgroundPath() {
|
|
+ return this.handle.getBackground().map(CraftNamespacedKey::fromMinecraft).orElse(null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull Component displayName() {
|
|
+ return PaperAdventure.asAdventure(Advancement.decorateName(java.util.Objects.requireNonNull(this.handle, "cannot build display name for null handle, invalid state")));
|
|
+ }
|
|
+
|
|
+ public static @NotNull Frame asPaperFrame(final @NotNull AdvancementType frameType) {
|
|
+ return switch (frameType) {
|
|
+ case TASK -> Frame.TASK;
|
|
+ case CHALLENGE -> Frame.CHALLENGE;
|
|
+ case GOAL -> Frame.GOAL;
|
|
+ };
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/advancements/DisplayInfo.java b/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
|
index d357deb8a9e1d4043f5fb3302b957b20ffc0cc32..54298a80bd86ae8c2bdbfc69d381173aea2f1410 100644
|
|
--- a/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
|
+++ b/src/main/java/net/minecraft/advancements/DisplayInfo.java
|
|
@@ -24,6 +24,7 @@ public class DisplayInfo {
|
|
private final boolean hidden;
|
|
private float x;
|
|
private float y;
|
|
+ public final io.papermc.paper.advancement.AdvancementDisplay paper = new io.papermc.paper.advancement.PaperAdvancementDisplay(this); // Paper - Add more advancement API
|
|
|
|
public DisplayInfo(ItemStack icon, Component title, Component description, Optional<ResourceLocation> background, AdvancementType 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 52baf818579a6841b77ff80e42f4f1b9f635ea08..8dfaca2efa0b0bdc97b75aaa83158a2e46361e4e 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancement.java
|
|
@@ -29,12 +29,47 @@ public class CraftAdvancement implements org.bukkit.advancement.Advancement {
|
|
return Collections.unmodifiableCollection(this.handle.value().criteria().keySet());
|
|
}
|
|
|
|
+ // Paper start - Add more advancement API
|
|
@Override
|
|
- public AdvancementDisplay getDisplay() {
|
|
- if (this.handle.value().display().isEmpty()) {
|
|
- return null;
|
|
+ public io.papermc.paper.advancement.AdvancementDisplay getDisplay() {
|
|
+ return this.handle.value().display().map(d -> d.paper).orElse(null);
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ @io.papermc.paper.annotation.DoNotUse
|
|
+ public AdvancementDisplay getDisplay0() { // May be called by plugins via Commodore
|
|
+ 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(net.minecraft.advancements.Advancement.name(this.handle));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.advancement.Advancement getParent() {
|
|
+ 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 com.google.common.collect.ImmutableList.Builder<org.bukkit.advancement.Advancement> children = com.google.common.collect.ImmutableList.<org.bukkit.advancement.Advancement>builder();
|
|
+ final net.minecraft.advancements.AdvancementNode advancementNode = net.minecraft.server.MinecraftServer.getServer().getAdvancements().tree().get(this.handle);
|
|
+ if (advancementNode != null) {
|
|
+ for (final net.minecraft.advancements.AdvancementNode child : advancementNode.children()) {
|
|
+ children.add(child.holder().toBukkit());
|
|
+ }
|
|
}
|
|
+ return children.build();
|
|
+ }
|
|
|
|
- return new CraftAdvancementDisplay(this.handle.value().display().get());
|
|
+ @Override
|
|
+ public org.bukkit.advancement.Advancement getRoot() {
|
|
+ final net.minecraft.advancements.AdvancementNode 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 - Add more advancement API
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java
|
|
index 8ca86852319d7463f60832bc98b825b0b4325995..62ada73302c6b3ce3fb2dcc8c31a1d9c0ac4fd09 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/advancement/CraftAdvancementDisplay.java
|
|
@@ -6,6 +6,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
+@Deprecated // Paper
|
|
public class CraftAdvancementDisplay implements org.bukkit.advancement.AdvancementDisplay {
|
|
|
|
private final DisplayInfo handle;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
index a06352499b9f2c6fb84e585459077b4aa1886d6f..6d6a7abe1aa39a2e4ecf3ac5f55b1f227e1a9db9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
@@ -56,6 +56,7 @@ public class Commodore {
|
|
);
|
|
|
|
// Paper start - Plugin rewrites
|
|
+ private static final String CB_PACKAGE = org.bukkit.Bukkit.getServer().getClass().getPackageName().replace('.', '/');
|
|
private static final Map<String, String> SEARCH_AND_REMOVE = initReplacementsMap();
|
|
private static Map<String, String> initReplacementsMap() {
|
|
Map<String, String> getAndRemove = new HashMap<>();
|
|
@@ -388,6 +389,11 @@ public class Commodore {
|
|
super.visitMethodInsn(opcode, owner, name, "()Lcom/destroystokyo/paper/profile/PlayerProfile;", itf);
|
|
return;
|
|
}
|
|
+ if (owner.equals("org/bukkit/advancement/Advancement") && name.equals("getDisplay") && desc.endsWith(")Lorg/bukkit/advancement/AdvancementDisplay;")) {
|
|
+ super.visitTypeInsn(Opcodes.CHECKCAST, CB_PACKAGE + "/advancement/CraftAdvancement");
|
|
+ super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CB_PACKAGE + "/advancement/CraftAdvancement", "getDisplay0", desc, false);
|
|
+ return;
|
|
+ }
|
|
// Paper end
|
|
|
|
if (modern) {
|
|
diff --git a/src/test/java/io/papermc/paper/advancement/AdvancementFrameTest.java b/src/test/java/io/papermc/paper/advancement/AdvancementFrameTest.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..47535c27d7cffc4b5ee6cc9e145b1087477eef79
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/advancement/AdvancementFrameTest.java
|
|
@@ -0,0 +1,24 @@
|
|
+package io.papermc.paper.advancement;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import net.kyori.adventure.text.format.TextColor;
|
|
+import net.minecraft.advancements.AdvancementType;
|
|
+import net.minecraft.network.chat.contents.TranslatableContents;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
+
|
|
+public class AdvancementFrameTest {
|
|
+
|
|
+ @Test
|
|
+ public void test() {
|
|
+ for (final AdvancementType advancementType : AdvancementType.values()) {
|
|
+ final TextColor expectedColor = PaperAdventure.asAdventure(advancementType.getChatColor());
|
|
+ final String expectedTranslationKey = ((TranslatableContents) advancementType.getDisplayName().getContents()).getKey();
|
|
+ final var frame = PaperAdvancementDisplay.asPaperFrame(advancementType);
|
|
+ assertEquals(expectedTranslationKey, frame.translationKey(), "The translation keys should be the same");
|
|
+ assertEquals(expectedColor, frame.color(), "The frame colors should be the same");
|
|
+ assertEquals(advancementType.getSerializedName(), AdvancementDisplay.Frame.NAMES.key(frame));
|
|
+ }
|
|
+ }
|
|
+}
|