From 73cf1257ca8770b01766703f3a5cb130724bdabf Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 15 Mar 2023 13:19:54 +0100 Subject: [PATCH] Update adventure to 4.13.0 --- patches/api/0005-Adventure.patch | 6 +- patches/server/0010-Adventure.patch | 126 +++++++++++++++++- patches/server/0011-Paper-command.patch | 64 +++++++-- patches/server/0013-Paper-Plugins.patch | 14 +- patches/server/0014-Timings-v2.patch | 9 +- patches/server/0016-Starlight.patch | 14 +- .../server/0018-Rewrite-chunk-system.patch | 17 +-- ...ient-crashes-server-lists-and-Mojang.patch | 4 +- patches/server/0040-Optimize-explosions.patch | 4 +- ...ckPhysicsEvent-if-a-plugin-has-a-lis.patch | 4 +- ...-possibility-for-getServer-singleton.patch | 4 +- ...oleAppender-for-console-improvements.patch | 4 +- .../0279-Optimize-World-Time-Updates.patch | 4 +- ...ault-permission-message-configurable.patch | 6 +- .../0351-Add-debug-for-sync-chunk-loads.patch | 12 +- ...-Add-tick-times-API-and-mspt-command.patch | 6 +- .../0375-Improved-Watchdog-Support.patch | 6 +- ...ld-Difficulty-Remembering-Difficulty.patch | 8 +- .../server/0428-Paper-dumpitem-command.patch | 12 +- .../0473-Cache-block-data-strings.patch | 4 +- ...-non-whitelisted-player-when-white-l.patch | 4 +- ...5-Added-ServerResourcesReloadedEvent.patch | 6 +- patches/server/0560-EntityMoveEvent.patch | 6 +- ...pport-for-hex-color-codes-in-console.patch | 4 +- ...telist-use-configurable-kick-message.patch | 4 +- .../0629-Add-PlayerKickEvent-causes.patch | 6 +- ...aper-mobcaps-and-paper-playermobcaps.patch | 16 +-- .../0700-Execute-chunk-tasks-mid-tick.patch | 4 +- patches/server/0804-Custom-Potion-Mixes.patch | 6 +- ...n-on-world-create-while-being-ticked.patch | 10 +- ...0921-Add-paper-dumplisteners-command.patch | 12 +- 31 files changed, 258 insertions(+), 148 deletions(-) diff --git a/patches/api/0005-Adventure.patch b/patches/api/0005-Adventure.patch index 23e70c0122..fd64d35c28 100644 --- a/patches/api/0005-Adventure.patch +++ b/patches/api/0005-Adventure.patch @@ -7,14 +7,14 @@ Co-authored-by: zml Co-authored-by: Jake Potrebic diff --git a/build.gradle.kts b/build.gradle.kts -index 464a209dbf52ebdfa287a553778a37c382a5405c..9e003c1eb0d4e19ecfa7637fc41ec055c5ffdfdf 100644 +index 464a209dbf52ebdfa287a553778a37c382a5405c..b7aa72ae9a8b1f39e7bb355d4c6b3bf4bfaa030b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,11 +8,24 @@ java { withJavadocJar() } -+val adventureVersion = "4.12.0" ++val adventureVersion = "4.13.0" +val apiAndDocs: Configuration by configurations.creating { + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) @@ -2499,7 +2499,7 @@ index c60e1fc1cad1b9889a508602df84840723b7b966..baf0887ec941533f8007f2c7f7ab78f1 throw new UnsupportedOperationException("Not supported yet."); } diff --git a/src/main/java/org/bukkit/entity/TextDisplay.java b/src/main/java/org/bukkit/entity/TextDisplay.java -index 766d6f001d4bc59cbe13d67f539bcae3fce67144..eff2ee74f4257b18dfc677e16e9ddf970e09a056 100644 +index a0ee539a46bcdf49ea750318374d393e9ef3ce68..112fa7a324bc1e49a4ebb0c8f46866a3c02ab984 100644 --- a/src/main/java/org/bukkit/entity/TextDisplay.java +++ b/src/main/java/org/bukkit/entity/TextDisplay.java @@ -13,17 +13,37 @@ public interface TextDisplay extends Display { diff --git a/patches/server/0010-Adventure.patch b/patches/server/0010-Adventure.patch index 513c5e5181..247dcf9898 100644 --- a/patches/server/0010-Adventure.patch +++ b/patches/server/0010-Adventure.patch @@ -1169,6 +1169,109 @@ index 0000000000000000000000000000000000000000..2a08e0461db4e699b7e6a1558a4419c8 + return net.minecraft.network.chat.Component.Serializer.fromJson(GsonComponentSerializer.gson().serializer().toJsonTree(component)); + } +} +diff --git a/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..04bc65019b7abf331feb1b6c5475466b9d7ad075 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java +@@ -0,0 +1,97 @@ ++package io.papermc.paper.adventure.providers; ++ ++import it.unimi.dsi.fastutil.longs.Long2ObjectMap; ++import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; ++import net.kyori.adventure.audience.Audience; ++import net.kyori.adventure.text.event.ClickCallback; ++import net.kyori.adventure.text.event.ClickEvent; ++import org.jetbrains.annotations.NotNull; ++ ++import java.util.Queue; ++import java.util.concurrent.ConcurrentLinkedQueue; ++import java.util.concurrent.atomic.AtomicLong; ++ ++@SuppressWarnings("UnstableApiUsage") // permitted provider ++public class ClickCallbackProviderImpl implements ClickCallback.Provider { ++ ++ public static final CallbackManager CALLBACK_MANAGER = new CallbackManager(); ++ ++ @Override ++ public @NotNull ClickEvent create(final @NotNull ClickCallback callback, final ClickCallback.@NotNull Options options) { ++ return ClickEvent.runCommand("/paper callback " + CALLBACK_MANAGER.addCallback(callback, options)); ++ } ++ ++ public static final class CallbackManager { ++ ++ private final Long2ObjectMap callbacks = new Long2ObjectOpenHashMap<>(); ++ private final Queue queue = new ConcurrentLinkedQueue<>(); ++ private final AtomicLong current = new AtomicLong(); ++ ++ private CallbackManager() { ++ } ++ ++ public long addCallback(final @NotNull ClickCallback callback, final ClickCallback.@NotNull Options options) { ++ final long id = current.getAndIncrement(); ++ this.queue.add(new StoredCallback(callback, options, id)); ++ return id; ++ } ++ ++ public void handleQueue(final int currentTick) { ++ // Evict expired entries ++ if (currentTick % 100 == 0) { ++ this.callbacks.values().removeIf(callback -> !callback.valid()); ++ } ++ ++ // Add entries from queue ++ StoredCallback callback; ++ while ((callback = this.queue.poll()) != null) { ++ this.callbacks.put(callback.id(), callback); ++ } ++ } ++ ++ public void runCallback(final @NotNull Audience audience, final long id) { ++ final StoredCallback callback = this.callbacks.get(id); ++ if (callback != null && callback.valid()) { //TODO Message if expired/invalid? ++ callback.takeUse(); ++ callback.callback.accept(audience); ++ } ++ } ++ } ++ ++ private static final class StoredCallback { ++ private final long startedAt = System.nanoTime(); ++ private final ClickCallback callback; ++ private final long lifetime; ++ private final long id; ++ private int remainingUses; ++ ++ private StoredCallback(final @NotNull ClickCallback callback, final ClickCallback.@NotNull Options options, final long id) { ++ this.callback = callback; ++ this.lifetime = options.lifetime().toNanos(); ++ this.remainingUses = options.uses(); ++ this.id = id; ++ } ++ ++ public void takeUse() { ++ if (this.remainingUses != ClickCallback.UNLIMITED_USES) { ++ this.remainingUses--; ++ } ++ } ++ ++ public boolean hasRemainingUses() { ++ return this.remainingUses == ClickCallback.UNLIMITED_USES || this.remainingUses > 0; ++ } ++ ++ public boolean expired() { ++ return System.nanoTime() - this.startedAt >= this.lifetime; ++ } ++ ++ public boolean valid() { ++ return hasRemainingUses() && !expired(); ++ } ++ ++ public long id() { ++ return this.id; ++ } ++ } ++} diff --git a/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..c3631efda9c7fa531a8a9f18fbee7b5f8655382b @@ -2012,7 +2115,7 @@ index 5f051cb22ae77f4d8994b07ac5b963bd0ff05673..7952635a963e28cb670c8f4869664103 list.forEach((loader) -> { Registry registry = loader.getFirst(); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 5725631835ea68802c75934cd85d5c1b1a78d358..47ec7832579c2f5d473301e7127cae47da630c03 100644 +index 5725631835ea68802c75934cd85d5c1b1a78d358..0b859ebcc2c53e74615feca5c864136586c1523b 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -244,6 +244,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop reference = new HashSet(players.size()); for (ServerPlayer player : players) { reference.add(player.getBukkitEntity()); +diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.event.ClickCallback$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.text.event.ClickCallback$Provider +new file mode 100644 +index 0000000000000000000000000000000000000000..845711e03c41c6b6a03d541f1c43d37b24c11733 +--- /dev/null ++++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.event.ClickCallback$Provider +@@ -0,0 +1 @@ ++io.papermc.paper.adventure.providers.ClickCallbackProviderImpl diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider b/src/main/resources/META-INF/services/net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider new file mode 100644 index 0000000000000000000000000000000000000000..399bde6e57cd82b50d3ebe0f51a3958fa2d52d43 diff --git a/patches/server/0011-Paper-command.patch b/patches/server/0011-Paper-command.patch index 198c0c0224..c586cc5a75 100644 --- a/patches/server/0011-Paper-command.patch +++ b/patches/server/0011-Paper-command.patch @@ -81,16 +81,13 @@ index 0000000000000000000000000000000000000000..953c30500892e5f0c55b8597bc708ea8 +} diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..b3a58bf4b654e336826dc04da9e2f80ff8b9a9a7 +index 0000000000000000000000000000000000000000..e7931b6cb2a46d07ac017f620b807e3474dc481e --- /dev/null +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -0,0 +1,145 @@ +@@ -0,0 +1,144 @@ +package io.papermc.paper.command; + -+import io.papermc.paper.command.subcommands.EntityCommand; -+import io.papermc.paper.command.subcommands.HeapDumpCommand; -+import io.papermc.paper.command.subcommands.ReloadCommand; -+import io.papermc.paper.command.subcommands.VersionCommand; ++import io.papermc.paper.command.subcommands.*; +import it.unimi.dsi.fastutil.Pair; +import java.util.ArrayList; +import java.util.Arrays; @@ -127,11 +124,13 @@ index 0000000000000000000000000000000000000000..b3a58bf4b654e336826dc04da9e2f80f + commands.put(Set.of("entity"), new EntityCommand()); + commands.put(Set.of("reload"), new ReloadCommand()); + commands.put(Set.of("version"), new VersionCommand()); ++ commands.put(Set.of("callback"), new CallbackCommand()); + + return commands.entrySet().stream() + .flatMap(entry -> entry.getKey().stream().map(s -> Map.entry(s, entry.getValue()))) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + }); ++ private static final Set COMPLETABLE_SUBCOMMANDS = SUBCOMMANDS.entrySet().stream().filter(entry -> entry.getValue().tabCompletes()).map(Map.Entry::getKey).collect(Collectors.toSet()); + // alias -> subcommand label + private static final Map ALIASES = Util.make(() -> { + final Map> aliases = new HashMap<>(); @@ -173,7 +172,7 @@ index 0000000000000000000000000000000000000000..b3a58bf4b654e336826dc04da9e2f80f + final @Nullable Location location + ) throws IllegalArgumentException { + if (args.length <= 1) { -+ return CommandUtil.getListMatchingLast(sender, args, SUBCOMMANDS.keySet()); ++ return CommandUtil.getListMatchingLast(sender, args, COMPLETABLE_SUBCOMMANDS); + } + + final @Nullable Pair subCommand = resolveCommand(args[0]); @@ -265,10 +264,10 @@ index 0000000000000000000000000000000000000000..6a00f3d38da8107825ab1d405f337fd0 +} diff --git a/src/main/java/io/papermc/paper/command/PaperSubcommand.java b/src/main/java/io/papermc/paper/command/PaperSubcommand.java new file mode 100644 -index 0000000000000000000000000000000000000000..6ff5d42a866d2752c73a766815aa190b2b0dc36f +index 0000000000000000000000000000000000000000..7e9e0ff8639be135bf8575e375cbada5b57164e1 --- /dev/null +++ b/src/main/java/io/papermc/paper/command/PaperSubcommand.java -@@ -0,0 +1,16 @@ +@@ -0,0 +1,20 @@ +package io.papermc.paper.command; + +import java.util.Collections; @@ -284,6 +283,53 @@ index 0000000000000000000000000000000000000000..6ff5d42a866d2752c73a766815aa190b + default List tabComplete(final CommandSender sender, final String subCommand, final String[] args) { + return Collections.emptyList(); + } ++ ++ default boolean tabCompletes() { ++ return true; ++ } ++} +diff --git a/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java +new file mode 100644 +index 0000000000000000000000000000000000000000..62e121e703716b38162020d34467855a02443d88 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/command/subcommands/CallbackCommand.java +@@ -0,0 +1,37 @@ ++package io.papermc.paper.command.subcommands; ++ ++import io.papermc.paper.adventure.providers.ClickCallbackProviderImpl; ++import io.papermc.paper.command.PaperSubcommand; ++import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.event.ClickCallback; ++import net.kyori.adventure.text.event.ClickEvent; ++import org.bukkit.command.CommandSender; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++import java.time.Duration; ++ ++@DefaultQualifier(NonNull.class) ++public final class CallbackCommand implements PaperSubcommand { ++ @Override ++ public boolean execute(final CommandSender sender, final String subCommand, final String[] args) { ++ if (args.length != 1) { ++ return false; ++ } ++ ++ final long id; ++ try { ++ id = Long.parseLong(args[0]); ++ } catch (final NumberFormatException ignored) { ++ return false; ++ } ++ ++ ClickCallbackProviderImpl.CALLBACK_MANAGER.runCallback(sender, id); ++ return true; ++ } ++ ++ @Override ++ public boolean tabCompletes() { ++ return false; ++ } +} diff --git a/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java b/src/main/java/io/papermc/paper/command/subcommands/EntityCommand.java new file mode 100644 diff --git a/patches/server/0013-Paper-Plugins.patch b/patches/server/0013-Paper-Plugins.patch index 2fea05bdd6..0a8841e3d6 100644 --- a/patches/server/0013-Paper-Plugins.patch +++ b/patches/server/0013-Paper-Plugins.patch @@ -5,21 +5,13 @@ Subject: [PATCH] Paper Plugins diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index b3a58bf4b654e336826dc04da9e2f80ff8b9a9a7..156334e3876d966fedc91d18da29f562395ab182 100644 +index e7931b6cb2a46d07ac017f620b807e3474dc481e..16fdfda717300a3168c27526470f83ce6239e95f 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -4,6 +4,7 @@ import io.papermc.paper.command.subcommands.EntityCommand; - import io.papermc.paper.command.subcommands.HeapDumpCommand; - import io.papermc.paper.command.subcommands.ReloadCommand; - import io.papermc.paper.command.subcommands.VersionCommand; -+import io.papermc.paper.command.subcommands.DumpPluginsCommand; - import it.unimi.dsi.fastutil.Pair; - import java.util.ArrayList; - import java.util.Arrays; -@@ -40,6 +41,7 @@ public final class PaperCommand extends Command { - commands.put(Set.of("entity"), new EntityCommand()); +@@ -38,6 +38,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("reload"), new ReloadCommand()); commands.put(Set.of("version"), new VersionCommand()); + commands.put(Set.of("callback"), new CallbackCommand()); + commands.put(Set.of("dumpplugins"), new DumpPluginsCommand()); return commands.entrySet().stream() diff --git a/patches/server/0014-Timings-v2.patch b/patches/server/0014-Timings-v2.patch index f9c26cc9fd..252a7b447e 100644 --- a/patches/server/0014-Timings-v2.patch +++ b/patches/server/0014-Timings-v2.patch @@ -729,7 +729,7 @@ index fc4dcd801480fe6d89a985de411baa9a3a66f6ef..4a1148a76020089caf01f888f87afdbb } catch (Exception exception) { if (listener.shouldPropagateHandlingExceptions()) { diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 47ec7832579c2f5d473301e7127cae47da630c03..013556d54894dc2914b8cda7a70b9ea142b6668f 100644 +index 0b859ebcc2c53e74615feca5c864136586c1523b..027200b4702d3379ae2f987b69f390c0dbdf1d9a 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -189,7 +189,7 @@ import org.bukkit.event.player.AsyncPlayerChatPreviewEvent; @@ -833,7 +833,7 @@ index 47ec7832579c2f5d473301e7127cae47da630c03..013556d54894dc2914b8cda7a70b9ea1 } private ServerStatus buildServerStatus() { -@@ -1261,25 +1284,25 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { -@@ -2332,9 +2334,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop completablefuture = CompletableFuture.supplyAsync(() -> { Stream stream = dataPacks.stream(); // CraftBukkit - decompile error -@@ -2036,6 +2042,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper @@ -29,7 +29,7 @@ index 2af673fe240fbb0ce7667e207a833d09afa7074b..652b2c5dc17c6ba65eb59cbd3ac218d2 final Throwable thr = new Throwable(entity + " Added to world at " + new java.util.Date()); io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thr); diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index c7209675ad3eeca881da75bfc0c3212204da898e..7ce102e7a28b70d1ffeb3a433b927f49fc4d5904 100644 +index fcd670d1371dca3bb644dfea79f98670d75a68a4..276cdeb349c6b9c23ff4198beb807b5f090de3b6 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -3291,6 +3291,20 @@ public abstract class LivingEntity extends Entity implements Attackable { diff --git a/patches/server/0568-Add-support-for-hex-color-codes-in-console.patch b/patches/server/0568-Add-support-for-hex-color-codes-in-console.patch index d2e020d30d..ec9dd842c7 100644 --- a/patches/server/0568-Add-support-for-hex-color-codes-in-console.patch +++ b/patches/server/0568-Add-support-for-hex-color-codes-in-console.patch @@ -283,10 +283,10 @@ index 0000000000000000000000000000000000000000..b9922b07cb105618390187d98acdf89e + +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 41d97d9e69a5763e83c4e017c285f4bcbe6af676..fa9d8c995ea1a15663af98aa0f932173b79f800e 100644 +index 3c30d51cc497f2aa4071fed1ef9a5c93ddd358ab..ed3ec53f11cf2be94b82a779d89e8d4b7819172f 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1705,7 +1705,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); -@@ -1484,7 +1485,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper -@@ -1562,6 +1565,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop diff --git a/src/main/java/io/papermc/paper/command/PaperCommand.java b/src/main/java/io/papermc/paper/command/PaperCommand.java -index 5c0b02f1ca8f6594f8f94613edba2783087950f2..f7a92aba7c8b98c44839fd6687dd9b96df893399 100644 +index db9567711f7e0ad1778d41e79b59e31916aa9f09..7ba60b4b4f29a42c58d98aafc5ea0fa3214f554c 100644 --- a/src/main/java/io/papermc/paper/command/PaperCommand.java +++ b/src/main/java/io/papermc/paper/command/PaperCommand.java -@@ -2,6 +2,7 @@ package io.papermc.paper.command; - - import io.papermc.paper.command.subcommands.ChunkDebugCommand; - import io.papermc.paper.command.subcommands.DumpItemCommand; -+import io.papermc.paper.command.subcommands.DumpListenersCommand; - import io.papermc.paper.command.subcommands.EntityCommand; - import io.papermc.paper.command.subcommands.FixLightCommand; - import io.papermc.paper.command.subcommands.HeapDumpCommand; -@@ -52,6 +53,7 @@ public final class PaperCommand extends Command { +@@ -44,6 +44,7 @@ public final class PaperCommand extends Command { commands.put(Set.of("syncloadinfo"), new SyncLoadInfoCommand()); commands.put(Set.of("dumpitem"), new DumpItemCommand()); commands.put(Set.of("mobcaps", "playermobcaps"), new MobcapsCommand());