Paper/patches/server/0010-Adventure.patch

5079 lines
261 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Riley Park <rileysebastianpark@gmail.com>
2021-06-11 14:02:28 +02:00
Date: Fri, 29 Jan 2021 17:54:03 +0100
Subject: [PATCH] Adventure
Co-authored-by: zml <zml@stellardrift.ca>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/io/papermc/paper/adventure/AdventureComponent.java b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
new file mode 100644
index 0000000000000000000000000000000000000000..3246049fd557951d971ef40112a411c12aec205c
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
@@ -0,0 +1,90 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import java.lang.reflect.Type;
+import java.util.List;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
2022-06-08 16:24:55 +02:00
+import net.minecraft.network.chat.ComponentContents;
2021-06-11 14:02:28 +02:00
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.chat.Style;
2022-06-08 16:24:55 +02:00
+import net.minecraft.network.chat.contents.LiteralContents;
2021-06-12 00:37:16 +02:00
+import net.minecraft.util.FormattedCharSequence;
2021-06-11 14:02:28 +02:00
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
+import org.jetbrains.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+public final class AdventureComponent implements net.minecraft.network.chat.Component {
+ final Component adventure;
+ private net.minecraft.network.chat.@MonotonicNonNull Component vanilla;
2021-06-11 14:02:28 +02:00
+
+ public AdventureComponent(final Component adventure) {
+ this.adventure = adventure;
2021-06-11 14:02:28 +02:00
+ }
+
+ public net.minecraft.network.chat.Component deepConverted() {
+ net.minecraft.network.chat.Component vanilla = this.vanilla;
+ if (vanilla == null) {
+ vanilla = PaperAdventure.WRAPPER_AWARE_SERIALIZER.serialize(this.adventure);
+ this.vanilla = vanilla;
2021-06-11 14:02:28 +02:00
+ }
+ return vanilla;
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-12 00:37:16 +02:00
+ public net.minecraft.network.chat.@Nullable Component deepConvertedIfPresent() {
+ return this.vanilla;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public Style getStyle() {
+ return this.deepConverted().getStyle();
+ }
+
+ @Override
2022-06-08 16:24:55 +02:00
+ public ComponentContents getContents() {
+ if (this.adventure instanceof TextComponent) {
2022-06-08 16:24:55 +02:00
+ return new LiteralContents(((TextComponent) this.adventure).content());
2021-06-11 14:02:28 +02:00
+ } else {
+ return this.deepConverted().getContents();
+ }
+ }
+
+ @Override
+ public String getString() {
+ return PlainTextComponentSerializer.plainText().serialize(this.adventure);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public List<net.minecraft.network.chat.Component> getSiblings() {
+ return this.deepConverted().getSiblings();
+ }
+
+ @Override
+ public MutableComponent plainCopy() {
+ return this.deepConverted().plainCopy();
+ }
+
+ @Override
+ public MutableComponent copy() {
+ return this.deepConverted().copy();
+ }
+
2021-06-12 00:37:16 +02:00
+ @Override
+ public FormattedCharSequence getVisualOrderText() {
+ return this.deepConverted().getVisualOrderText();
+ }
+
+ public Component adventure$component() {
+ return this.adventure;
+ }
+
2021-06-11 14:02:28 +02:00
+ public static class Serializer implements JsonSerializer<AdventureComponent> {
+ @Override
+ public JsonElement serialize(final AdventureComponent src, final Type type, final JsonSerializationContext context) {
+ return GsonComponentSerializer.gson().serializer().toJsonTree(src.adventure, Component.class);
2021-06-11 14:02:28 +02:00
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/BossBarImplementationImpl.java b/src/main/java/io/papermc/paper/adventure/BossBarImplementationImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..465d634dae2e94a488c03376c3ec59a242c8e59b
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/BossBarImplementationImpl.java
@@ -0,0 +1,84 @@
+package io.papermc.paper.adventure;
+
+import com.google.common.collect.Collections2;
+import java.util.Set;
+import java.util.function.Function;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.bossbar.BossBarImplementation;
+import net.kyori.adventure.bossbar.BossBarViewer;
+import net.kyori.adventure.text.Component;
+import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
+import net.minecraft.server.level.ServerBossEvent;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.BossEvent;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.jetbrains.annotations.NotNull;
+
+public final class BossBarImplementationImpl implements BossBar.Listener, BossBarImplementation {
+ private final BossBar bar;
+ private ServerBossEvent vanilla;
+
+ public BossBarImplementationImpl(final BossBar bar) {
+ this.bar = bar;
+ }
+
+ public void playerShow(final CraftPlayer player) {
+ if (this.vanilla == null) {
+ this.vanilla = new ServerBossEvent(
+ PaperAdventure.asVanilla(this.bar.name()),
+ PaperAdventure.asVanilla(this.bar.color()),
+ PaperAdventure.asVanilla(this.bar.overlay())
+ );
+ this.vanilla.adventure = this.bar;
+ this.bar.addListener(this);
+ }
+ this.vanilla.addPlayer(player.getHandle());
+ }
+
+ public void playerHide(final CraftPlayer player) {
+ if (this.vanilla != null) {
+ this.vanilla.removePlayer(player.getHandle());
+ if (this.vanilla.getPlayers().isEmpty()) {
+ this.bar.removeListener(this);
+ this.vanilla = null;
+ }
+ }
+ }
+
+ @Override
+ public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
+ this.maybeBroadcast(ClientboundBossEventPacket::createUpdateNamePacket);
+ }
+
+ @Override
+ public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
+ this.maybeBroadcast(ClientboundBossEventPacket::createUpdateProgressPacket);
+ }
+
+ @Override
+ public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
+ this.maybeBroadcast(ClientboundBossEventPacket::createUpdateStylePacket);
+ }
+
+ @Override
+ public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
+ this.maybeBroadcast(ClientboundBossEventPacket::createUpdateStylePacket);
+ }
+
+ @Override
+ public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
+ this.maybeBroadcast(ClientboundBossEventPacket::createUpdatePropertiesPacket);
+ }
+
+ @Override
+ public @NotNull Iterable<? extends BossBarViewer> viewers() {
+ return this.vanilla == null ? Set.of() : Collections2.transform(this.vanilla.getPlayers(), ServerPlayer::getBukkitEntity);
+ }
+
+ private void maybeBroadcast(final Function<BossEvent, ClientboundBossEventPacket> fn) {
+ if (this.vanilla != null) {
+ this.vanilla.broadcast(fn);
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
new file mode 100644
2023-03-15 00:10:18 +01:00
index 0000000000000000000000000000000000000000..3b53d87a52cafb2503419f21ddd87d42a5ec0330
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
@@ -0,0 +1,145 @@
+package io.papermc.paper.adventure;
+
+import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
+import io.papermc.paper.event.player.AsyncChatDecorateEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.regex.Pattern;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
2023-03-15 00:10:18 +01:00
+import net.minecraft.Optionull;
+import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.network.chat.ChatDecorator;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.event.Event;
+import org.bukkit.event.player.AsyncPlayerChatPreviewEvent;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+
+import static io.papermc.paper.adventure.ChatProcessor.DEFAULT_LEGACY_FORMAT;
+import static io.papermc.paper.adventure.ChatProcessor.canYouHearMe;
+import static io.papermc.paper.adventure.ChatProcessor.displayName;
+import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
+
+@DefaultQualifier(NonNull.class)
+public final class ChatDecorationProcessor {
+
+ private static final String DISPLAY_NAME_TAG = "---paper_dn---";
+ private static final Pattern DISPLAY_NAME_PATTERN = Pattern.compile("%(1\\$)?s");
+ private static final String CONTENT_TAG = "---paper_content---";
+ private static final Pattern CONTENT_PATTERN = Pattern.compile("%(2\\$)?s");
+
+ final MinecraftServer server;
+ final @Nullable ServerPlayer player;
+ final @Nullable CommandSourceStack commandSourceStack;
+ final Component originalMessage;
+
2022-12-07 21:16:54 +01:00
+ public ChatDecorationProcessor(final MinecraftServer server, final @Nullable ServerPlayer player, final @Nullable CommandSourceStack commandSourceStack, final net.minecraft.network.chat.Component originalMessage) {
+ this.server = server;
+ this.player = player;
+ this.commandSourceStack = commandSourceStack;
+ this.originalMessage = PaperAdventure.asAdventure(originalMessage);
+ }
+
+ public CompletableFuture<ChatDecorator.Result> process() {
+ return CompletableFuture.supplyAsync(() -> {
+ ChatDecorator.Result result = new ChatDecorator.ModernResult(this.originalMessage, true, false);
+ if (listenToLegacy()) {
+ result = this.processLegacy(result);
+ }
+ return this.processModern(result);
+ }, this.server.chatExecutor);
+ }
+
+ @SuppressWarnings("deprecation")
+ private static boolean listenToLegacy() {
+ return canYouHearMe(AsyncPlayerChatPreviewEvent.getHandlerList());
+ }
+
+ @SuppressWarnings("deprecation")
+ private ChatDecorator.Result processLegacy(final ChatDecorator.Result input) {
+ if (this.player != null) {
+ final CraftPlayer player = this.player.getBukkitEntity();
+ final String originalMessage = legacySection().serialize(this.originalMessage);
+ final AsyncPlayerChatPreviewEvent event = new AsyncPlayerChatPreviewEvent(true, player, originalMessage, new LazyPlayerSet(this.server));
+ this.post(event);
+
+ final boolean isDefaultFormat = DEFAULT_LEGACY_FORMAT.equals(event.getFormat());
+ if (event.isCancelled() || (isDefaultFormat && originalMessage.equals(event.getMessage()))) {
+ return input;
+ } else {
+ final Component message = legacySection().deserialize(event.getMessage());
+ final Component component = isDefaultFormat ? message : legacyFormat(event.getFormat(), ((CraftPlayer) event.getPlayer()), legacySection().deserialize(event.getMessage()));
+ return legacy(component, event.getFormat(), new ChatDecorator.MessagePair(message, event.getMessage()), isDefaultFormat);
+ }
+ }
+ return input;
+ }
+
+ private ChatDecorator.Result processModern(final ChatDecorator.Result input) {
2023-03-15 00:10:18 +01:00
+ final @Nullable CraftPlayer player = Optionull.map(this.player, ServerPlayer::getBukkitEntity);
+
+ final Component initialResult = input.message().component();
+ final AsyncChatDecorateEvent event;
+ if (this.commandSourceStack != null) {
+ // TODO more command decorate context
+ event = new AsyncChatCommandDecorateEvent(true, player, this.originalMessage, initialResult);
+ } else {
+ event = new AsyncChatDecorateEvent(true, player, this.originalMessage, initialResult);
+ }
+ this.post(event);
+ if (!event.isCancelled() && !event.result().equals(initialResult)) {
+ if (input instanceof ChatDecorator.LegacyResult legacyResult) {
+ if (legacyResult.hasNoFormatting()) {
+ /*
+ The MessagePair in the decoration result may be different at this point. This is because the legacy
+ decoration system requires the same modifications be made to the message, so we can't have the initial
+ message value for the legacy chat events be changed by the modern decorate event.
+ */
+ return noFormatting(event.result(), legacyResult.format(), legacyResult.message().legacyMessage());
+ } else {
+ final Component formatted = legacyFormat(legacyResult.format(), player, event.result());
+ return withFormatting(formatted, legacyResult.format(), event.result(), legacyResult.message().legacyMessage());
+ }
+ } else {
+ return new ChatDecorator.ModernResult(event.result(), true, false);
+ }
+ }
+ return input;
+ }
+
+ private void post(final Event event) {
+ this.server.server.getPluginManager().callEvent(event);
+ }
+
+ private static Component legacyFormat(final String format, final @Nullable CraftPlayer player, final Component message) {
+ final List<TagResolver.Single> args = new ArrayList<>(player != null ? 2 : 1);
+ if (player != null) {
+ args.add(Placeholder.component(DISPLAY_NAME_TAG, displayName(player)));
+ }
+ args.add(Placeholder.component(CONTENT_TAG, message));
+ String miniMsg = MiniMessage.miniMessage().serialize(legacySection().deserialize(format));
+ miniMsg = DISPLAY_NAME_PATTERN.matcher(miniMsg).replaceFirst("<" + DISPLAY_NAME_TAG + ">");
+ miniMsg = CONTENT_PATTERN.matcher(miniMsg).replaceFirst("<" + CONTENT_TAG + ">");
+ return MiniMessage.miniMessage().deserialize(miniMsg, TagResolver.resolver(args));
+ }
+
+ public static ChatDecorator.LegacyResult legacy(final Component maybeFormatted, final String format, final ChatDecorator.MessagePair message, final boolean hasNoFormatting) {
+ return new ChatDecorator.LegacyResult(maybeFormatted, format, message, hasNoFormatting, false);
+ }
+
+ public static ChatDecorator.LegacyResult noFormatting(final Component component, final String format, final String legacyMessage) {
+ return new ChatDecorator.LegacyResult(component, format, new ChatDecorator.MessagePair(component, legacyMessage), true, true);
+ }
+
+ public static ChatDecorator.LegacyResult withFormatting(final Component formatted, final String format, final Component message, final String legacyMessage) {
+ return new ChatDecorator.LegacyResult(formatted, format, new ChatDecorator.MessagePair(message, legacyMessage), false, true);
+ }
+}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
new file mode 100644
2023-06-08 22:56:13 +02:00
index 0000000000000000000000000000000000000000..7ddec8e330ab058e72d90b68c5361a6c4feb2393
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
2023-03-15 00:10:18 +01:00
@@ -0,0 +1,412 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import io.papermc.paper.chat.ChatRenderer;
+import io.papermc.paper.event.player.AbstractChatEvent;
+import io.papermc.paper.event.player.AsyncChatEvent;
+import io.papermc.paper.event.player.ChatEvent;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.BitSet;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
2021-06-11 14:02:28 +02:00
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.audience.ForwardingAudience;
+import net.kyori.adventure.key.Key;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.text.Component;
2023-03-15 00:10:18 +01:00
+import net.minecraft.Optionull;
+import net.minecraft.Util;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.network.chat.ChatDecorator;
+import net.minecraft.network.chat.ChatType;
2022-12-08 17:32:29 +01:00
+import net.minecraft.network.chat.OutgoingChatMessage;
+import net.minecraft.network.chat.PlayerChatMessage;
+import net.minecraft.resources.ResourceKey;
2021-06-11 14:02:28 +02:00
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.command.ConsoleCommandSender;
2021-06-11 14:02:28 +02:00
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.craftbukkit.util.Waitable;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerChatEvent;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+
+import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
2021-06-11 14:02:28 +02:00
+
+@DefaultQualifier(NonNull.class)
2021-06-11 14:02:28 +02:00
+public final class ChatProcessor {
+ static final String DEFAULT_LEGACY_FORMAT = "<%1$s> %2$s"; // copied from PlayerChatEvent/AsyncPlayerChatEvent
2021-06-11 14:02:28 +02:00
+ final MinecraftServer server;
+ final ServerPlayer player;
+ final PlayerChatMessage message;
2021-06-11 14:02:28 +02:00
+ final boolean async;
+ final String craftbukkit$originalMessage;
+ final Component paper$originalMessage;
2022-12-08 17:32:29 +01:00
+ final OutgoingChatMessage outgoing;
2021-06-11 14:02:28 +02:00
+
+ static final int MESSAGE_CHANGED = 1;
+ static final int FORMAT_CHANGED = 2;
+ static final int SENDER_CHANGED = 3; // Not used
+ // static final int FORCE_PREVIEW_USE = 4; // TODO (future, maybe?)
+ private final BitSet flags = new BitSet(3);
+
+ public ChatProcessor(final MinecraftServer server, final ServerPlayer player, final PlayerChatMessage message, final boolean async) {
2021-06-11 14:02:28 +02:00
+ this.server = server;
+ this.player = player;
+ /*
+ CraftBukkit's preview/decoration system relies on both the "decorate" and chat event making the same modifications. If
+ there is unsigned content in the legacyMessage, that is because the player sent the legacyMessage without it being
+ previewed (probably by sending it too quickly). We can just ignore that because the same changes will
+ happen in the chat event.
+
+ If unsigned content is present, it will be the same as `this.legacyMessage.signedContent().previewResult().component()`.
+ */
2021-06-11 14:02:28 +02:00
+ this.message = message;
+ this.async = async;
2022-12-08 17:32:29 +01:00
+ if (this.message.requireResult().modernized()) {
+ this.craftbukkit$originalMessage = this.message.requireResult().message().legacyMessage();
+ } else {
2022-12-08 17:32:29 +01:00
+ this.craftbukkit$originalMessage = message.signedContent();
+ }
+ /*
+ this.paper$originalMessage is the input to paper's chat events. This should be the decorated message component.
+ Even if the legacy preview event modified the format, and the client signed the formatted message, this should
+ still just be the message component.
+ */
2022-12-08 17:32:29 +01:00
+ this.paper$originalMessage = this.message.requireResult().message().component();
+ this.outgoing = OutgoingChatMessage.create(this.message);
2021-06-11 14:02:28 +02:00
+ }
+
2022-02-28 22:38:23 +01:00
+ @SuppressWarnings("deprecated")
2021-06-11 14:02:28 +02:00
+ public void process() {
2022-02-28 22:38:23 +01:00
+ final boolean listenersOnAsyncEvent = canYouHearMe(AsyncPlayerChatEvent.getHandlerList());
+ final boolean listenersOnSyncEvent = canYouHearMe(PlayerChatEvent.getHandlerList());
2021-06-11 14:02:28 +02:00
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
+ final CraftPlayer player = this.player.getBukkitEntity();
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.craftbukkit$originalMessage, new LazyPlayerSet(this.server));
2022-02-28 22:38:23 +01:00
+ this.post(ae);
2021-06-11 14:02:28 +02:00
+ if (listenersOnSyncEvent) {
+ final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
2022-02-28 22:38:23 +01:00
+ ChatProcessor.this.post(se);
2021-06-11 14:02:28 +02:00
+ return null;
+ }
+ });
+ this.readLegacyModifications(se.getMessage(), se.getFormat(), se.getPlayer());
2022-02-28 22:38:23 +01:00
+ this.processModern(
+ this.modernRenderer(se.getFormat()),
2022-02-28 22:38:23 +01:00
+ this.viewersFromLegacy(se.getRecipients()),
+ this.modernMessage(se.getMessage()),
+ se.getPlayer(),
2022-02-28 22:38:23 +01:00
+ se.isCancelled()
+ );
2021-06-11 14:02:28 +02:00
+ } else {
+ this.readLegacyModifications(ae.getMessage(), ae.getFormat(), ae.getPlayer());
2022-02-28 22:38:23 +01:00
+ this.processModern(
+ this.modernRenderer(ae.getFormat()),
2022-02-28 22:38:23 +01:00
+ this.viewersFromLegacy(ae.getRecipients()),
+ this.modernMessage(ae.getMessage()),
+ ae.getPlayer(),
2022-02-28 22:38:23 +01:00
+ ae.isCancelled()
+ );
2021-06-11 14:02:28 +02:00
+ }
+ } else {
2022-02-28 22:38:23 +01:00
+ this.processModern(
+ defaultRenderer(),
2022-02-28 22:38:23 +01:00
+ new LazyChatAudienceSet(this.server),
+ this.paper$originalMessage,
+ this.player.getBukkitEntity(),
2022-02-28 22:38:23 +01:00
+ false
+ );
2021-06-11 14:02:28 +02:00
+ }
+ }
+
+ private ChatRenderer modernRenderer(final String format) {
+ if (this.flags.get(FORMAT_CHANGED)) {
+ return legacyRenderer(format);
2022-12-08 17:32:29 +01:00
+ } else if (this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
+ return legacyRenderer(legacyResult.format());
+ } else {
+ return defaultRenderer();
+ }
+ }
+
+ private Component modernMessage(final String legacyMessage) {
+ if (this.flags.get(MESSAGE_CHANGED)) {
+ return legacySection().deserialize(legacyMessage);
2022-12-08 17:32:29 +01:00
+ } else if (this.message.unsignedContent() == null && this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
+ return legacyResult.message().component();
+ } else {
+ return this.paper$originalMessage;
+ }
+ }
+
+ private void readLegacyModifications(final String message, final String format, final Player playerSender) {
2022-12-08 17:32:29 +01:00
+ if (this.message.requireResult() instanceof ChatDecorator.LegacyResult result) {
+ if (this.message.unsignedContent() != null && !result.modernized()) {
+ this.flags.set(MESSAGE_CHANGED, !message.equals(result.message().legacyMessage()));
+ } else {
+ this.flags.set(MESSAGE_CHANGED, !message.equals(this.craftbukkit$originalMessage));
+ }
+ this.flags.set(FORMAT_CHANGED, !format.equals(result.format()));
+ } else {
+ this.flags.set(MESSAGE_CHANGED, !message.equals(this.craftbukkit$originalMessage));
+ this.flags.set(FORMAT_CHANGED, !format.equals(DEFAULT_LEGACY_FORMAT));
+ }
+ this.flags.set(SENDER_CHANGED, playerSender != this.player.getBukkitEntity());
+ }
+
+ private void processModern(final ChatRenderer renderer, final Set<Audience> viewers, final Component message, final Player player, final boolean cancelled) {
+ final PlayerChatMessage.AdventureView signedMessage = this.message.adventureView();
+ final AsyncChatEvent ae = new AsyncChatEvent(this.async, player, viewers, renderer, message, this.paper$originalMessage, signedMessage);
2021-06-11 14:02:28 +02:00
+ ae.setCancelled(cancelled); // propagate cancelled state
2022-02-28 22:38:23 +01:00
+ this.post(ae);
+ final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList());
2021-06-11 14:02:28 +02:00
+ if (listenersOnSyncEvent) {
2022-02-28 22:38:23 +01:00
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
+ final ChatEvent se = new ChatEvent(player, ae.viewers(), ae.renderer(), ae.message(), ChatProcessor.this.paper$originalMessage/*, ae.usePreviewComponent()*/, signedMessage);
2022-02-28 22:38:23 +01:00
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ ChatProcessor.this.post(se);
+ ChatProcessor.this.readModernModifications(se, renderer);
2022-02-28 22:38:23 +01:00
+ ChatProcessor.this.complete(se);
+ return null;
+ }
+ });
2021-06-11 14:02:28 +02:00
+ } else {
+ this.readModernModifications(ae, renderer);
2021-06-11 14:02:28 +02:00
+ this.complete(ae);
+ }
+ }
+
+ private void readModernModifications(final AbstractChatEvent chatEvent, final ChatRenderer originalRenderer) {
2022-12-08 17:32:29 +01:00
+ if (this.message.unsignedContent() != null) {
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.message.requireResult().message().component()));
+ } else {
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.paper$originalMessage));
+ }
+ if (originalRenderer != chatEvent.renderer()) { // don't set to false if it hasn't changed
+ this.flags.set(FORMAT_CHANGED, true);
+ }
+ // this.flags.set(FORCE_PREVIEW_USE, chatEvent.usePreviewComponent()); // TODO (future, maybe?)
+ }
+
2021-06-11 14:02:28 +02:00
+ private void complete(final AbstractChatEvent event) {
+ if (event.isCancelled()) {
+ return;
+ }
+
+ final CraftPlayer player = ((CraftPlayer) event.getPlayer());
2021-06-11 14:02:28 +02:00
+ final Component displayName = displayName(player);
+ final Component message = event.message();
+ final ChatRenderer renderer = event.renderer();
+
+ final Set<Audience> viewers = event.viewers();
+ final ResourceKey<ChatType> chatTypeKey = renderer instanceof ChatRenderer.Default ? ChatType.CHAT : ChatType.RAW;
2023-06-08 22:56:13 +02:00
+ final ChatType.Bound chatType = ChatType.bind(chatTypeKey, this.player.level().registryAccess(), PaperAdventure.asVanilla(displayName(player)));
+
+ OutgoingChat outgoingChat = viewers instanceof LazyChatAudienceSet lazyAudienceSet && lazyAudienceSet.isLazy() ? new ServerOutgoingChat() : new ViewersOutgoingChat();
+ /* if (this.flags.get(FORCE_PREVIEW_USE)) { // TODO (future, maybe?)
+ outgoingChat.sendOriginal(player, viewers, chatType);
+ } else */
+ if (this.flags.get(FORMAT_CHANGED)) {
+ if (renderer instanceof ChatRenderer.ViewerUnaware unaware) {
+ outgoingChat.sendFormatChangedViewerUnaware(player, PaperAdventure.asVanilla(unaware.render(player, displayName, message)), viewers, chatType);
+ } else {
+ outgoingChat.sendFormatChangedViewerAware(player, displayName, message, renderer, viewers, chatType);
2021-06-11 14:02:28 +02:00
+ }
+ } else if (this.flags.get(MESSAGE_CHANGED)) {
+ if (!(renderer instanceof ChatRenderer.ViewerUnaware unaware)) {
+ throw new IllegalStateException("BUG: There should not be a non-legacy renderer at this point");
+ }
+ final Component renderedComponent = chatTypeKey == ChatType.CHAT ? message : unaware.render(player, displayName, message);
+ outgoingChat.sendMessageChanged(player, PaperAdventure.asVanilla(renderedComponent), viewers, chatType);
2021-06-11 14:02:28 +02:00
+ } else {
+ outgoingChat.sendOriginal(player, viewers, chatType);
+ }
+ }
+
+ interface OutgoingChat {
+ default void sendFormatChangedViewerUnaware(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
+ this.sendMessageChanged(player, renderedMessage, viewers, chatType);
+ }
+
+ void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType);
+
+ void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType);
+
+ void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType);
+ }
+
+ final class ServerOutgoingChat implements OutgoingChat {
+ @Override
+ public void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType) {
+ ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message, ChatProcessor.this.player, chatType, viewer -> PaperAdventure.asVanilla(renderer.render(player, displayName, message, viewer)));
+ }
+
+ @Override
+ public void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
+ ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message.withUnsignedContent(renderedMessage), ChatProcessor.this.player, chatType);
+ }
+
+ @Override
+ public void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType) {
+ ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message, ChatProcessor.this.player, chatType);
+ }
+ }
+
+ final class ViewersOutgoingChat implements OutgoingChat {
+ @Override
+ public void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType) {
+ this.broadcastToViewers(viewers, chatType, v -> PaperAdventure.asVanilla(renderer.render(player, displayName, message, v)));
+ }
+
+ @Override
+ public void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
+ this.broadcastToViewers(viewers, chatType, $ -> renderedMessage);
+ }
+
+ @Override
+ public void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType) {
+ this.broadcastToViewers(viewers, chatType, null);
+ }
+
+ private void broadcastToViewers(Collection<Audience> viewers, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
+ for (Audience viewer : viewers) {
+ if (acceptsNative(viewer)) {
+ this.sendNative(viewer, chatType, msgFunction);
+ } else {
2023-03-15 00:10:18 +01:00
+ final net.minecraft.network.chat.@Nullable Component unsigned = Optionull.map(msgFunction, f -> f.apply(viewer));
+ final PlayerChatMessage msg = unsigned == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(unsigned);
+ viewer.sendMessage(msg.adventureView(), this.adventure(chatType));
+ }
+ }
+ }
+
+ private static final Map<String, net.kyori.adventure.chat.ChatType> BUILT_IN_CHAT_TYPES = Util.make(() -> {
+ final Map<String, net.kyori.adventure.chat.ChatType> map = new HashMap<>();
+ for (final Field declaredField : net.kyori.adventure.chat.ChatType.class.getDeclaredFields()) {
+ if (Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType().equals(ChatType.class)) {
+ try {
+ final net.kyori.adventure.chat.ChatType type = (net.kyori.adventure.chat.ChatType) declaredField.get(null);
+ map.put(type.key().asString(), type);
+ } catch (final ReflectiveOperationException ignore) {
+ }
+ }
+ }
+ return map;
+ });
+
+ private net.kyori.adventure.chat.ChatType.Bound adventure(ChatType.Bound chatType) {
+ final String stringKey = Objects.requireNonNull(
+ ChatProcessor.this.server.registryAccess().registryOrThrow(Registries.CHAT_TYPE).getKey(chatType.chatType()),
+ () -> "No key for '%s' in CHAT_TYPE registry.".formatted(chatType)
+ ).toString();
+ net.kyori.adventure.chat.@Nullable ChatType adventure = BUILT_IN_CHAT_TYPES.get(stringKey);
+ if (adventure == null) {
+ adventure = net.kyori.adventure.chat.ChatType.chatType(Key.key(stringKey));
+ }
+ return adventure.bind(
+ PaperAdventure.asAdventure(chatType.name()),
+ PaperAdventure.asAdventure(chatType.targetName())
+ );
+ }
+
+ private static boolean acceptsNative(final Audience viewer) {
+ if (viewer instanceof Player || viewer instanceof ConsoleCommandSender) {
+ return true;
+ }
+ if (viewer instanceof ForwardingAudience.Single single) {
+ return acceptsNative(single.audience());
+ }
+ return false;
+ }
+
+ private void sendNative(final Audience viewer, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
+ if (viewer instanceof ConsoleCommandSender) {
+ this.sendToServer(chatType, msgFunction);
+ } else if (viewer instanceof CraftPlayer craftPlayer) {
2023-03-15 00:10:18 +01:00
+ craftPlayer.getHandle().sendChatMessage(ChatProcessor.this.outgoing, ChatProcessor.this.player.shouldFilterMessageTo(craftPlayer.getHandle()), chatType, Optionull.map(msgFunction, f -> f.apply(viewer)));
+ } else if (viewer instanceof ForwardingAudience.Single single) {
+ this.sendNative(single.audience(), chatType, msgFunction);
+ } else {
+ throw new IllegalStateException("Should only be a Player or Console or ForwardingAudience.Single pointing to one!");
+ }
+ }
+
+ private void sendToServer(final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
+ final PlayerChatMessage toConsoleMessage = msgFunction == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(msgFunction.apply(ChatProcessor.this.server.console));
2022-12-08 17:32:29 +01:00
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure");
+ }
2021-06-11 14:02:28 +02:00
+ }
+
2022-02-28 22:38:23 +01:00
+ private Set<Audience> viewersFromLegacy(final Set<Player> recipients) {
+ if (recipients instanceof LazyPlayerSet lazyPlayerSet && lazyPlayerSet.isLazy()) {
+ return new LazyChatAudienceSet(this.server);
+ }
+ final HashSet<Audience> viewers = new HashSet<>(recipients);
+ viewers.add(this.server.console);
+ return viewers;
2021-06-11 14:02:28 +02:00
+ }
+
+ static String legacyDisplayName(final CraftPlayer player) {
2021-06-11 14:02:28 +02:00
+ return player.getDisplayName();
+ }
+
+ static Component displayName(final CraftPlayer player) {
2021-06-11 14:02:28 +02:00
+ return player.displayName();
+ }
+
+ private static ChatRenderer.Default defaultRenderer() {
+ return (ChatRenderer.Default) ChatRenderer.defaultRenderer();
+ }
+
2021-06-11 14:02:28 +02:00
+ private static ChatRenderer legacyRenderer(final String format) {
+ if (DEFAULT_LEGACY_FORMAT.equals(format)) {
+ return defaultRenderer();
+ }
+ return ChatRenderer.viewerUnaware((player, sourceDisplayName, message) -> legacySection().deserialize(legacyFormat(format, player, legacySection().serialize(message))));
+ }
+
+ static String legacyFormat(final String format, Player player, String message) {
+ return String.format(format, legacyDisplayName((CraftPlayer) player), message);
2021-06-11 14:02:28 +02:00
+ }
+
+ private void queueIfAsyncOrRunImmediately(final Waitable<Void> waitable) {
+ if (this.async) {
+ this.server.processQueue.add(waitable);
+ } else {
+ waitable.run();
+ }
+ try {
+ waitable.get();
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt(); // tag, you're it
+ } catch (final ExecutionException e) {
+ throw new RuntimeException("Exception processing chat", e.getCause());
+ }
+ }
+
2022-02-28 22:38:23 +01:00
+ private void post(final Event event) {
+ this.server.server.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
+ }
+
+ static boolean canYouHearMe(final HandlerList handlers) {
2021-06-11 14:02:28 +02:00
+ return handlers.getRegisteredListeners().length > 0;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/DisplayNames.java b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
new file mode 100644
index 0000000000000000000000000000000000000000..d496a9a6ad229e42f1c44e31eafa6974b9faced5
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
@@ -0,0 +1,25 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2021-06-11 14:02:28 +02:00
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.ChatColor;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+
+public final class DisplayNames {
+ private DisplayNames() {
+ }
+
+ public static String getLegacy(final CraftPlayer player) {
+ return getLegacy(player.getHandle());
+ }
+
+ @SuppressWarnings("deprecation") // Valid suppress due to supporting legacy display name formatting
2021-06-11 14:02:28 +02:00
+ public static String getLegacy(final ServerPlayer player) {
+ final String legacy = player.displayName;
+ if (legacy != null) {
2022-02-28 22:38:23 +01:00
+ // thank you for being worse than wet socks, Bukkit
+ return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName);
2021-06-11 14:02:28 +02:00
+ }
+ return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName);
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
new file mode 100644
index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559b6e105ce
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
@@ -0,0 +1,26 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import java.util.HashSet;
+import java.util.Set;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.audience.Audience;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.util.LazyHashSet;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.entity.Player;
+
+final class LazyChatAudienceSet extends LazyHashSet<Audience> {
+ private final MinecraftServer server;
+
+ public LazyChatAudienceSet(final MinecraftServer server) {
+ this.server = server;
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ protected Set<Audience> makeReference() {
+ final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(this.server);
2021-06-11 14:02:28 +02:00
+ final HashSet<Audience> audiences = new HashSet<>(playerSet);
+ audiences.add(Bukkit.getConsoleSender());
+ return audiences;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
new file mode 100644
index 0000000000000000000000000000000000000000..3dc613116c086444ece88bcb0a569eeea953074f
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -0,0 +1,390 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.netty.util.AttributeKey;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+import java.util.function.BiConsumer;
2021-06-11 14:02:28 +02:00
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.inventory.Book;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.nbt.api.BinaryTagHolder;
+import net.kyori.adventure.sound.Sound;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TranslatableComponent;
+import net.kyori.adventure.text.flattener.ComponentFlattener;
+import net.kyori.adventure.text.format.TextColor;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.translation.GlobalTranslator;
+import net.kyori.adventure.translation.TranslationRegistry;
+import net.kyori.adventure.translation.Translator;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.util.Codec;
+import net.minecraft.ChatFormatting;
2022-11-23 05:53:50 +01:00
+import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.core.Holder;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.locale.Language;
2021-06-11 14:02:28 +02:00
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.nbt.StringTag;
+import net.minecraft.nbt.TagParser;
2022-11-23 05:53:50 +01:00
+import net.minecraft.network.chat.ComponentUtils;
+import net.minecraft.network.protocol.Packet;
+import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
+import net.minecraft.network.protocol.game.ClientboundSoundPacket;
2021-06-11 14:02:28 +02:00
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.sounds.SoundEvent;
2021-06-11 14:02:28 +02:00
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.BossEvent;
+import net.minecraft.world.entity.Entity;
2021-06-11 14:02:28 +02:00
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.WrittenBookItem;
2022-11-23 05:53:50 +01:00
+import org.bukkit.command.CommandSender;
+import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
+import org.bukkit.craftbukkit.entity.CraftEntity;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+public final class PaperAdventure {
+ private static final Pattern LOCALIZATION_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?s");
+ public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
+ .complexMapper(TranslatableComponent.class, (translatable, consumer) -> {
+ if (!Language.getInstance().has(translatable.key())) {
2022-02-28 22:38:23 +01:00
+ for (final Translator source : GlobalTranslator.translator().sources()) {
+ if (source instanceof TranslationRegistry registry && registry.contains(translatable.key())) {
+ consumer.accept(GlobalTranslator.render(translatable, Locale.US));
+ return;
+ }
+ }
+ }
+ final @Nullable String fallback = translatable.fallback();
+ final @NotNull String translated = Language.getInstance().getOrDefault(translatable.key(), fallback != null ? fallback : translatable.key());
2021-06-11 14:02:28 +02:00
+
+ final Matcher matcher = LOCALIZATION_PATTERN.matcher(translated);
+ final List<Component> args = translatable.args();
+ int argPosition = 0;
+ int lastIdx = 0;
+ while (matcher.find()) {
+ // append prior
+ if (lastIdx < matcher.start()) {
+ consumer.accept(Component.text(translated.substring(lastIdx, matcher.start())));
+ }
+ lastIdx = matcher.end();
+
+ final @Nullable String argIdx = matcher.group(1);
+ // calculate argument position
+ if (argIdx != null) {
+ try {
+ final int idx = Integer.parseInt(argIdx) - 1;
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ } catch (final NumberFormatException ex) {
+ // ignore, drop the format placeholder
+ }
+ } else {
+ final int idx = argPosition++;
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ }
+ }
+
+ // append tail
+ if (lastIdx < translated.length()) {
+ consumer.accept(Component.text(translated.substring(lastIdx)));
+ }
+ })
+ .build();
+ public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale"); // init after FLATTENER because classloading triggered here might create a logger
+ @Deprecated
+ public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
2021-06-11 14:02:28 +02:00
+ private static final Codec<CompoundTag, String, IOException, IOException> NBT_CODEC = new Codec<CompoundTag, String, IOException, IOException>() {
+ @Override
+ public @NotNull CompoundTag decode(final @NotNull String encoded) throws IOException {
2021-06-11 14:02:28 +02:00
+ try {
+ return TagParser.parseTag(encoded);
+ } catch (final CommandSyntaxException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public @NotNull String encode(final @NotNull CompoundTag decoded) {
2021-06-11 14:02:28 +02:00
+ return decoded.toString();
+ }
+ };
+ public static final ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer();
2021-06-11 14:02:28 +02:00
+
+ private PaperAdventure() {
+ }
+
+ // Key
+
+ public static ResourceLocation asVanilla(final Key key) {
+ return new ResourceLocation(key.namespace(), key.value());
+ }
+
+ public static ResourceLocation asVanillaNullable(final Key key) {
+ if (key == null) {
+ return null;
+ }
2022-02-28 22:38:23 +01:00
+ return asVanilla(key);
2021-06-11 14:02:28 +02:00
+ }
+
+ // Component
+
+ public static Component asAdventure(final net.minecraft.network.chat.Component component) {
+ return component == null ? Component.empty() : GsonComponentSerializer.gson().serializer().fromJson(net.minecraft.network.chat.Component.Serializer.toJsonTree(component), Component.class);
2021-06-11 14:02:28 +02:00
+ }
+
+ public static ArrayList<Component> asAdventure(final List<net.minecraft.network.chat.Component> vanillas) {
+ final ArrayList<Component> adventures = new ArrayList<>(vanillas.size());
+ for (final net.minecraft.network.chat.Component vanilla : vanillas) {
+ adventures.add(asAdventure(vanilla));
+ }
+ return adventures;
+ }
+
+ public static ArrayList<Component> asAdventureFromJson(final List<String> jsonStrings) {
+ final ArrayList<Component> adventures = new ArrayList<>(jsonStrings.size());
+ for (final String json : jsonStrings) {
+ adventures.add(GsonComponentSerializer.gson().deserialize(json));
+ }
+ return adventures;
+ }
+
+ public static List<String> asJson(final List<? extends Component> adventures) {
2021-06-11 14:02:28 +02:00
+ final List<String> jsons = new ArrayList<>(adventures.size());
+ for (final Component component : adventures) {
+ jsons.add(GsonComponentSerializer.gson().serialize(component));
+ }
+ return jsons;
+ }
+
+ public static net.minecraft.network.chat.Component asVanilla(final Component component) {
+ if (component == null) return null;
2021-06-11 14:02:28 +02:00
+ if (true) return new AdventureComponent(component);
+ return net.minecraft.network.chat.Component.Serializer.fromJson(GsonComponentSerializer.gson().serializer().toJsonTree(component));
2021-06-11 14:02:28 +02:00
+ }
+
+ public static List<net.minecraft.network.chat.Component> asVanilla(final List<Component> adventures) {
+ final List<net.minecraft.network.chat.Component> vanillas = new ArrayList<>(adventures.size());
+ for (final Component adventure : adventures) {
+ vanillas.add(asVanilla(adventure));
+ }
+ return vanillas;
+ }
+
+ public static String asJsonString(final Component component, final Locale locale) {
+ return GsonComponentSerializer.gson().serialize(translated(component, locale));
2021-06-11 14:02:28 +02:00
+ }
+
+ public static String asJsonString(final net.minecraft.network.chat.Component component, final Locale locale) {
+ if (component instanceof AdventureComponent) {
+ return asJsonString(((AdventureComponent) component).adventure, locale);
2021-06-11 14:02:28 +02:00
+ }
2021-06-16 19:48:25 +02:00
+ return net.minecraft.network.chat.Component.Serializer.toJson(component);
2021-06-11 14:02:28 +02:00
+ }
+
+ public static String asPlain(final Component component, final Locale locale) {
+ return PlainTextComponentSerializer.plainText().serialize(translated(component, locale));
+ }
+
2022-02-28 22:38:23 +01:00
+ private static Component translated(final Component component, final Locale locale) {
+ return GlobalTranslator.render(
+ component,
+ // play it safe
+ locale != null
+ ? locale
+ : Locale.US
+ );
2021-06-11 14:02:28 +02:00
+ }
+
+ public static Component resolveWithContext(final @NotNull Component component, final @Nullable CommandSender context, final @Nullable org.bukkit.entity.Entity scoreboardSubject, final boolean bypassPermissions) throws IOException {
2022-11-23 05:53:50 +01:00
+ final CommandSourceStack css = context != null ? VanillaCommandWrapper.getListener(context) : null;
+ Boolean previous = null;
+ if (css != null && bypassPermissions) {
+ previous = css.bypassSelectorPermissions;
+ css.bypassSelectorPermissions = true;
+ }
+ try {
+ return asAdventure(ComponentUtils.updateForEntity(css, asVanilla(component), scoreboardSubject == null ? null : ((CraftEntity) scoreboardSubject).getHandle(), 0));
+ } catch (CommandSyntaxException e) {
+ throw new IOException(e);
+ } finally {
+ if (css != null && previous != null) {
+ css.bypassSelectorPermissions = previous;
+ }
+ }
+ }
+
2021-06-11 14:02:28 +02:00
+ // BossBar
+
+ public static BossEvent.BossBarColor asVanilla(final BossBar.Color color) {
+ return switch (color) {
+ case PINK -> BossEvent.BossBarColor.PINK;
+ case BLUE -> BossEvent.BossBarColor.BLUE;
+ case RED -> BossEvent.BossBarColor.RED;
+ case GREEN -> BossEvent.BossBarColor.GREEN;
+ case YELLOW -> BossEvent.BossBarColor.YELLOW;
+ case PURPLE -> BossEvent.BossBarColor.PURPLE;
+ case WHITE -> BossEvent.BossBarColor.WHITE;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossBar.Color asAdventure(final BossEvent.BossBarColor color) {
+ return switch (color) {
+ case PINK -> BossBar.Color.PINK;
+ case BLUE -> BossBar.Color.BLUE;
+ case RED -> BossBar.Color.RED;
+ case GREEN -> BossBar.Color.GREEN;
+ case YELLOW -> BossBar.Color.YELLOW;
+ case PURPLE -> BossBar.Color.PURPLE;
+ case WHITE -> BossBar.Color.WHITE;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossEvent.BossBarOverlay asVanilla(final BossBar.Overlay overlay) {
+ return switch (overlay) {
+ case PROGRESS -> BossEvent.BossBarOverlay.PROGRESS;
+ case NOTCHED_6 -> BossEvent.BossBarOverlay.NOTCHED_6;
+ case NOTCHED_10 -> BossEvent.BossBarOverlay.NOTCHED_10;
+ case NOTCHED_12 -> BossEvent.BossBarOverlay.NOTCHED_12;
+ case NOTCHED_20 -> BossEvent.BossBarOverlay.NOTCHED_20;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossBar.Overlay asAdventure(final BossEvent.BossBarOverlay overlay) {
+ return switch (overlay) {
+ case PROGRESS -> BossBar.Overlay.PROGRESS;
+ case NOTCHED_6 -> BossBar.Overlay.NOTCHED_6;
+ case NOTCHED_10 -> BossBar.Overlay.NOTCHED_10;
+ case NOTCHED_12 -> BossBar.Overlay.NOTCHED_12;
+ case NOTCHED_20 -> BossBar.Overlay.NOTCHED_20;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static void setFlag(final BossBar bar, final BossBar.Flag flag, final boolean value) {
+ if (value) {
+ bar.addFlag(flag);
+ } else {
+ bar.removeFlag(flag);
+ }
+ }
+
+ // Book
+
+ public static ItemStack asItemStack(final Book book, final Locale locale) {
+ final ItemStack item = new ItemStack(net.minecraft.world.item.Items.WRITTEN_BOOK, 1);
+ final CompoundTag tag = item.getOrCreateTag();
+ tag.putString(WrittenBookItem.TAG_TITLE, validateField(asPlain(book.title(), locale), WrittenBookItem.TITLE_MAX_LENGTH, WrittenBookItem.TAG_TITLE));
+ tag.putString(WrittenBookItem.TAG_AUTHOR, asPlain(book.author(), locale));
2021-06-11 14:02:28 +02:00
+ final ListTag pages = new ListTag();
+ if (book.pages().size() > WrittenBookItem.MAX_PAGES) {
+ throw new IllegalArgumentException("Book provided had " + book.pages().size() + " pages, but is only allowed a maximum of " + WrittenBookItem.MAX_PAGES);
+ }
2021-06-11 14:02:28 +02:00
+ for (final Component page : book.pages()) {
+ pages.add(StringTag.valueOf(validateField(asJsonString(page, locale), WrittenBookItem.PAGE_LENGTH, "page")));
2021-06-11 14:02:28 +02:00
+ }
+ tag.put(WrittenBookItem.TAG_PAGES, pages);
2021-06-11 14:02:28 +02:00
+ return item;
+ }
+
+ private static String validateField(final String content, final int length, final String name) {
+ if (content == null) {
+ return content;
+ }
+
+ final int actual = content.length();
+ if (actual > length) {
+ throw new IllegalArgumentException("Field '" + name + "' has a maximum length of " + length + " but was passed '" + content + "', which was " + actual + " characters long.");
+ }
+ return content;
+ }
+
2021-06-11 14:02:28 +02:00
+ // Sounds
+
+ public static SoundSource asVanilla(final Sound.Source source) {
2022-02-28 22:38:23 +01:00
+ return switch (source) {
+ case MASTER -> SoundSource.MASTER;
+ case MUSIC -> SoundSource.MUSIC;
+ case RECORD -> SoundSource.RECORDS;
+ case WEATHER -> SoundSource.WEATHER;
+ case BLOCK -> SoundSource.BLOCKS;
+ case HOSTILE -> SoundSource.HOSTILE;
+ case NEUTRAL -> SoundSource.NEUTRAL;
+ case PLAYER -> SoundSource.PLAYERS;
+ case AMBIENT -> SoundSource.AMBIENT;
+ case VOICE -> SoundSource.VOICE;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static @Nullable SoundSource asVanillaNullable(final Sound.@Nullable Source source) {
+ if (source == null) {
+ return null;
+ }
+ return asVanilla(source);
+ }
+
+ public static Packet<?> asSoundPacket(final Sound sound, final double x, final double y, final double z, final long seed, @Nullable BiConsumer<Packet<?>, Float> packetConsumer) {
+ final ResourceLocation name = asVanilla(sound.name());
+ final Optional<SoundEvent> soundEvent = BuiltInRegistries.SOUND_EVENT.getOptional(name);
+ final SoundSource source = asVanilla(sound.source());
+
+ final Holder<SoundEvent> soundEventHolder = soundEvent.map(BuiltInRegistries.SOUND_EVENT::wrapAsHolder).orElseGet(() -> Holder.direct(SoundEvent.createVariableRangeEvent(name)));
+ final Packet<?> packet = new ClientboundSoundPacket(soundEventHolder, source, x, y, z, sound.volume(), sound.pitch(), seed);
+ if (packetConsumer != null) {
+ packetConsumer.accept(packet, soundEventHolder.value().getRange(sound.volume()));
+ }
+ return packet;
+ }
+
+ public static Packet<?> asSoundPacket(final Sound sound, final Entity emitter, final long seed, @Nullable BiConsumer<Packet<?>, Float> packetConsumer) {
+ final ResourceLocation name = asVanilla(sound.name());
+ final Optional<SoundEvent> soundEvent = BuiltInRegistries.SOUND_EVENT.getOptional(name);
+ final SoundSource source = asVanilla(sound.source());
+
+ final Holder<SoundEvent> soundEventHolder = soundEvent.map(BuiltInRegistries.SOUND_EVENT::wrapAsHolder).orElseGet(() -> Holder.direct(SoundEvent.createVariableRangeEvent(name)));
+ final Packet<?> packet = new ClientboundSoundEntityPacket(soundEventHolder, source, emitter, sound.volume(), sound.pitch(), seed);
+ if (packetConsumer != null) {
+ packetConsumer.accept(packet, soundEventHolder.value().getRange(sound.volume()));
+ }
+ return packet;
+ }
+
2021-06-11 14:02:28 +02:00
+ // NBT
+
+ public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
+ if (tag == null) {
+ return null;
+ }
+ try {
+ return BinaryTagHolder.encode(tag, NBT_CODEC);
+ } catch (final IOException e) {
+ return null;
+ }
+ }
+
+ // Colors
+
+ public static @NotNull TextColor asAdventure(final ChatFormatting formatting) {
+ final Integer color = formatting.getColor();
+ if (color == null) {
2021-06-11 14:02:28 +02:00
+ throw new IllegalArgumentException("Not a valid color");
+ }
+ return TextColor.color(color);
2021-06-11 14:02:28 +02:00
+ }
+
+ public static @Nullable ChatFormatting asVanilla(final TextColor color) {
2021-06-11 14:02:28 +02:00
+ return ChatFormatting.getByHexValue(color.value());
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..2a08e0461db4e699b7e6a1558a4419c848fc7f4f
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
@@ -0,0 +1,20 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
2021-06-11 14:02:28 +02:00
+
+final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> {
+ @Override
+ public Component deserialize(final net.minecraft.network.chat.Component input) {
+ if (input instanceof AdventureComponent) {
+ return ((AdventureComponent) input).adventure;
2021-06-11 14:02:28 +02:00
+ }
+ return GsonComponentSerializer.gson().serializer().fromJson(net.minecraft.network.chat.Component.Serializer.toJsonTree(input), Component.class);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public net.minecraft.network.chat.Component serialize(final Component component) {
+ return net.minecraft.network.chat.Component.Serializer.fromJson(GsonComponentSerializer.gson().serializer().toJsonTree(component));
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/BossBarImplementationProvider.java b/src/main/java/io/papermc/paper/adventure/providers/BossBarImplementationProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ee72fe7cb56e70404b8c86f0c9578750a45af03
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/BossBarImplementationProvider.java
@@ -0,0 +1,14 @@
+package io.papermc.paper.adventure.providers;
+
+import io.papermc.paper.adventure.BossBarImplementationImpl;
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.bossbar.BossBarImplementation;
+import org.jetbrains.annotations.NotNull;
+
+@SuppressWarnings("UnstableApiUsage") // permitted provider
+public class BossBarImplementationProvider implements BossBarImplementation.Provider {
+ @Override
+ public @NotNull BossBarImplementation create(final @NotNull BossBar bar) {
+ return new BossBarImplementationImpl(bar);
+ }
+}
2023-03-15 13:19:54 +01:00
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..3c17001bcd3862a76a22df488bff80a0ff4d1b83
2023-03-15 13:19:54 +01:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/ClickCallbackProviderImpl.java
@@ -0,0 +1,96 @@
2023-03-15 13:19:54 +01:00
+package io.papermc.paper.adventure.providers;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
2023-03-15 13:19:54 +01:00
+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;
+
+@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<Audience> callback, final ClickCallback.@NotNull Options options) {
+ return ClickEvent.runCommand("/paper callback " + CALLBACK_MANAGER.addCallback(callback, options));
+ }
+
+ public static final class CallbackManager {
+
+ private final Map<UUID, StoredCallback> callbacks = new HashMap<>();
2023-03-15 13:19:54 +01:00
+ private final Queue<StoredCallback> queue = new ConcurrentLinkedQueue<>();
+
+ private CallbackManager() {
+ }
+
+ public UUID addCallback(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options) {
+ final UUID id = UUID.randomUUID();
2023-03-15 13:19:54 +01:00
+ 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 UUID id) {
2023-03-15 13:19:54 +01:00
+ 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<Audience> callback;
+ private final long lifetime;
+ private final UUID id;
2023-03-15 13:19:54 +01:00
+ private int remainingUses;
+
+ private StoredCallback(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options, final UUID id) {
2023-03-15 13:19:54 +01:00
+ 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 UUID id() {
2023-03-15 13:19:54 +01:00
+ 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
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
@@ -0,0 +1,19 @@
+package io.papermc.paper.adventure.providers;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
+import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.LoggerFactory;
+
+public class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
+ @Override
+ public @NotNull ComponentLogger logger(@NotNull LoggerHelper helper, @NotNull String name) {
+ return helper.delegating(LoggerFactory.getLogger(name), this::serialize);
+ }
+
+ private String serialize(final Component message) {
+ return PaperAdventure.asPlain(message, null);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/GsonComponentSerializerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/GsonComponentSerializerProviderImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..c620d5aa2b0208b769dbe9563f0e99edc9a91047
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/GsonComponentSerializerProviderImpl.java
@@ -0,0 +1,30 @@
+package io.papermc.paper.adventure.providers;
+
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+
+@SuppressWarnings("UnstableApiUsage") // permitted provider
+public class GsonComponentSerializerProviderImpl implements GsonComponentSerializer.Provider {
+
+ @Override
+ public @NotNull GsonComponentSerializer gson() {
+ return GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .build();
+ }
+
+ @Override
+ public @NotNull GsonComponentSerializer gsonLegacy() {
+ return GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .downsampleColors()
+ .build();
+ }
+
+ @Override
+ public @NotNull Consumer<GsonComponentSerializer.Builder> builder() {
+ return builder -> builder.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/LegacyComponentSerializerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/LegacyComponentSerializerProviderImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..03723dbe32b7eb95253e8ff6e72dbf8d2300a059
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/LegacyComponentSerializerProviderImpl.java
@@ -0,0 +1,36 @@
+package io.papermc.paper.adventure.providers;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+
+@SuppressWarnings("UnstableApiUsage") // permitted provider
+public class LegacyComponentSerializerProviderImpl implements LegacyComponentSerializer.Provider {
+
+ @Override
+ public @NotNull LegacyComponentSerializer legacyAmpersand() {
+ return LegacyComponentSerializer.builder()
+ .flattener(PaperAdventure.FLATTENER)
+ .character(LegacyComponentSerializer.AMPERSAND_CHAR)
+ .hexColors()
+ .useUnusualXRepeatedCharacterHexFormat()
+ .build();
+ }
+
+ @Override
+ public @NotNull LegacyComponentSerializer legacySection() {
+ return LegacyComponentSerializer.builder()
+ .flattener(PaperAdventure.FLATTENER)
+ .character(LegacyComponentSerializer.SECTION_CHAR)
+ .hexColors()
+ .useUnusualXRepeatedCharacterHexFormat()
+ .build();
+ }
+
+ @Override
+ public @NotNull Consumer<LegacyComponentSerializer.Builder> legacy() {
+ return builder -> builder.flattener(PaperAdventure.FLATTENER);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/MiniMessageProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/MiniMessageProviderImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..25fd6992c869c841b1b1b3240f4d524948487614
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/MiniMessageProviderImpl.java
@@ -0,0 +1,20 @@
+package io.papermc.paper.adventure.providers;
+
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+
+@SuppressWarnings("UnstableApiUsage") // permitted provider
+public class MiniMessageProviderImpl implements MiniMessage.Provider {
+
+ @Override
+ public @NotNull MiniMessage miniMessage() {
+ return MiniMessage.builder().build();
+ }
+
+ @Override
+ public @NotNull Consumer<MiniMessage.Builder> builder() {
+ return builder -> {};
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/NBTLegacyHoverEventSerializer.java b/src/main/java/io/papermc/paper/adventure/providers/NBTLegacyHoverEventSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..b3514a3e415f3444a235f1a45f0c53741264e516
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/NBTLegacyHoverEventSerializer.java
@@ -0,0 +1,89 @@
+package io.papermc.paper.adventure.providers;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import net.kyori.adventure.key.Key;
+import net.kyori.adventure.nbt.api.BinaryTagHolder;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.HoverEvent;
+import net.kyori.adventure.text.serializer.gson.LegacyHoverEventSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import net.kyori.adventure.util.Codec;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.Tag;
+import net.minecraft.nbt.TagParser;
+
+import java.io.IOException;
+import java.util.UUID;
+
+final class NBTLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
+ public static final NBTLegacyHoverEventSerializer INSTANCE = new NBTLegacyHoverEventSerializer();
+ private static final Codec<CompoundTag, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.codec(TagParser::parseTag, Tag::toString);
+
+ static final String ITEM_TYPE = "id";
+ static final String ITEM_COUNT = "Count";
+ static final String ITEM_TAG = "tag";
+
+ static final String ENTITY_NAME = "name";
+ static final String ENTITY_TYPE = "type";
+ static final String ENTITY_ID = "id";
+
+ NBTLegacyHoverEventSerializer() {
+ }
+
+ @Override
+ public HoverEvent.ShowItem deserializeShowItem(final Component input) throws IOException {
+ final String raw = PlainTextComponentSerializer.plainText().serialize(input);
+ try {
+ final CompoundTag contents = SNBT_CODEC.decode(raw);
+ final CompoundTag tag = contents.getCompound(ITEM_TAG);
+ return HoverEvent.ShowItem.of(
+ Key.key(contents.getString(ITEM_TYPE)),
+ contents.contains(ITEM_COUNT) ? contents.getByte(ITEM_COUNT) : 1,
+ tag.isEmpty() ? null : BinaryTagHolder.encode(tag, SNBT_CODEC)
+ );
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public HoverEvent.ShowEntity deserializeShowEntity(final Component input, final Codec.Decoder<Component, String, ? extends RuntimeException> componentCodec) throws IOException {
+ final String raw = PlainTextComponentSerializer.plainText().serialize(input);
+ try {
+ final CompoundTag contents = SNBT_CODEC.decode(raw);
+ return HoverEvent.ShowEntity.of(
+ Key.key(contents.getString(ENTITY_TYPE)),
+ UUID.fromString(contents.getString(ENTITY_ID)),
+ componentCodec.decode(contents.getString(ENTITY_NAME))
+ );
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+
+ @Override
+ public Component serializeShowItem(final HoverEvent.ShowItem input) throws IOException {
+ final CompoundTag tag = new CompoundTag();
+ tag.putString(ITEM_TYPE, input.item().asString());
+ tag.putByte(ITEM_COUNT, (byte) input.count());
+ if (input.nbt() != null) {
+ try {
+ tag.put(ITEM_TAG, input.nbt().get(SNBT_CODEC));
+ } catch (final CommandSyntaxException ex) {
+ throw new IOException(ex);
+ }
+ }
+ return Component.text(SNBT_CODEC.encode(tag));
+ }
+
+ @Override
+ public Component serializeShowEntity(final HoverEvent.ShowEntity input, final Codec.Encoder<Component, String, ? extends RuntimeException> componentCodec) throws IOException {
+ final CompoundTag tag = new CompoundTag();
+ tag.putString(ENTITY_ID, input.id().toString());
+ tag.putString(ENTITY_TYPE, input.type().asString());
+ if (input.name() != null) {
+ tag.putString(ENTITY_NAME, componentCodec.encode(input.name()));
+ }
+ return Component.text(SNBT_CODEC.encode(tag));
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/providers/PlainTextComponentSerializerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/PlainTextComponentSerializerProviderImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..c0701d4f93a4d77a8177d2dd8d5076f9f781873d
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/providers/PlainTextComponentSerializerProviderImpl.java
@@ -0,0 +1,23 @@
+package io.papermc.paper.adventure.providers;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+
+@SuppressWarnings("UnstableApiUsage") // permitted provider
+public class PlainTextComponentSerializerProviderImpl implements PlainTextComponentSerializer.Provider {
+
+ @Override
+ public @NotNull PlainTextComponentSerializer plainTextSimple() {
+ return PlainTextComponentSerializer.builder()
+ .flattener(PaperAdventure.FLATTENER)
+ .build();
+ }
+
+ @Override
+ public @NotNull Consumer<PlainTextComponentSerializer.Builder> plainText() {
+ return builder -> builder.flattener(PaperAdventure.FLATTENER);
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/net/minecraft/ChatFormatting.java b/src/main/java/net/minecraft/ChatFormatting.java
2022-06-07 20:12:34 +02:00
index 98f2def9125d6faf5859572a004fa8d2fa066417..436f381c727cda72c04859c540dce4715b445390 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/ChatFormatting.java
+++ b/src/main/java/net/minecraft/ChatFormatting.java
2022-06-07 20:12:34 +02:00
@@ -113,6 +113,18 @@ public enum ChatFormatting implements StringRepresentable {
2021-06-11 21:23:46 +02:00
return name == null ? null : FORMATTING_BY_NAME.get(cleanName(name));
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Nullable public static ChatFormatting getByHexValue(int i) {
+ for (ChatFormatting value : values()) {
2021-06-16 19:48:25 +02:00
+ if (value.getColor() != null && value.getColor() == i) {
2021-06-11 14:02:28 +02:00
+ return value;
+ }
+ }
+
+ return null;
+ }
+ // Paper end
+
@Nullable
public static ChatFormatting getById(int colorIndex) {
if (colorIndex < 0) {
2022-11-23 05:53:50 +01:00
diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java
2023-06-07 19:18:05 +02:00
index 5aa9be9b4b89352784835c4bbf25023a3304c0c8..fb381a7f3362b5c7848f9c326e9378b76f6fdad9 100644
2022-11-23 05:53:50 +01:00
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
2023-06-07 19:18:05 +02:00
@@ -65,6 +65,7 @@ public class CommandSourceStack implements SharedSuggestionProvider {
2022-11-23 05:53:50 +01:00
private final TaskChainer chatMessageChainer;
2023-06-07 19:18:05 +02:00
private final IntConsumer returnValueConsumer;
2022-11-23 05:53:50 +01:00
public volatile CommandNode currentCommand; // CraftBukkit
+ public boolean bypassSelectorPermissions = false; // Paper
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
this(output, pos, rot, world, level, name, displayName, server, entity, false, (commandcontext, flag, j) -> {
2022-12-08 18:06:14 +01:00
diff --git a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
index 42242735f8f85b1852381a9f77368527203172b4..4d0694c478d476717fd11f8975955c1741b47abf 100644
--- a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
+++ b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
@@ -50,10 +50,10 @@ public class MessageArgument implements SignedArgument<MessageArgument.Message>
private static void resolveSignedMessage(Consumer<PlayerChatMessage> callback, CommandSourceStack source, PlayerChatMessage message) {
MinecraftServer minecraftServer = source.getServer();
CompletableFuture<FilteredText> completableFuture = filterPlainText(source, message);
- CompletableFuture<Component> completableFuture2 = minecraftServer.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent());
+ CompletableFuture<net.minecraft.network.chat.ChatDecorator.Result> completableFuture2 = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent()); // Paper
source.getChatMessageChainer().append((executor) -> {
return CompletableFuture.allOf(completableFuture, completableFuture2).thenAcceptAsync((void_) -> {
- PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(completableFuture2.join()).filter(completableFuture.join().mask());
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(completableFuture2.join().component()).filter(completableFuture.join().mask()); // Paper
callback.accept(playerChatMessage2);
}, executor);
});
@@ -61,10 +61,10 @@ public class MessageArgument implements SignedArgument<MessageArgument.Message>
private static void resolveDisguisedMessage(Consumer<PlayerChatMessage> callback, CommandSourceStack source, PlayerChatMessage message) {
MinecraftServer minecraftServer = source.getServer();
- CompletableFuture<Component> completableFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent());
+ CompletableFuture<net.minecraft.network.chat.ChatDecorator.Result> completableFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent()); // Paper
source.getChatMessageChainer().append((executor) -> {
return completableFuture.thenAcceptAsync((content) -> {
- callback.accept(message.withUnsignedContent(content));
+ callback.accept(message.withUnsignedContent(content.component())); // Paper
}, executor);
});
}
2022-11-23 05:53:50 +01:00
diff --git a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java
2022-12-07 18:53:34 +01:00
index ca5d08eb4115817f846b312fe35f4ab28a099401..f25b9330e068c7d9e12cb57a7761cfef9ebaf7bc 100644
2022-11-23 05:53:50 +01:00
--- a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java
+++ b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelector.java
2022-12-07 18:53:34 +01:00
@@ -92,7 +92,7 @@ public class EntitySelector {
2022-11-23 05:53:50 +01:00
}
private void checkPermissions(CommandSourceStack source) throws CommandSyntaxException {
- if (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector")) { // CraftBukkit
+ if (source.bypassSelectorPermissions || (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector"))) { // CraftBukkit // Paper
throw EntityArgument.ERROR_SELECTORS_NOT_ALLOWED.create();
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2023-03-14 19:05:23 +01:00
index 5fb11741ca75b06322de00624353687c28df81a2..9020bc6d9ff6bc0c9b3f00470813f3258554cf45 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2023-03-14 19:05:23 +01:00
@@ -22,6 +22,7 @@ import io.netty.handler.codec.EncoderException;
2021-06-11 14:02:28 +02:00
import io.netty.util.ByteProcessor;
2021-06-11 21:23:46 +02:00
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
2021-06-11 14:02:28 +02:00
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.DataOutput;
import java.io.IOException;
2021-11-23 12:27:39 +01:00
import java.io.InputStream;
2023-03-14 19:05:23 +01:00
@@ -89,6 +90,7 @@ public class FriendlyByteBuf extends ByteBuf {
2021-06-11 21:23:46 +02:00
private static final int MAX_VARLONG_SIZE = 10;
2022-12-07 18:53:34 +01:00
public static final int DEFAULT_NBT_QUOTA = 2097152;
2021-06-11 14:02:28 +02:00
private final ByteBuf source;
+ public java.util.Locale adventure$locale; // Paper
2021-06-11 21:23:46 +02:00
public static final short MAX_STRING_LENGTH = 32767;
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
2022-06-07 20:12:34 +02:00
private static final int PUBLIC_KEY_SIZE = 256;
2023-03-14 19:05:23 +01:00
@@ -542,8 +544,15 @@ public class FriendlyByteBuf extends ByteBuf {
2022-06-07 20:12:34 +02:00
}
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public FriendlyByteBuf writeComponent(final net.kyori.adventure.text.Component component) {
+ return this.writeUtf(PaperAdventure.asJsonString(component, this.adventure$locale), 262144);
+ }
+ // Paper end
+
public FriendlyByteBuf writeComponent(Component text) {
- return this.writeUtf(Component.Serializer.toJson(text), 262144);
+ //return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144); // Paper - comment
+ return this.writeUtf(PaperAdventure.asJsonString(text, this.adventure$locale), 262144); // Paper
}
2021-06-11 21:23:46 +02:00
public <T extends Enum<T>> T readEnum(Class<T> enumClass) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
2023-03-14 19:05:23 +01:00
index a63e7ee5c42bd51312155feab31c6ec4232e1bc7..42828edf81bd475b673a9d143f79c0d0711f14f5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
2022-03-01 06:43:03 +01:00
@@ -4,6 +4,7 @@ import com.mojang.logging.LogUtils;
2021-06-11 14:02:28 +02:00
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.IOException;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
2022-03-01 06:43:03 +01:00
@@ -33,6 +34,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
2021-06-11 14:02:28 +02:00
} else {
2021-06-11 21:23:46 +02:00
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
2023-03-14 19:05:23 +01:00
friendlyByteBuf.writeVarInt(i);
2021-06-11 21:23:46 +02:00
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
try {
2023-03-14 19:05:23 +01:00
int j = friendlyByteBuf.writerIndex();
diff --git a/src/main/java/net/minecraft/network/chat/ChatDecorator.java b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
2022-12-08 18:06:14 +01:00
index 825ab7534f1ad9787ae2a6c2bf9a300f52cbfc95..53be8a43d784db5e8450c242adeb06f3fab2717a 100644
--- a/src/main/java/net/minecraft/network/chat/ChatDecorator.java
+++ b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
2022-12-08 18:06:14 +01:00
@@ -10,5 +10,64 @@ public interface ChatDecorator {
return CompletableFuture.completedFuture(message);
};
2022-12-08 18:06:14 +01:00
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper
CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message);
2022-12-07 18:53:34 +01:00
+
+ // Paper start
2022-12-07 18:53:34 +01:00
+ default CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
+ throw new UnsupportedOperationException("Must override this implementation");
+ }
+
+ static ChatDecorator create(ImprovedChatDecorator delegate) {
+ return new ChatDecorator() {
+ @Override
+ public CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message) {
2022-12-07 18:53:34 +01:00
+ return this.decorate(sender, null, message).thenApply(Result::component);
+ }
+
+ @Override
2022-12-07 18:53:34 +01:00
+ public CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
+ return delegate.decorate(sender, commandSourceStack, message);
+ }
+ };
+ }
+
+ @FunctionalInterface
+ interface ImprovedChatDecorator {
2022-12-07 18:53:34 +01:00
+ CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message);
+ }
+
+ interface Result {
+ boolean hasNoFormatting();
+
+ Component component();
+
+ MessagePair message();
+
+ boolean modernized();
+ }
+
+ record MessagePair(net.kyori.adventure.text.Component component, String legacyMessage) { }
+
+ record LegacyResult(Component component, String format, MessagePair message, boolean hasNoFormatting, boolean modernized) implements Result {
+ public LegacyResult(net.kyori.adventure.text.Component component, String format, MessagePair message, boolean hasNoFormatting, boolean modernified) {
+ this(io.papermc.paper.adventure.PaperAdventure.asVanilla(component), format, message, hasNoFormatting, modernified);
+ }
+ public LegacyResult {
+ component = component instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent ? adventureComponent.deepConverted() : component;
+ }
+ }
+
2022-12-08 18:06:14 +01:00
+ record ModernResult(Component component, boolean hasNoFormatting, boolean modernized) implements Result {
+ public ModernResult(net.kyori.adventure.text.Component component, boolean hasNoFormatting, boolean modernized) {
+ this(io.papermc.paper.adventure.PaperAdventure.asVanilla(component), hasNoFormatting, modernized);
+ }
+
+ @Override
+ public MessagePair message() {
2022-12-08 18:06:14 +01:00
+ final net.kyori.adventure.text.Component adventureComponent = io.papermc.paper.adventure.PaperAdventure.WRAPPER_AWARE_SERIALIZER.deserialize(this.component);
+ return new MessagePair(adventureComponent, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(adventureComponent));
+ }
+ }
+ // Paper end
2022-12-07 18:53:34 +01:00
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/chat/Component.java b/src/main/java/net/minecraft/network/chat/Component.java
2023-03-14 19:05:23 +01:00
index 8f5e07047f88138422ae82143a80427be869a760..37fc353c3e59dd5af2fd6c58ac084fb0e6e155d7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/chat/Component.java
+++ b/src/main/java/net/minecraft/network/chat/Component.java
2021-06-11 21:23:46 +02:00
@@ -1,6 +1,7 @@
2021-06-11 14:02:28 +02:00
package net.minecraft.network.chat;
2021-06-11 21:23:46 +02:00
import com.google.common.collect.Lists;
2021-06-11 14:02:28 +02:00
+import io.papermc.paper.adventure.AdventureComponent; // Paper
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
2023-03-14 19:05:23 +01:00
@@ -224,6 +225,7 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
2021-06-11 14:02:28 +02:00
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.disableHtmlEscaping();
+ gsonbuilder.registerTypeAdapter(AdventureComponent.class, new AdventureComponent.Serializer()); // Paper
gsonbuilder.registerTypeHierarchyAdapter(Component.class, new Component.Serializer());
gsonbuilder.registerTypeHierarchyAdapter(Style.class, new Style.Serializer());
gsonbuilder.registerTypeAdapterFactory(new LowerCaseEnumTypeAdapterFactory());
2023-03-14 19:05:23 +01:00
@@ -401,6 +403,7 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
2021-06-11 14:02:28 +02:00
}
public JsonElement serialize(Component ichatbasecomponent, Type type, JsonSerializationContext jsonserializationcontext) {
+ if (ichatbasecomponent instanceof AdventureComponent) return jsonserializationcontext.serialize(ichatbasecomponent); // Paper
JsonObject jsonobject = new JsonObject();
if (!ichatbasecomponent.getStyle().isEmpty()) {
2022-11-23 05:53:50 +01:00
diff --git a/src/main/java/net/minecraft/network/chat/ComponentUtils.java b/src/main/java/net/minecraft/network/chat/ComponentUtils.java
2023-03-14 19:05:23 +01:00
index ea30dad0134644a8ad292a892450404203f3535e..584a58659fae6ba3d8b53858890bc6ec509ffb0e 100644
2022-11-23 05:53:50 +01:00
--- a/src/main/java/net/minecraft/network/chat/ComponentUtils.java
+++ b/src/main/java/net/minecraft/network/chat/ComponentUtils.java
@@ -42,6 +42,11 @@ public class ComponentUtils {
if (depth > 100) {
return text.copy();
} else {
+ // Paper start
+ if (text instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) {
+ text = adventureComponent.deepConverted();
+ }
+ // Paper end
MutableComponent mutableComponent = text.getContents().resolve(source, sender, depth + 1);
for(Component component : text.getSiblings()) {
diff --git a/src/main/java/net/minecraft/network/chat/MessageSignature.java b/src/main/java/net/minecraft/network/chat/MessageSignature.java
2022-12-17 08:46:46 +01:00
index df9997873c4bbec184379ec14dca1bf4566eb89d..e2812cdce3b1170b7b7d0f52209e8b4fd2b64c61 100644
--- a/src/main/java/net/minecraft/network/chat/MessageSignature.java
+++ b/src/main/java/net/minecraft/network/chat/MessageSignature.java
2022-12-17 08:46:46 +01:00
@@ -13,11 +13,12 @@ import net.minecraft.util.SignatureUpdater;
import net.minecraft.util.SignatureValidator;
2022-12-17 08:46:46 +01:00
public record MessageSignature(byte[] bytes) {
+ public net.kyori.adventure.chat.SignedMessage.Signature adventure() { return () -> this.bytes; } // Paper
public static final Codec<MessageSignature> CODEC = ExtraCodecs.BASE64_STRING.xmap(MessageSignature::new, MessageSignature::bytes);
public static final int BYTES = 256;
public MessageSignature {
- Preconditions.checkState(bs.length == 256, "Invalid message signature size");
+ Preconditions.checkState(bytes.length == 256, "Invalid message signature size"); // Paper - decompile fix
}
public static MessageSignature read(FriendlyByteBuf buf) {
2022-12-07 18:53:34 +01:00
diff --git a/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java b/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
index f8773f2982e6cd40661d138a7c32f219cda9225c..74cf1c043beef03cfd5adf481414a5ee78bef2a6 100644
--- a/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
+++ b/src/main/java/net/minecraft/network/chat/OutgoingChatMessage.java
@@ -7,6 +7,12 @@ public interface OutgoingChatMessage {
2022-08-06 00:58:34 +02:00
void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params);
+ // Paper start
2022-08-06 00:58:34 +02:00
+ default void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
+ this.sendToPlayer(sender, filterMaskEnabled, params);
+ }
+ // Paper end
2022-08-06 00:58:34 +02:00
+
2022-12-07 18:53:34 +01:00
static OutgoingChatMessage create(PlayerChatMessage message) {
return (OutgoingChatMessage)(message.isSystem() ? new OutgoingChatMessage.Disguised(message.decoratedContent()) : new OutgoingChatMessage.Player(message));
}
@@ -14,7 +20,12 @@ public interface OutgoingChatMessage {
public static record Disguised(Component content) implements OutgoingChatMessage {
@Override
2022-08-06 00:58:34 +02:00
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
2022-12-07 18:53:34 +01:00
- sender.connection.sendDisguisedChatMessage(this.content, params);
+ // Paper start
2022-08-06 00:58:34 +02:00
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
+ }
2022-08-06 00:58:34 +02:00
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
2022-12-07 18:53:34 +01:00
+ sender.connection.sendDisguisedChatMessage(unsigned != null ? unsigned : this.content, params);
+ // Paper end
2022-12-07 18:53:34 +01:00
}
}
@@ -26,7 +37,13 @@ public interface OutgoingChatMessage {
@Override
2022-08-06 00:58:34 +02:00
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
+ // Paper start
2022-08-06 00:58:34 +02:00
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
+ }
2022-08-06 00:58:34 +02:00
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
+ // Paper end
2022-08-06 00:58:34 +02:00
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
+ playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
if (!playerChatMessage.isFullyFiltered()) {
2022-12-07 18:53:34 +01:00
sender.connection.sendPlayerChatMessage(playerChatMessage, params);
}
2022-12-08 17:32:29 +01:00
diff --git a/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java b/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
2022-12-17 08:46:46 +01:00
index b3a44ed8f365daf1031d46d879c84d2ea15cd951..ed92592e4d9e3d88b7300ea7a315541bfb430231 100644
2022-12-08 17:32:29 +01:00
--- a/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
+++ b/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
@@ -15,7 +15,53 @@ import net.minecraft.util.ExtraCodecs;
2022-12-08 17:32:29 +01:00
import net.minecraft.util.SignatureUpdater;
import net.minecraft.util.SignatureValidator;
-public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
+// Paper start
+public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask, @Nullable net.minecraft.network.chat.ChatDecorator.Result result) {
+ public PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
+ this(link, signature, signedBody, unsignedContent, filterMask, null);
+ }
+ public PlayerChatMessage withResult(net.minecraft.network.chat.ChatDecorator.Result result) {
+ final PlayerChatMessage msg = this.withUnsignedContent(result.component());
+ return new PlayerChatMessage(msg.link, msg.signature, msg.signedBody, msg.unsignedContent, msg.filterMask, result);
+ }
+ public net.minecraft.network.chat.ChatDecorator.Result requireResult() {
+ return Objects.requireNonNull(this.result, "Requires a decoration result to be set here");
+ }
+ public final class AdventureView implements net.kyori.adventure.chat.SignedMessage {
+ private AdventureView() {
+ }
+ @Override
+ public @org.jetbrains.annotations.NotNull Instant timestamp() {
+ return PlayerChatMessage.this.timeStamp();
+ }
+ @Override
+ public long salt() {
+ return PlayerChatMessage.this.salt();
+ }
+ @Override
+ public @org.jetbrains.annotations.Nullable Signature signature() {
2022-12-17 08:46:46 +01:00
+ return PlayerChatMessage.this.signature == null ? null : PlayerChatMessage.this.signature.adventure();
+ }
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component unsignedContent() {
+ return PlayerChatMessage.this.unsignedContent() == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(PlayerChatMessage.this.unsignedContent());
+ }
+ @Override
+ public @org.jetbrains.annotations.NotNull String message() {
+ return PlayerChatMessage.this.signedContent();
+ }
+ @Override
+ public @org.jetbrains.annotations.NotNull net.kyori.adventure.identity.Identity identity() {
+ return net.kyori.adventure.identity.Identity.identity(PlayerChatMessage.this.sender());
+ }
+ public PlayerChatMessage playerChatMessage() {
+ return PlayerChatMessage.this;
+ }
+ }
+ public AdventureView adventureView() {
+ return new AdventureView();
+ }
2022-12-08 17:32:29 +01:00
+ // Paper end
public static final MapCodec<PlayerChatMessage> MAP_CODEC = RecordCodecBuilder.mapCodec((instance) -> {
return instance.group(SignedMessageLink.CODEC.fieldOf("link").forGetter(PlayerChatMessage::link), MessageSignature.CODEC.optionalFieldOf("signature").forGetter((message) -> {
return Optional.ofNullable(message.signature);
@@ -40,7 +86,7 @@ public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignatu
2022-12-08 18:06:14 +01:00
}
public PlayerChatMessage withUnsignedContent(Component unsignedContent) {
- Component component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
+ Component component = !(unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent ? advComponent.deepConverted() : unsignedContent).equals(Component.literal(this.signedContent())) ? unsignedContent : null; // Paper
return new PlayerChatMessage(this.link, this.signature, this.signedBody, component, this.filterMask);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
index 02183c810f9968621b9b20c1f7b54258b620c507..32ef3edebe94a2014168b7e438752a80b2687e5f 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetActionBarTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetActionBarTextPacket(Component message) {
this.text = message;
@@ -17,6 +18,11 @@ public class ClientboundSetActionBarTextPacket implements Packet<ClientGamePacke
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
index bea682c52a95863c474b8283bd4ae795e525a94f..c44a276d201fdfa5144d45d319d7761583c60639 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetSubtitleTextPacket(Component subtitle) {
this.text = subtitle;
@@ -17,6 +18,11 @@ public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacket
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
index 1fb62779527a228f748b49a4d2ddfc57ccb80cf8..bd808eb312ade7122973a47f4b96505829511da5 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetTitleTextPacket(Component title) {
this.text = title;
@@ -17,6 +18,11 @@ public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketLis
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
2022-06-07 20:12:34 +02:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
index fd5cdc33c4cc8f24265b450621a13d3ab03644c2..55e21c7b13826f60e3c656f76e1507e0242e0af3 100644
2022-06-07 20:12:34 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
@@ -6,24 +6,42 @@ import net.minecraft.network.chat.Component;
2022-06-07 20:12:34 +02:00
import net.minecraft.network.protocol.Packet;
// Spigot start
2022-07-27 21:18:51 +02:00
-public record ClientboundSystemChatPacket(String content, boolean overlay) implements Packet<ClientGamePacketListener> {
+public record ClientboundSystemChatPacket(@javax.annotation.Nullable net.kyori.adventure.text.Component adventure$content, @javax.annotation.Nullable String content, boolean overlay) implements Packet<ClientGamePacketListener> { // Paper - Adventure
2022-06-07 20:12:34 +02:00
+ @io.papermc.paper.annotation.DoNotUse // Paper - No locale context
2022-07-27 21:18:51 +02:00
public ClientboundSystemChatPacket(Component content, boolean overlay) {
- this(Component.Serializer.toJson(content), overlay);
+ this(null, Component.Serializer.toJson(content), overlay); // Paper - Adventure
2022-06-07 20:12:34 +02:00
}
2022-07-27 21:18:51 +02:00
public ClientboundSystemChatPacket(net.md_5.bungee.api.chat.BaseComponent[] content, boolean overlay) {
- this(net.md_5.bungee.chat.ComponentSerializer.toString(content), overlay);
+ this(null, net.md_5.bungee.chat.ComponentSerializer.toString(content), overlay); // Paper - Adventure
2022-06-07 20:12:34 +02:00
}
// Spigot end
2022-06-08 01:49:14 +02:00
+ // Paper start
+ public ClientboundSystemChatPacket {
+ com.google.common.base.Preconditions.checkArgument(!(adventure$content == null && content == null), "Component adventure$content and String (json) content cannot both be null");
+ }
+
2022-07-27 21:18:51 +02:00
+ public ClientboundSystemChatPacket(net.kyori.adventure.text.Component content, boolean overlay) {
+ this(content, null, overlay);
2022-06-08 01:49:14 +02:00
+ }
2022-06-07 20:12:34 +02:00
+ // Paper end
public ClientboundSystemChatPacket(FriendlyByteBuf buf) {
- this(buf.readComponent(), buf.readBoolean());
+ this(null, io.papermc.paper.adventure.PaperAdventure.asJsonString(buf.readComponent(), buf.adventure$locale), buf.readBoolean()); // Paper - Adventure
}
2022-06-07 20:12:34 +02:00
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
2022-06-08 01:49:14 +02:00
+ if (this.adventure$content != null) {
+ buf.writeComponent(this.adventure$content);
+ } else if (this.content != null) {
buf.writeUtf(this.content, 262144); // Spigot
2022-06-07 20:12:34 +02:00
+ } else {
2022-06-08 01:49:14 +02:00
+ throw new IllegalArgumentException("Must supply either adventure component or string json content");
2022-06-07 20:12:34 +02:00
+ }
+ // Paper end
2022-07-27 21:18:51 +02:00
buf.writeBoolean(this.overlay);
2022-06-07 20:12:34 +02:00
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
2021-06-11 21:23:46 +02:00
index 762a9392ffac3042356709dddd15bb3516048bed..3544e2dc2522e9d6305d727d56e73490015662c2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
2021-06-11 21:23:46 +02:00
@@ -7,6 +7,10 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundTabListPacket implements Packet<ClientGamePacketListener> {
public final Component header;
public final Component footer;
2021-06-11 14:02:28 +02:00
+ // Paper start
+ public net.kyori.adventure.text.Component adventure$header;
+ public net.kyori.adventure.text.Component adventure$footer;
+ // Paper end
2021-06-11 21:23:46 +02:00
public ClientboundTabListPacket(Component header, Component footer) {
this.header = header;
2021-06-11 14:02:28 +02:00
@@ -20,6 +24,13 @@ public class ClientboundTabListPacket implements Packet<ClientGamePacketListener
@Override
2021-06-11 21:23:46 +02:00
public void write(FriendlyByteBuf buf) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (this.adventure$header != null && this.adventure$footer != null) {
+ buf.writeComponent(this.adventure$header);
+ buf.writeComponent(this.adventure$footer);
+ return;
+ }
+ // Paper end
buf.writeComponent(this.header);
buf.writeComponent(this.footer);
}
2022-12-08 17:32:29 +01:00
diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
2023-03-14 19:05:23 +01:00
index 5f051cb22ae77f4d8994b07ac5b963bd0ff05673..7952635a963e28cb670c8f4869664103c7ebfefb 100644
2022-12-08 17:32:29 +01:00
--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java
+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
2023-03-14 19:05:23 +01:00
@@ -61,6 +61,11 @@ public class RegistryDataLoader {
2022-12-08 17:32:29 +01:00
RegistryOps.RegistryInfoLookup registryInfoLookup = createContext(baseRegistryManager, list);
list.forEach((loader) -> {
loader.getSecond().load(resourceManager, registryInfoLookup);
+ // Paper start
+ if (loader.getFirst().key() == Registries.CHAT_TYPE) {
+ Registry.register((Registry<ChatType>) loader.getFirst(), ChatType.RAW, new ChatType(new net.minecraft.network.chat.ChatTypeDecoration("%s", List.of(net.minecraft.network.chat.ChatTypeDecoration.Parameter.CONTENT), net.minecraft.network.chat.Style.EMPTY), new net.minecraft.network.chat.ChatTypeDecoration("%s", List.of(net.minecraft.network.chat.ChatTypeDecoration.Parameter.CONTENT), net.minecraft.network.chat.Style.EMPTY))); // CraftBukkit
+ }
+ // Paper end
});
list.forEach((loader) -> {
Registry<?> registry = loader.getFirst();
2022-07-23 03:56:50 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9b34e401040a45393afbb9e984ff421a89f744a0..3250a9310b57351d6d832a8ef42837d990cf6c99 100644
2022-07-23 03:56:50 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -194,6 +194,7 @@ import org.bukkit.craftbukkit.SpigotTimings; // Spigot
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements CommandSource, AutoCloseable {
public static final Logger LOGGER = LogUtils.getLogger();
+ public static final net.kyori.adventure.text.logger.slf4j.ComponentLogger COMPONENT_LOGGER = net.kyori.adventure.text.logger.slf4j.ComponentLogger.logger(LOGGER.getName()); // Paper
public static final String VANILLA_BRAND = "vanilla";
private static final float AVERAGE_TICK_TIME_SMOOTHING = 0.8F;
private static final int TICK_STATS_SPAN = 100;
@@ -242,8 +243,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private boolean preventProxyConnections;
private boolean pvp;
2022-07-23 03:56:50 +02:00
private boolean allowFlight;
- @Nullable
- private String motd;
+ private net.kyori.adventure.text.Component motd; // Paper - Adventure
2022-07-23 03:56:50 +02:00
private int playerIdleTimeout;
public final long[] tickTimes;
@Nullable
@@ -1232,7 +1232,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private ServerStatus buildServerStatus() {
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
- return new ServerStatus(Component.nullToEmpty(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile());
+ return new ServerStatus(io.papermc.paper.adventure.PaperAdventure.asVanilla(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile()); // Paper - Adventure
}
private ServerStatus.Players buildPlayerStatus() {
@@ -1261,6 +1261,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2023-03-15 13:19:54 +01:00
SpigotTimings.schedulerTimer.startTiming(); // Spigot
this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
SpigotTimings.schedulerTimer.stopTiming(); // Spigot
+ io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
this.profiler.push("commandFunctions");
SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
this.getFunctions().tick();
@@ -1626,10 +1627,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public abstract boolean isCommandBlockEnabled();
public String getMotd() {
- return this.motd;
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.motd); // Paper - Adventure
2022-07-23 03:56:50 +02:00
}
public void setMotd(String motd) {
+ // Paper start - Adventure
+ this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOr(motd, net.kyori.adventure.text.Component.empty());
+ }
2022-07-23 03:56:50 +02:00
+
+ public net.kyori.adventure.text.Component motd() {
+ return this.motd;
2022-07-23 03:56:50 +02:00
+ }
+
+ public void motd(net.kyori.adventure.text.Component motd) {
+ // Paper end - Adventure
2022-07-23 03:56:50 +02:00
this.motd = motd;
}
@@ -2343,39 +2354,29 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
- String s1 = params.decorate(message).getString();
+ // Paper start
+ net.kyori.adventure.text.Component s1 = io.papermc.paper.adventure.PaperAdventure.asAdventure(params.decorate(message));
if (prefix != null) {
- MinecraftServer.LOGGER.info("[{}] {}", prefix, s1);
+ MinecraftServer.COMPONENT_LOGGER.info("[{}] {}", prefix, s1);
} else {
- MinecraftServer.LOGGER.info("{}", s1);
+ MinecraftServer.COMPONENT_LOGGER.info("{}", s1);
+ // Paper end
}
}
// CraftBukkit start
public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").build());
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
public ChatDecorator getChatDecorator() {
- return (entityplayer, ichatbasecomponent) -> {
- // SPIGOT-7127: Console /say and similar
- if (entityplayer == null) {
- return CompletableFuture.completedFuture(ichatbasecomponent);
- }
-
- return CompletableFuture.supplyAsync(() -> {
- AsyncPlayerChatPreviewEvent event = new AsyncPlayerChatPreviewEvent(true, entityplayer.getBukkitEntity(), CraftChatMessage.fromComponent(ichatbasecomponent), new LazyPlayerSet(this));
- String originalFormat = event.getFormat(), originalMessage = event.getMessage();
- this.server.getPluginManager().callEvent(event);
-
- if (originalFormat.equals(event.getFormat()) && originalMessage.equals(event.getMessage()) && event.getPlayer().getName().equalsIgnoreCase(event.getPlayer().getDisplayName())) {
- return ichatbasecomponent;
- }
-
- return CraftChatMessage.fromStringOrNull(String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()));
- }, chatExecutor);
- };
+ // Paper start - moved to ChatPreviewProcessor
2022-12-07 21:16:54 +01:00
+ return ChatDecorator.create((sender, commandSourceStack, message) -> {
+ final io.papermc.paper.adventure.ChatDecorationProcessor processor = new io.papermc.paper.adventure.ChatDecorationProcessor(this, sender, commandSourceStack, message);
+ return processor.process();
+ });
+ // Paper end
// CraftBukkit end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index ba89c0d7ae99e53350249365d0e035e6f14e1c5f..dc87e56cfcd59bc1505f5b3c0363038e790271a0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2023-03-14 19:05:23 +01:00
@@ -161,6 +161,7 @@ import net.minecraft.world.scores.Score;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.Team;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import org.bukkit.Bukkit;
import org.bukkit.Location;
2021-11-23 12:27:39 +01:00
import org.bukkit.WeatherType;
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -243,6 +244,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
public String displayName;
+ public net.kyori.adventure.text.Component adventure$displayName; // Paper
public Component listName;
public org.bukkit.Location compassTarget;
public int newExp = 0;
2023-06-07 19:18:05 +02:00
@@ -325,6 +327,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
this.displayName = this.getScoreboardName();
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
2021-06-11 21:23:46 +02:00
this.bukkitPickUpLoot = true;
2021-06-11 14:02:28 +02:00
this.maxHealthCache = this.getMaxHealth();
}
2023-06-07 19:18:05 +02:00
@@ -818,22 +821,17 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
String deathmessage = defaultMessage.getString();
this.keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
2021-06-11 14:02:28 +02:00
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure
// SPIGOT-943 - only call if they have an inventory open
if (this.containerMenu != this.inventoryMenu) {
this.closeContainer();
}
- String deathMessage = event.getDeathMessage();
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
- if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
- Component ichatbasecomponent;
- if (deathMessage.equals(deathmessage)) {
- ichatbasecomponent = this.getCombatTracker().getDeathMessage();
- } else {
- ichatbasecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromStringOrNull(deathMessage);
- }
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
+ Component ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure
2023-06-07 19:18:05 +02:00
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
2022-07-27 21:18:51 +02:00
boolean flag1 = true;
2023-06-07 19:18:05 +02:00
@@ -1774,13 +1772,13 @@ public class ServerPlayer extends Player {
public void sendSystemMessage(Component message, boolean overlay) {
if (this.acceptsSystemMessages(overlay)) {
- this.connection.send(new ClientboundSystemChatPacket(message, overlay), PacketSendListener.exceptionallySend(() -> {
+ this.connection.send(new ClientboundSystemChatPacket(PaperAdventure.asAdventure(message), overlay), PacketSendListener.exceptionallySend(() -> { // Paper - Adventure
if (this.acceptsSystemMessages(false)) {
boolean flag1 = true;
String s = message.getString(256);
MutableComponent ichatmutablecomponent = Component.literal(s).withStyle(ChatFormatting.YELLOW);
- return new ClientboundSystemChatPacket(Component.translatable("multiplayer.message_not_delivered", ichatmutablecomponent).withStyle(ChatFormatting.RED), false);
+ return new ClientboundSystemChatPacket(PaperAdventure.asAdventure(Component.translatable("multiplayer.message_not_delivered", ichatmutablecomponent).withStyle(ChatFormatting.RED)), false); // Paper - Adventure
} else {
return null;
}
2023-06-07 19:18:05 +02:00
@@ -1789,8 +1787,13 @@ public class ServerPlayer extends Player {
}
2022-12-07 18:53:34 +01:00
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
+ // Paper start
2022-08-06 00:58:34 +02:00
+ this.sendChatMessage(message, filterMaskEnabled, params, null);
+ }
2022-12-07 18:53:34 +01:00
+ public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params, @Nullable Component unsigned) {
+ // Paper end
if (this.acceptsChatMessages()) {
2022-08-06 00:58:34 +02:00
- message.sendToPlayer(this, filterMaskEnabled, params);
+ message.sendToPlayer(this, filterMaskEnabled, params, unsigned); // Paper
}
}
2023-06-07 19:18:05 +02:00
@@ -1808,6 +1811,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
}
public String locale = "en_us"; // CraftBukkit - add, lowercase
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
public void updateOptions(ServerboundClientInformationPacket packet) {
// CraftBukkit start
2021-11-23 12:27:39 +01:00
if (getMainArm() != packet.mainHand()) {
2023-06-07 19:18:05 +02:00
@@ -1819,6 +1823,10 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
this.server.server.getPluginManager().callEvent(event);
}
this.locale = packet.language;
+ // Paper start
+ this.adventure$locale = net.kyori.adventure.translation.Translator.parseLocale(this.locale);
+ this.connection.connection.channel.attr(PaperAdventure.LOCALE_ATTRIBUTE).set(this.adventure$locale);
+ // Paper end
this.clientViewDistance = packet.viewDistance;
// CraftBukkit end
2021-11-23 12:27:39 +01:00
this.chatVisibility = packet.chatVisibility();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index c77e561ab7598846cb3de2aaee3e59e34d48215f..9e47f748ff6ccdb5791828ac8c41684ba2682fbd 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-03-14 19:05:23 +01:00
@@ -187,6 +187,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
2022-03-01 06:43:03 +01:00
import org.slf4j.Logger;
2021-06-11 14:02:28 +02:00
// CraftBukkit start
+import io.papermc.paper.adventure.ChatProcessor; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
2022-12-07 18:53:34 +01:00
import com.mojang.datafixers.util.Pair;
import java.util.Arrays;
2021-06-11 14:02:28 +02:00
import java.util.concurrent.ExecutionException;
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -252,7 +254,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2023-03-14 20:24:52 +01:00
private static final int NO_BLOCK_UPDATES_TO_ACK = -1;
private static final int TRACKED_MESSAGE_DISCONNECT_THRESHOLD = 4096;
private static final Component CHAT_VALIDATION_FAILED = Component.translatable("multiplayer.disconnect.chat_validation_failed");
- private final Connection connection;
+ public final Connection connection; // Paper
private final MinecraftServer server;
public ServerPlayer player;
private int tickCount;
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -440,14 +442,17 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
return this.server.isSingleplayerOwner(this.player.getGameProfile());
}
- // CraftBukkit start
- @Deprecated
- public void disconnect(Component reason) {
2021-06-11 21:23:46 +02:00
- this.disconnect(CraftChatMessage.fromComponent(reason));
2023-03-23 22:57:03 +01:00
+ public void disconnect(String s) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s));
2023-03-23 22:57:03 +01:00
}
- // CraftBukkit end
- public void disconnect(String s) {
2021-06-11 14:02:28 +02:00
+ public void disconnect(final Component reason) {
+ this.disconnect(PaperAdventure.asAdventure(reason));
+ }
+
+ public void disconnect(net.kyori.adventure.text.Component reason) {
+ // Paper end
// CraftBukkit start - fire PlayerKickEvent
if (this.processedDisconnect) {
return;
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -456,7 +461,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-27 21:18:51 +02:00
Waitable waitable = new Waitable() {
@Override
protected Object evaluate() {
- ServerGamePacketListenerImpl.this.disconnect(s);
2022-12-07 18:53:34 +01:00
+ ServerGamePacketListenerImpl.this.disconnect(reason); // Paper - adventure
2022-07-27 21:18:51 +02:00
return null;
}
};
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -473,9 +478,9 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-07-27 21:18:51 +02:00
return;
2021-06-11 14:02:28 +02:00
}
2022-07-27 21:18:51 +02:00
2021-06-11 14:02:28 +02:00
- String leaveMessage = ChatFormatting.YELLOW + this.player.getScoreboardName() + " left the game.";
+ net.kyori.adventure.text.Component leaveMessage = net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? this.player.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(this.player.getScoreboardName())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
- PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), s, leaveMessage);
2021-06-11 21:23:46 +02:00
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), reason, leaveMessage); // Paper - Adventure
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
if (this.cserver.getServer().isRunning()) {
this.cserver.getPluginManager().callEvent(event);
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -487,7 +492,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
}
this.player.kickLeaveMessage = event.getLeaveMessage(); // CraftBukkit - SPIGOT-3034: Forward leave message to PlayerQuitEvent
2021-06-11 14:02:28 +02:00
// Send the possibly modified leave message
2022-07-27 21:18:51 +02:00
- final Component ichatbasecomponent = CraftChatMessage.fromString(event.getReason(), true)[0];
2021-06-11 14:02:28 +02:00
+ final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end
2022-07-27 21:18:51 +02:00
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), PacketSendListener.thenRun(() -> {
@@ -1786,9 +1791,11 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
*/
this.player.disconnect();
2021-11-23 12:27:39 +01:00
- String quitMessage = this.server.getPlayerList().remove(this.player);
2021-06-11 14:02:28 +02:00
- if ((quitMessage != null) && (quitMessage.length() > 0)) {
2021-11-23 12:27:39 +01:00
- this.server.getPlayerList().broadcastMessage(CraftChatMessage.fromString(quitMessage));
2021-06-11 14:02:28 +02:00
+ // Paper start - Adventure
2021-11-23 12:27:39 +01:00
+ net.kyori.adventure.text.Component quitMessage = this.server.getPlayerList().remove(this.player);
2021-06-11 14:02:28 +02:00
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
2022-07-27 21:18:51 +02:00
+ this.server.getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(quitMessage), false);
2021-06-11 14:02:28 +02:00
+ // Paper end
}
// CraftBukkit end
2021-06-11 21:23:46 +02:00
this.player.getTextFilter().leave();
@@ -1885,11 +1892,11 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2022-12-07 18:53:34 +01:00
}
CompletableFuture<FilteredText> completablefuture = this.filterTextPacket(playerchatmessage.signedContent());
- CompletableFuture<Component> completablefuture1 = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
+ CompletableFuture<net.minecraft.network.chat.ChatDecorator.Result> completablefuture1 = this.server.getChatDecorator().decorate(this.player, null, playerchatmessage.decoratedContent()); // Paper
this.chatMessageChain.append((executor) -> {
return CompletableFuture.allOf(completablefuture, completablefuture1).thenAcceptAsync((ovoid) -> {
- PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent((Component) completablefuture1.join()).filter(((FilteredText) completablefuture.join()).mask());
2022-12-08 17:32:29 +01:00
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.filter(((FilteredText) completablefuture.join()).mask()).withResult(completablefuture1.join()); // Paper
2022-12-07 18:53:34 +01:00
this.broadcastChatMessage(playerchatmessage1);
}, this.server.chatExecutor); // CraftBukkit - async chat
@@ -1995,7 +2002,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(acknowledgment);
2023-03-14 19:05:23 +01:00
if (this.player.isRemoved() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { // CraftBukkit - dead men tell no tales
- this.send(new ClientboundSystemChatPacket(Component.translatable("chat.disabled.options").withStyle(ChatFormatting.RED), false));
+ this.send(new ClientboundSystemChatPacket(PaperAdventure.asAdventure(Component.translatable("chat.disabled.options").withStyle(ChatFormatting.RED)), false)); // Paper - Adventure
return Optional.empty();
} else {
this.player.resetLastActionTime();
@@ -2053,7 +2060,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
2021-06-11 14:02:28 +02:00
this.handleCommand(s);
} else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) {
// Do nothing, this is coming from a plugin
- } else {
+ // Paper start
+ } else if (true) {
+ final ChatProcessor cp = new ChatProcessor(this.server, this.player, original, async);
2021-06-11 14:02:28 +02:00
+ cp.process();
2021-06-11 21:23:46 +02:00
+ // Paper end
2021-06-11 14:02:28 +02:00
+ } else if (false) { // Paper
2021-06-11 21:23:46 +02:00
Player player = this.getCraftPlayer();
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(this.server));
2022-07-27 21:18:51 +02:00
String originalFormat = event.getFormat(), originalMessage = event.getMessage();
@@ -2183,7 +2195,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
}
});
} else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) { // Re-add "Command Only" flag check
- this.send(new ClientboundSystemChatPacket(Component.translatable("chat.cannotSend").withStyle(ChatFormatting.RED), false));
+ this.send(new ClientboundSystemChatPacket(PaperAdventure.asAdventure(Component.translatable("chat.cannotSend").withStyle(ChatFormatting.RED)), false)); // Paper - Adventure
} else {
this.chat(s, message, true);
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2023-03-14 19:05:23 +01:00
index 1aae5c4c85efbaab626fa3776252b046618ae1cc..7983033160b77e28eb8135f8709dacd6b806ebe3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2022-12-07 18:53:34 +01:00
@@ -323,7 +323,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2021-06-11 14:02:28 +02:00
if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
- event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
+ event.disallow(asyncEvent.getResult(), asyncEvent.kickMessage()); // Paper - Adventure
}
Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
@Override
2022-12-07 18:53:34 +01:00
@@ -334,12 +334,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2021-06-11 14:02:28 +02:00
ServerLoginPacketListenerImpl.this.server.processQueue.add(waitable);
if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
2021-06-11 21:23:46 +02:00
- ServerLoginPacketListenerImpl.this.disconnect(event.getKickMessage());
2022-03-01 06:43:03 +01:00
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
return;
}
} else {
if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
2021-06-11 21:23:46 +02:00
- ServerLoginPacketListenerImpl.this.disconnect(asyncEvent.getKickMessage());
2022-03-01 06:43:03 +01:00
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
return;
}
}
diff --git a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
2023-03-14 19:05:23 +01:00
index 1cb95db25a20d38faacd99a5805630c1598e9db3..d99b2235038eb1aba8cda474c4aa51e207149ef4 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
2023-03-14 19:05:23 +01:00
@@ -57,7 +57,7 @@ public class ServerStatusPacketListenerImpl implements ServerStatusPacketListene
2021-06-11 14:02:28 +02:00
CraftIconCache icon = server.server.getServerIcon();
ServerListPingEvent() {
2023-03-14 19:05:23 +01:00
- super(connection.hostname, ((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), server.getMotd(), server.getPlayerList().getMaxPlayers());
+ super(connection.hostname, ((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), server.server.motd(), server.getPlayerList().getMaxPlayers()); // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
@Override
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index edf629f2e810eebf014b1565021888f96def92a1..d3dc7752aadf36985660d04dcb4377a69dfeddff 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2022-03-04 22:19:57 +01:00
@@ -8,6 +8,7 @@ import com.mojang.logging.LogUtils;
2021-06-11 14:02:28 +02:00
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import io.netty.buffer.Unpooled;
+import io.papermc.paper.adventure.PaperAdventure;
import java.io.File;
import java.net.SocketAddress;
2021-07-07 08:52:40 +02:00
import java.nio.file.Path;
2023-06-07 19:18:05 +02:00
@@ -283,7 +284,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// CraftBukkit start
2022-06-07 20:12:34 +02:00
ichatmutablecomponent.withStyle(ChatFormatting.YELLOW);
- String joinMessage = CraftChatMessage.fromComponent(ichatmutablecomponent);
+ Component joinMessage = ichatmutablecomponent; // Paper - Adventure
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
2023-03-14 19:05:23 +01:00
ServerStatus serverping = this.server.getStatus();
2023-06-07 19:18:05 +02:00
@@ -304,19 +305,18 @@ public abstract class PlayerList {
// Ensure that player inventory is populated with its viewer
player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
2021-06-11 14:02:28 +02:00
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, joinMessage);
2022-06-07 20:12:34 +02:00
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(playerJoinEvent);
2021-06-11 14:02:28 +02:00
2023-03-14 19:05:23 +01:00
if (!player.connection.isAcceptingMessages()) {
2021-06-11 14:02:28 +02:00
return;
}
- joinMessage = playerJoinEvent.getJoinMessage();
+ final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
- if (joinMessage != null && joinMessage.length() > 0) {
2022-07-28 00:10:27 +02:00
- for (Component line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
- this.server.getPlayerList().broadcastSystemMessage(line, false);
- }
2021-06-11 14:02:28 +02:00
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
+ joinMessage = PaperAdventure.asVanilla(jm); // Paper - Adventure
2022-07-27 21:18:51 +02:00
+ this.server.getPlayerList().broadcastSystemMessage(joinMessage, false); // Paper - Adventure
2022-07-28 00:10:27 +02:00
}
// CraftBukkit end
2023-06-07 20:03:53 +02:00
@@ -513,7 +513,7 @@ public abstract class PlayerList {
}
- public String remove(ServerPlayer entityplayer) { // CraftBukkit - return string
+ public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // CraftBukkit - return string // Paper - return Component
ServerLevel worldserver = entityplayer.serverLevel();
entityplayer.awardStat(Stats.LEAVE_GAME);
2023-06-07 19:18:05 +02:00
@@ -524,7 +524,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
entityplayer.closeContainer();
}
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), entityplayer.kickLeaveMessage != null ? entityplayer.kickLeaveMessage : "\u00A7e" + entityplayer.getScoreboardName() + " left the game");
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(playerQuitEvent);
2021-06-11 14:02:28 +02:00
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
2023-06-07 19:18:05 +02:00
@@ -577,7 +577,7 @@ public abstract class PlayerList {
2021-06-11 21:23:46 +02:00
this.cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
2021-06-11 14:02:28 +02:00
// CraftBukkit end
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
}
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
2023-06-07 19:18:05 +02:00
@@ -623,10 +623,10 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// return chatmessage;
2022-06-07 20:12:34 +02:00
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
2021-06-11 14:02:28 +02:00
} else if (!this.isWhiteListed(gameprofile)) {
2022-06-07 20:12:34 +02:00
ichatmutablecomponent = Component.translatable("multiplayer.disconnect.not_whitelisted");
2021-06-11 14:02:28 +02:00
- event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure
2021-06-11 21:23:46 +02:00
} else if (this.getIpBans().isBanned(socketaddress) && !this.getIpBans().get(socketaddress).hasExpired()) {
2021-06-11 14:02:28 +02:00
IpBanListEntry ipbanentry = this.ipBans.get(socketaddress);
2023-06-07 19:18:05 +02:00
@@ -636,17 +636,17 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// return chatmessage;
2022-06-07 20:12:34 +02:00
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
2021-06-11 14:02:28 +02:00
} else {
2022-06-07 20:12:34 +02:00
// return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
2021-06-11 14:02:28 +02:00
if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
- event.disallow(PlayerLoginEvent.Result.KICK_FULL, org.spigotmc.SpigotConfig.serverFullMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
}
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
- loginlistener.disconnect(event.getKickMessage());
+ loginlistener.disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
return null;
}
return entity;
2023-06-07 19:18:05 +02:00
@@ -1157,7 +1157,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
public void removeAll() {
// CraftBukkit start - disconnect safely
for (ServerPlayer player : this.players) {
- player.connection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
+ player.connection.disconnect(this.server.server.shutdownMessage()); // CraftBukkit - add custom shutdown message // Paper - Adventure
}
// CraftBukkit end
2023-06-07 19:18:05 +02:00
@@ -1198,24 +1198,43 @@ public abstract class PlayerList {
}
2022-08-06 00:58:34 +02:00
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
+ // Paper start
2022-08-06 00:58:34 +02:00
+ this.broadcastChatMessage(message, sender, params, null);
+ }
2022-08-06 00:58:34 +02:00
+ public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
+ // Paper end
Objects.requireNonNull(sender);
2022-12-07 18:53:34 +01:00
- this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, params);
+ this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, params, unsignedFunction); // Paper
}
2022-12-07 18:53:34 +01:00
private void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatType.Bound params) {
+ // Paper start
2022-12-07 18:53:34 +01:00
+ this.broadcastChatMessage(message, shouldSendFiltered, sender, params, null);
+ }
2022-12-07 18:53:34 +01:00
+ public void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
+ // Paper end
2022-12-07 18:53:34 +01:00
boolean flag = this.verifyChatTrusted(message);
- this.server.logChatMessage(message.decoratedContent(), params, flag ? null : "Not Secure");
+ this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), params, flag ? null : "Not Secure"); // Paper
2022-12-07 18:53:34 +01:00
OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(message);
boolean flag1 = false;
boolean flag2;
2023-06-08 00:28:06 +02:00
+ Packet<?> disguised = sender != null && unsignedFunction == null ? new net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket(outgoingchatmessage.content(), params.toNetwork(sender.level().registryAccess())) : null; // Paper - don't send player chat packets from vanished players
for (Iterator iterator = this.players.iterator(); iterator.hasNext(); flag1 |= flag2 && message.isFullyFiltered()) {
ServerPlayer entityplayer1 = (ServerPlayer) iterator.next();
2022-12-07 18:53:34 +01:00
flag2 = shouldSendFiltered.test(entityplayer1);
- entityplayer1.sendChatMessage(outgoingchatmessage, flag2, params);
+ // Paper start - don't send player chat packets from vanished players
+ if (sender != null && !entityplayer1.getBukkitEntity().canSee(sender.getBukkitEntity())) {
+ entityplayer1.connection.send(unsignedFunction != null
2023-06-08 00:28:06 +02:00
+ ? new net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket(unsignedFunction.apply(entityplayer1.getBukkitEntity()), params.toNetwork(sender.level().registryAccess()))
+ : disguised);
+ continue;
+ }
+ // Paper end
2022-12-07 18:53:34 +01:00
+ entityplayer1.sendChatMessage(outgoingchatmessage, flag2, params, unsignedFunction == null ? null : unsignedFunction.apply(entityplayer1.getBukkitEntity())); // Paper
}
if (flag1 && sender != null) {
2023-06-07 19:18:05 +02:00
@@ -1224,7 +1243,7 @@ public abstract class PlayerList {
}
2022-12-07 18:53:34 +01:00
- private boolean verifyChatTrusted(PlayerChatMessage message) {
+ public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public
return message.hasSignature() && !message.hasExpiredServer(Instant.now());
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/BossEvent.java b/src/main/java/net/minecraft/world/BossEvent.java
2022-03-01 06:43:03 +01:00
index 4c62df5a3781ec9df4a5c5f1b528649e6e8a62d1..affd1b8c7589ba59330dc0b6fc803cce4ee57397 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/BossEvent.java
+++ b/src/main/java/net/minecraft/world/BossEvent.java
@@ -13,6 +13,7 @@ public abstract class BossEvent {
2021-06-11 14:02:28 +02:00
protected boolean darkenScreen;
protected boolean playBossMusic;
protected boolean createWorldFog;
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
public BossEvent(UUID uuid, Component name, BossEvent.BossBarColor color, BossEvent.BossBarOverlay style) {
this.id = uuid;
@@ -27,61 +28,75 @@ public abstract class BossEvent {
}
public Component getName() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.name()); // Paper
return this.name;
}
public void setName(Component name) {
+ if (this.adventure != null) this.adventure.name(io.papermc.paper.adventure.PaperAdventure.asAdventure(name)); // Paper
this.name = name;
}
public float getProgress() {
+ if (this.adventure != null) return this.adventure.progress(); // Paper
return this.progress;
}
2022-03-01 06:43:03 +01:00
public void setProgress(float percent) {
+ if (this.adventure != null) this.adventure.progress(percent); // Paper
this.progress = percent;
}
public BossEvent.BossBarColor getColor() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.color()); // Paper
return this.color;
}
public void setColor(BossEvent.BossBarColor color) {
+ if (this.adventure != null) this.adventure.color(io.papermc.paper.adventure.PaperAdventure.asAdventure(color)); // Paper
this.color = color;
}
public BossEvent.BossBarOverlay getOverlay() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.overlay()); // Paper
return this.overlay;
}
public void setOverlay(BossEvent.BossBarOverlay style) {
+ if (this.adventure != null) this.adventure.overlay(io.papermc.paper.adventure.PaperAdventure.asAdventure(style)); // Paper
this.overlay = style;
}
public boolean shouldDarkenScreen() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN); // Paper
return this.darkenScreen;
}
public BossEvent setDarkenScreen(boolean darkenSky) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN, darkenSky); // Paper
this.darkenScreen = darkenSky;
return this;
}
public boolean shouldPlayBossMusic() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC); // Paper
return this.playBossMusic;
}
public BossEvent setPlayBossMusic(boolean dragonMusic) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, dragonMusic); // Paper
this.playBossMusic = dragonMusic;
return this;
}
public BossEvent setCreateWorldFog(boolean thickenFog) {
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, thickenFog); // Paper
this.createWorldFog = thickenFog;
return this;
}
public boolean shouldCreateWorldFog() {
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG); // Paper
return this.createWorldFog;
}
2023-06-07 19:18:05 +02:00
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
index f0c08f3a5094e1faaed70ffdc0eb5b6dd16ed500..8b26e90c0e7affb23fe8f92d757fe3a690b858ec 100644
2023-06-07 19:18:05 +02:00
--- a/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SignBlockEntity.java
@@ -211,22 +211,22 @@ public class SignBlockEntity extends BlockEntity implements CommandSource { // C
2023-06-07 20:03:53 +02:00
// CraftBukkit start
Player player = ((ServerPlayer) entityhuman).getBukkitEntity();
- String[] lines = new String[4];
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>(); // Paper - adventure
2023-06-07 20:03:53 +02:00
for (int i = 0; i < list.size(); ++i) {
- lines[i] = CraftChatMessage.fromComponent(signtext.getMessage(i, entityhuman.isTextFilteringEnabled()));
+ lines.add(io.papermc.paper.adventure.PaperAdventure.asAdventure(signtext.getMessage(i, entityhuman.isTextFilteringEnabled()))); // Paper - Adventure
}
2023-06-07 20:03:53 +02:00
- SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, lines.clone(), (front) ? Side.FRONT : Side.BACK);
+ SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, new java.util.ArrayList<>(lines), (front) ? Side.FRONT : Side.BACK); // Paper - Adventure
entityhuman.level().getCraftServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return originalText;
}
- Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
+ Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.lines()); // Paper - Adventure
for (int i = 0; i < components.length; i++) {
- if (!Objects.equals(lines[i], event.getLine(i))) {
+ if (!Objects.equals(lines.get(i), event.line(i))) { // Paper - Adventure
signtext = signtext.setMessage(i, components[i]);
2023-06-07 20:03:53 +02:00
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
2023-06-07 19:18:05 +02:00
index 614e567eb1ef10ac7514909a8425e29ac3627d3d..60596c4ac2ebb8caf19d65591624275ba63b0199 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
2022-03-01 06:43:03 +01:00
@@ -33,6 +33,7 @@ import net.minecraft.world.level.saveddata.SavedData;
import org.slf4j.Logger;
2021-06-11 14:02:28 +02:00
// CraftBukkit start
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.util.UUID;
2021-06-11 21:23:46 +02:00
import org.bukkit.Bukkit;
2021-11-23 12:27:39 +01:00
import org.bukkit.craftbukkit.CraftServer;
@@ -598,7 +599,7 @@ public class MapItemSavedData extends SavedData {
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
for (org.bukkit.map.MapCursor cursor : render.cursors) {
if (cursor.isVisible()) {
- icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
+ icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), PaperAdventure.asVanilla(cursor.caption()))); // Paper - Adventure
}
2021-06-11 14:02:28 +02:00
}
2021-06-11 21:23:46 +02:00
collection = icons;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index c3c30cbb74062fc25c1daf9b17c8956857766306..85867893da6bb4f24e86c32ea9fd5ff5b5684dbb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -608,8 +608,10 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
@Override
+ @Deprecated // Paper start
public int broadcastMessage(String message) {
2021-06-11 21:23:46 +02:00
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
2021-06-11 14:02:28 +02:00
+ // Paper end
}
@Override
@@ -1465,7 +1467,15 @@ public final class CraftServer implements Server {
2021-06-11 21:23:46 +02:00
return this.configuration.getInt("settings.spawn-radius", -1);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
2023-03-23 22:57:03 +01:00
+ @Override
2021-06-11 14:02:28 +02:00
+ public net.kyori.adventure.text.Component shutdownMessage() {
+ String msg = getShutdownMessage();
+ return msg != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(msg) : null;
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
2023-03-23 22:57:03 +01:00
@Override
2021-06-11 14:02:28 +02:00
+ @Deprecated // Paper
public String getShutdownMessage() {
2021-06-11 21:23:46 +02:00
return this.configuration.getString("settings.shutdown-message");
2021-06-11 14:02:28 +02:00
}
@@ -1633,7 +1643,20 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
@Override
+ @Deprecated // Paper
public int broadcast(String message, String permission) {
+ // Paper start - Adventure
+ return this.broadcast(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message), permission);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public int broadcast(net.kyori.adventure.text.Component message) {
+ return this.broadcast(message, BROADCAST_CHANNEL_USERS);
+ }
+
+ @Override
+ public int broadcast(net.kyori.adventure.text.Component message, String permission) {
+ // Paper end
Set<CommandSender> recipients = new HashSet<>();
2021-06-11 21:23:46 +02:00
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
2021-06-11 14:02:28 +02:00
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
@@ -1641,14 +1664,14 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
}
- BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.getPluginManager().callEvent(broadcastMessageEvent);
2021-06-11 14:02:28 +02:00
if (broadcastMessageEvent.isCancelled()) {
return 0;
}
- message = broadcastMessageEvent.getMessage();
+ message = broadcastMessageEvent.message(); // Paper - Adventure
for (CommandSender recipient : recipients) {
recipient.sendMessage(message);
@@ -1900,6 +1923,14 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Preconditions.checkArgument(type.isCreatable(), "Cannot open an inventory of type ", type);
2021-06-11 14:02:28 +02:00
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
Preconditions.checkArgument(type != null, "InventoryType cannot be null");
@@ -1914,13 +1945,28 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
+ Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
2021-06-11 14:02:28 +02:00
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got %s)", size);
2021-06-11 14:02:28 +02:00
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
}
+ // Paper start
2023-03-23 22:57:03 +01:00
+ @Override
2021-06-11 14:02:28 +02:00
+ public Merchant createMerchant(net.kyori.adventure.text.Component title) {
+ return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
+ }
+ // Paper end
2023-03-23 22:57:03 +01:00
@Override
2021-06-11 14:02:28 +02:00
+ @Deprecated // Paper
public Merchant createMerchant(String title) {
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
}
@@ -1985,6 +2031,17 @@ public final class CraftServer implements Server {
2021-06-11 21:23:46 +02:00
return Thread.currentThread().equals(console.serverThread) || this.console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
2021-06-11 14:02:28 +02:00
}
+ // Paper start - Adventure
2021-06-11 14:02:28 +02:00
+ @Override
+ public net.kyori.adventure.text.Component motd() {
+ return this.console.motd();
+ }
+ @Override
+ public void motd(final net.kyori.adventure.text.Component motd) {
+ this.console.motd(motd);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
2021-06-11 14:02:28 +02:00
@Override
public String getMotd() {
2021-06-11 21:23:46 +02:00
return this.console.getMotd();
@@ -2419,4 +2476,53 @@ public final class CraftServer implements Server {
return this.spigot;
2021-06-11 14:02:28 +02:00
}
// Spigot end
2021-06-11 14:02:28 +02:00
+
+ // Paper start - adventure sounds
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
+ for (ServerPlayer player : this.playerList.getPlayers()) {
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
+ }
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong), this.playSound0(x, y, z, this.console.getAllLevels()));
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
+ final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
+ for (ServerPlayer player : this.playerList.getPlayers()) {
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
+ }
+ } else if (emitter instanceof org.bukkit.craftbukkit.entity.CraftEntity craftEntity) {
+ final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
2023-06-08 00:12:41 +02:00
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ(), List.of((ServerLevel) entity.level())));
+ } else {
+ throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
+ }
+ }
+
+ private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z, final Iterable<ServerLevel> levels) {
+ return (packet, distance) -> {
+ for (final ServerLevel level : levels) {
+ level.getServer().getPlayerList().broadcast(null, x, y, z, distance, level.dimension(), packet);
+ }
+ };
+ }
+ // Paper end
+
2021-06-11 14:02:28 +02:00
+ // Paper start
+ private Iterable<? extends net.kyori.adventure.audience.Audience> adventure$audiences;
+ @Override
+ public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
+ if (this.adventure$audiences == null) {
+ this.adventure$audiences = com.google.common.collect.Iterables.concat(java.util.Collections.singleton(this.getConsoleSender()), this.getOnlinePlayers());
+ }
+ return this.adventure$audiences;
+ }
+ // Paper end
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 379b8a7d94c784db54ada01ad6bd04a54f8a089f..73f61f2b0c0aeefabb7b7bba7ca37914751dcc42 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -152,6 +152,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY);
+ private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
private static final Random rand = new Random();
@@ -1603,6 +1604,39 @@ public class CraftWorld extends CraftRegionAccessor implements World {
entityTracker.broadcastAndSend(packet);
}
}
+ // Paper start - Adventure
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
+ final long seed = sound.seed().orElseGet(this.world.getRandom()::nextLong);
+ for (ServerPlayer player : this.getHandle().players()) {
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
+ }
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
+ final long seed = sound.seed().orElseGet(this.getHandle().getRandom()::nextLong);
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
+ for (ServerPlayer player : this.getHandle().players()) {
+ player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
+ }
+ } else if (emitter instanceof CraftEntity craftEntity) {
+ final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
+ io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ()));
+ } else {
+ throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
+ }
+ }
+
+ private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z) {
+ return (packet, distance) -> this.world.getServer().getPlayerList().broadcast(null, x, y, z, distance, this.world.dimension(), packet);
+ }
+ // Paper end
private static Map<String, GameRules.Key<?>> gamerules;
public static synchronized Map<String, GameRules.Key<?>> getGameRulesNMS() {
@@ -1997,5 +2031,18 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return ret;
}
+
+ // Paper start - implement pointers
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUID)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
// Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
2023-06-07 19:18:05 +02:00
index 60ca15373b489941555315bf6fb311326670e7de..15b886634112b2a18b7952107b49ae1430376a3d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2023-03-14 19:05:23 +01:00
@@ -20,6 +20,12 @@ public class Main {
2021-12-10 15:24:07 +01:00
public static boolean useConsole = true;
2021-12-10 15:24:07 +01:00
public static void main(String[] args) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");
+ if (false && System.getProperty(warnWhenLegacyFormattingDetected) == null) {
+ System.setProperty(warnWhenLegacyFormattingDetected, String.valueOf(true));
+ }
+ // Paper end
// Todo: Installation script
OptionParser parser = new OptionParser() {
{
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
index 9d55f36f146435f0cfb4e62ffa7c94eab404a596..c186a44b927188ed222f8b2f8f76aaef35d9c654 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
@@ -68,6 +68,19 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
2021-06-11 14:02:28 +02:00
this.getSnapshot().secondaryPower = (effect != null) ? MobEffect.byId(effect.getId()) : null;
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final BeaconBlockEntity be = this.getSnapshot();
+ return be.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.name) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
BeaconBlockEntity beacon = this.getSnapshot();
2021-09-30 23:28:02 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
2022-06-08 10:45:59 +02:00
index 02fc6b189541fdedd0acef6700722eb7e53346c4..c4ea6760f489e6171f9e6e170160b932597f842f 100644
2021-09-30 23:28:02 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
@@ -30,4 +30,16 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
2021-09-30 23:28:02 +02:00
public void setName(String name) {
getSnapshot().getCommandBlock().setName(CraftChatMessage.fromStringOrNull(name != null ? name : "@"));
}
+
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getSnapshot().getCommandBlock().getName());
+ }
+
+ @Override
+ public void name(net.kyori.adventure.text.Component name) {
2022-06-08 10:45:59 +02:00
+ getSnapshot().getCommandBlock().setName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
2021-09-30 23:28:02 +02:00
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
index 05f37f306d623280823c7cf9516027189659f902..65104a0506131373b6b33433a118c7e1cd3696dc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
@@ -27,6 +27,19 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
2021-06-11 14:02:28 +02:00
this.getSnapshot().lockKey = (key == null) ? LockCode.NO_LOCK : new LockCode(key);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final T be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
T container = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
index 0beb96dc896f63003e1b1ae458b73902bdbe648a..102eb86bad3000f258775ac06ecd1a6dad174b0a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
@@ -11,6 +11,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantmentTable
super(world, tileEntity);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final EnchantmentTableBlockEntity be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
EnchantmentTableBlockEntity enchant = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
index 116c127381fe95825e719f4af8dfdf36d11048e0..8ce466c19dae6534be828779639aedb687a94e68 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
2023-06-07 19:18:05 +02:00
@@ -25,6 +25,23 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
this.back = new CraftSignSide(this.getSnapshot().getBackText());
}
+ // Paper start
+ @Override
+ public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
+ return this.front.lines();
+ }
+
+ @Override
+ public net.kyori.adventure.text.@NotNull Component line(int index) {
+ return this.front.line(index);
+ }
+
+ @Override
+ public void line(int index, net.kyori.adventure.text.@NotNull Component line) {
+ this.front.line(index, line);
+ }
+ // Paper end
+
@Override
public String[] getLines() {
return this.front.getLines();
@@ -104,6 +121,20 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
}
+ // Paper start
+ public static Component[] sanitizeLines(java.util.List<? extends net.kyori.adventure.text.Component> lines) {
+ Component[] components = new Component[4];
+ for (int i = 0; i < 4; i++) {
+ if (i < lines.size() && lines.get(i) != null) {
+ components[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(lines.get(i));
+ } else {
+ components[i] = net.minecraft.network.chat.Component.literal("");
+ }
+ }
+ return components;
+ }
+ // Paper end
+
public static Component[] sanitizeLines(String[] lines) {
Component[] components = new Component[4];
diff --git a/src/main/java/org/bukkit/craftbukkit/block/sign/CraftSignSide.java b/src/main/java/org/bukkit/craftbukkit/block/sign/CraftSignSide.java
index 43f6ac44525048faf0b0cd2c11f9bc36fa0cab5d..1317cdd48c1c27c9e5152da5403237b1bb15ac52 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/sign/CraftSignSide.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/sign/CraftSignSide.java
2023-06-07 19:18:05 +02:00
@@ -12,37 +12,69 @@ import org.jetbrains.annotations.Nullable;
public class CraftSignSide implements SignSide {
2021-06-11 14:02:28 +02:00
// Lazily initialized only if requested:
- private String[] originalLines = null;
- private String[] lines = null;
+ // Paper start
+ private java.util.ArrayList<net.kyori.adventure.text.Component> originalLines = null; // ArrayList for RandomAccess
+ private java.util.ArrayList<net.kyori.adventure.text.Component> lines = null; // ArrayList for RandomAccess
+ // Paper end
private SignText signText;
2021-06-11 14:02:28 +02:00
2023-06-07 19:18:05 +02:00
public CraftSignSide(SignText signText) {
this.signText = signText;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ return this.lines;
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ public net.kyori.adventure.text.@NotNull Component line(final int index) throws IndexOutOfBoundsException {
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ return this.lines.get(index);
+ }
+
+ @Override
+ public void line(final int index, final net.kyori.adventure.text.@NotNull Component line) throws IndexOutOfBoundsException {
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ this.lines.set(index, line);
+ }
+
+ private void loadLines() {
+ if (this.lines != null) {
2021-06-11 14:02:28 +02:00
+ return;
2021-06-11 21:23:46 +02:00
+ }
2021-06-11 14:02:28 +02:00
+ // Lazy initialization:
2023-06-07 19:18:05 +02:00
+ this.lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(this.signText.getMessages(false)));
+ this.originalLines = new java.util.ArrayList<>(this.lines);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
@NotNull
@Override
public String[] getLines() {
- if (this.lines == null) {
- // Lazy initialization:
2023-06-07 19:18:05 +02:00
- Component[] messages = this.signText.getMessages(false);
- this.lines = new String[messages.length];
- System.arraycopy(CraftSign.revertComponents(messages), 0, lines, 0, lines.length);
- this.originalLines = new String[lines.length];
- System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
- }
- return this.lines;
+ // Paper start
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ return this.lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
+ // Paper end
}
@NotNull
2021-06-11 14:02:28 +02:00
@Override
public String getLine(int index) throws IndexOutOfBoundsException {
2021-06-11 21:23:46 +02:00
- return this.getLines()[index];
+ // Paper start
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.lines.get(index));
+ // Paper end
2021-06-11 14:02:28 +02:00
}
@Override
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
2021-06-11 21:23:46 +02:00
- this.getLines()[index] = line;
+ // Paper start
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ this.lines.set(index, line != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(line) : net.kyori.adventure.text.Component.empty());
+ // Paper end
2021-06-11 14:02:28 +02:00
}
@Override
2023-06-07 19:18:05 +02:00
@@ -68,13 +100,16 @@ public class CraftSignSide implements SignSide {
2021-06-11 14:02:28 +02:00
public SignText applyLegacyStringToSignSide() {
2021-06-11 21:23:46 +02:00
if (this.lines != null) {
2021-06-11 14:02:28 +02:00
- for (int i = 0; i < lines.length; i++) {
2021-06-11 21:23:46 +02:00
- String line = (this.lines[i] == null) ? "" : this.lines[i];
- if (line.equals(this.originalLines[i])) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ for (int i = 0; i < this.lines.size(); ++i) {
+ net.kyori.adventure.text.Component component = this.lines.get(i);
+ net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
+ if (component.equals(origComp)) {
continue; // The line contents are still the same, skip.
}
- this.signText = this.signText.setMessage(i, CraftChatMessage.fromString(line)[0]);
+ this.signText = this.signText.setMessage(i, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
2021-06-11 14:02:28 +02:00
}
+ // Paper end
}
return this.signText;
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
index 3de88112bdb08d6bd0d28f20582c4090bfd8dbfe..87f2cea36d852c81fdb0a1bc21162d41377ab2e7 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
@@ -45,6 +45,18 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
return this.block.getTextName();
}
+ // Paper start
+ @Override
+ public void sendMessage(net.kyori.adventure.identity.Identity identity, net.kyori.adventure.text.Component message, net.kyori.adventure.audience.MessageType type) {
+ block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message));
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
index f3cb4102ab223f379f60dac317df7da1fab812a8..324e6d1a4fadd3e557e4ba05f04e6a5891cc54df 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
@@ -46,6 +46,13 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
return "CONSOLE";
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return net.kyori.adventure.text.Component.text(this.getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
@@ -80,4 +87,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
2021-06-11 14:02:28 +02:00
public boolean isConversing() {
2021-06-11 21:23:46 +02:00
return this.conversationTracker.isConversing();
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
+ this.sendRawMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(message));
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
2022-06-07 20:12:34 +02:00
index 03027fe2b7ffe4c7ce7f1bb4f56051a4743c7f01..a6612cc0ea87aeb8e87521ff7b5fe58c7b06b9ef 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
2022-06-07 20:12:34 +02:00
@@ -29,6 +29,13 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
return "Rcon";
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return net.kyori.adventure.text.Component.text(this.getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
index 53d6950ad270ba901de5226b9daecb683248ad05..3e7d14564f11a3ed0b0766444e9d681804597e9a 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
@@ -67,6 +67,13 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
return this.getCallee().getName();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return this.getCallee().name();
+ }
+ // Paper end
+
@Override
public boolean isPermissionSet(String name) {
return this.getCaller().isPermissionSet(name);
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
index 8107ed0d248ff2a1cf8e556b7610a68f6c197691..eaff8df6c8c12c64e005a68a02e2e35ed88f757c 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
@@ -14,6 +14,7 @@ import org.bukkit.plugin.Plugin;
public abstract class ServerCommandSender implements CommandSender {
private static PermissibleBase blockPermInst;
private final PermissibleBase perm;
+ private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
public ServerCommandSender() {
if (this instanceof CraftBlockCommandSender) {
@@ -134,4 +135,18 @@ public abstract class ServerCommandSender implements CommandSender {
return this.spigot;
}
// Spigot end
+
+ // Paper start - implement pointers
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
2022-12-07 18:53:34 +01:00
index f6c614bb1184f9c79121f64a2a030bf3f094b671..e8334e2264510f5101e80b4f130e7ae1442560d7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
2022-06-07 20:12:34 +02:00
@@ -189,6 +189,12 @@ public class CraftEnchantment extends Enchantment {
2021-06-11 14:02:28 +02:00
CraftEnchantment ench = (CraftEnchantment) other;
2021-06-11 21:23:46 +02:00
return !this.target.isCompatibleWith(ench.target);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName(int level) {
2021-06-17 21:37:37 +02:00
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
2021-06-11 21:23:46 +02:00
return this.target;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 61304b316985462e898a1b80f872b716a33207c6..11645e01924b4a66aa4f425c8962a000be761912 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2023-03-14 19:05:23 +01:00
@@ -202,6 +202,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
protected Entity entity;
private EntityDamageEvent lastDamageEvent;
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftEntity.DATA_TYPE_REGISTRY);
+ protected net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
public CraftEntity(final CraftServer server, final Entity entity) {
this.server = server;
@@ -853,6 +854,32 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-06-11 21:23:46 +02:00
return this.getHandle().getVehicle().getBukkitEntity();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final Component name = this.getHandle().getCustomName();
+ return name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(name) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getHandle().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
+
@Override
public void setCustomName(String name) {
// sane limit for name length
@@ -932,6 +959,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public String getName() {
return CraftChatMessage.fromComponent(this.getHandle().getName());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getName());
+ }
+
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getDisplayName());
+ }
+ // Paper end
@Override
public boolean isPermissionSet(String name) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 3421498e8e5fe2e22d6b31d9cf6b3337553e1c5f..abe978078270a45f7e77eb2b8a99309f12ca51ee 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -320,9 +320,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2021-06-11 14:02:28 +02:00
container = CraftEventFactory.callInventoryOpenEvent(player, container);
if (container == null) return;
- String title = container.getBukkitView().getTitle();
+ //String title = container.getBukkitView().getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title(); // Paper
+ if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
2021-06-11 14:02:28 +02:00
- player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
2022-06-11 11:02:09 +02:00
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
2021-06-11 14:02:28 +02:00
+ player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
2021-06-11 21:23:46 +02:00
player.containerMenu = container;
player.initMenu(container);
2021-06-11 14:02:28 +02:00
}
@@ -391,8 +394,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2021-06-11 14:02:28 +02:00
// Now open the window
MenuType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
- String title = inventory.getTitle();
- player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
+
+ //String title = inventory.getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
+ if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
2022-06-11 11:02:09 +02:00
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
2021-06-11 14:02:28 +02:00
+ player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
player.containerMenu = container;
2021-06-11 21:23:46 +02:00
player.initMenu(container);
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
index 446fdca49a5a6999626a7ee3a1d5c168b15a09dd..f9863e138994f6c7a7975a852f106faa96d52315 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
@@ -65,6 +65,13 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca
return CraftChatMessage.fromComponent(this.getHandle().getCommandBlock().getName());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getCommandBlock().getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 02b62fa3b5a472728c5f2daaa15b2595c8f01864..a513bef2e9b9329f129cc2d5028815e2a0b1b14b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -286,14 +286,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
@Override
public String getDisplayName() {
+ if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
2021-06-11 21:23:46 +02:00
return this.getHandle().displayName;
2021-06-11 14:02:28 +02:00
}
@Override
public void setDisplayName(final String name) {
+ this.getHandle().adventure$displayName = name != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(name) : net.kyori.adventure.text.Component.text(this.getName()); // Paper
2021-06-11 21:23:46 +02:00
this.getHandle().displayName = name == null ? getName() : name;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public void playerListName(net.kyori.adventure.text.Component name) {
+ getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
+ for (ServerPlayer player : server.getHandle().players) {
+ if (player.getBukkitEntity().canSee(this)) {
+ player.connection.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, getHandle()));
2021-06-11 14:02:28 +02:00
+ }
+ }
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListName() {
+ return getHandle().listName == null ? net.kyori.adventure.text.Component.text(getName()) : io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().listName);
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListHeader() {
+ return playerListHeader;
+ }
+ @Override
+ public net.kyori.adventure.text.Component playerListFooter() {
+ return playerListFooter;
+ }
+ // Paper end
@Override
public String getPlayerListName() {
2021-06-11 21:23:46 +02:00
return this.getHandle().listName == null ? getName() : CraftChatMessage.fromComponent(this.getHandle().listName);
@@ -312,42 +337,42 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
}
- private Component playerListHeader;
- private Component playerListFooter;
+ private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
+ private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
@Override
public String getPlayerListHeader() {
2021-06-11 21:23:46 +02:00
- return (this.playerListHeader == null) ? null : CraftChatMessage.fromComponent(playerListHeader);
+ return (this.playerListHeader == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(playerListHeader);
2021-06-11 14:02:28 +02:00
}
@Override
public String getPlayerListFooter() {
2021-06-11 21:23:46 +02:00
- return (this.playerListFooter == null) ? null : CraftChatMessage.fromComponent(playerListFooter);
+ return (this.playerListFooter == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(playerListFooter); // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListHeader(String header) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
+ this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListFooter(String footer) {
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListHeaderFooter(String header, String footer) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
+ this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
2021-06-11 21:23:46 +02:00
private void updatePlayerListHeaderFooter() {
if (this.getHandle().connection == null) return;
2021-06-11 14:02:28 +02:00
2022-06-07 20:12:34 +02:00
- ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? Component.empty() : this.playerListHeader, (this.playerListFooter == null) ? Component.empty() : this.playerListFooter);
+ ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? Component.empty() : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListHeader), (this.playerListFooter == null) ? Component.empty() : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListFooter)); // Paper - adventure
2021-06-11 21:23:46 +02:00
this.getHandle().connection.send(packet);
2021-06-11 14:02:28 +02:00
}
@@ -379,6 +404,23 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
this.getHandle().connection.disconnect(message == null ? "" : message);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
2022-06-01 08:20:12 +02:00
+ private static final net.kyori.adventure.text.Component DEFAULT_KICK_COMPONENT = net.kyori.adventure.text.Component.translatable("multiplayer.disconnect.kicked");
+ @Override
+ public void kick() {
+ this.kick(DEFAULT_KICK_COMPONENT);
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ public void kick(final net.kyori.adventure.text.Component message) {
+ org.spigotmc.AsyncCatcher.catchOp("player kick");
+ final ServerGamePacketListenerImpl connection = this.getHandle().connection;
+ if (connection != null) {
+ connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
+ }
+ }
+ // Paper end
+
@Override
public void setCompassTarget(Location loc) {
Preconditions.checkArgument(loc != null, "Location cannot be null");
@@ -673,6 +715,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
this.getHandle().connection.send(packet);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public void sendSignChange(Location loc, @Nullable List<? extends net.kyori.adventure.text.Component> lines, DyeColor dyeColor, boolean hasGlowingText) {
2021-06-11 14:02:28 +02:00
+ if (getHandle().connection == null) {
+ return;
+ }
+ if (lines == null) {
+ lines = new java.util.ArrayList<>(4);
+ }
+ Preconditions.checkArgument(loc != null, "Location cannot be null");
+ Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
2021-06-11 14:02:28 +02:00
+ if (lines.size() < 4) {
+ throw new IllegalArgumentException("Must have at least 4 lines");
+ }
+ Component[] components = CraftSign.sanitizeLines(lines);
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
@Override
public void sendSignChange(Location loc, String[] lines) {
this.sendSignChange(loc, lines, DyeColor.BLACK);
@@ -696,6 +756,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (this.getHandle().connection == null) return;
2021-06-11 14:02:28 +02:00
Component[] components = CraftSign.sanitizeLines(lines);
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
+ // Paper start - adventure
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
+ }
+
+ private void sendSignChange0(Component[] components, Location loc, DyeColor dyeColor, boolean hasGlowingText) {
SignBlockEntity sign = new SignBlockEntity(CraftLocation.toBlockPosition(loc), Blocks.OAK_SIGN.defaultBlockState());
2023-06-07 19:18:05 +02:00
SignText text = sign.getFrontText();
text = text.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
@@ -705,7 +770,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
sign.setText(text, true);
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
- this.getHandle().connection.send(sign.getUpdatePacket());
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
+ getHandle().connection.send(sign.getUpdatePacket());
+ // Paper end
2021-06-11 14:02:28 +02:00
}
@Override
@@ -1606,7 +1672,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void setResourcePack(String url) {
- this.setResourcePack(url, null);
+ this.setResourcePack(url, (byte[]) null);
}
@Override
@@ -1621,7 +1687,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void setResourcePack(String url, byte[] hash, boolean force) {
- this.setResourcePack(url, hash, null, force);
+ this.setResourcePack(url, hash, (String) null, force);
}
@Override
@@ -1637,6 +1703,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
}
+ // Paper start
+ @Override
+ public void setResourcePack(String url, byte[] hashBytes, net.kyori.adventure.text.Component prompt, boolean force) {
+ Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
+ final String hash;
+ if (hashBytes != null) {
+ Preconditions.checkArgument(hashBytes.length == 20, "Resource pack hash should be 20 bytes long but was " + hashBytes.length);
+ hash = BaseEncoding.base16().lowerCase().encode(hashBytes);
+ } else {
+ hash = "";
+ }
+ this.getHandle().sendTexturePack(url, hash, force, io.papermc.paper.adventure.PaperAdventure.asVanilla(prompt));
+ }
+ // Paper end
+
public void addChannel(String channel) {
Preconditions.checkState(this.channels.size() < 128, "Cannot register channel '%s'. Too many channels registered!", channel);
channel = StandardMessenger.validateAndCorrectChannel(channel);
@@ -2028,6 +2109,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
return (this.getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : this.getHandle().clientViewDistance;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public java.util.Locale locale() {
+ return getHandle().adventure$locale;
+ }
+ // Paper end
@Override
public int getPing() {
2021-06-11 21:23:46 +02:00
return this.getHandle().latency;
@@ -2078,6 +2165,252 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-11-23 12:27:39 +01:00
return this.getHandle().allowsListing();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return this.getHandle().adventure$displayName;
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName());
+ this.getHandle().displayName = null;
+ }
+
+ @Override
2022-12-09 10:11:28 +01:00
+ public void deleteMessage(net.kyori.adventure.chat.SignedMessage.Signature signature) {
+ if (getHandle().connection == null) return;
+ net.minecraft.network.chat.MessageSignature sig = new net.minecraft.network.chat.MessageSignature(signature.bytes());
+
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundDeleteChatPacket(new net.minecraft.network.chat.MessageSignature.Packed(sig)));
+ }
+
+ private net.minecraft.network.chat.ChatType.Bound toHandle(net.kyori.adventure.chat.ChatType.Bound boundChatType) {
2023-06-08 00:12:41 +02:00
+ net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().registryOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
2022-12-09 10:11:28 +01:00
+
+ return new net.minecraft.network.chat.ChatType.Bound(
+ chatTypeRegistry.get(io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.type().key())),
+ io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.name()),
+ io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.target())
+ );
+ }
+
+ @Override
+ public void sendMessage(net.kyori.adventure.text.Component message, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
+ if (getHandle().connection == null) return;
+
+ net.minecraft.network.chat.Component component = io.papermc.paper.adventure.PaperAdventure.asVanilla(message);
+ this.getHandle().sendChatMessage(new net.minecraft.network.chat.OutgoingChatMessage.Disguised(component), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
+ }
+
+ @Override
+ public void sendMessage(net.kyori.adventure.chat.SignedMessage signedMessage, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
+ if (getHandle().connection == null) return;
+
+ if (signedMessage instanceof PlayerChatMessage.AdventureView view) {
+ this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(view.playerChatMessage()), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
+ return;
+ }
2022-12-09 10:11:28 +01:00
+ net.kyori.adventure.text.Component message = signedMessage.unsignedContent() == null ? net.kyori.adventure.text.Component.text(signedMessage.message()) : signedMessage.unsignedContent();
+ if (signedMessage.isSystem()) {
+ this.sendMessage(message, boundChatType);
+ } else {
+ super.sendMessage(signedMessage, boundChatType);
+ }
+// net.minecraft.network.chat.PlayerChatMessage playerChatMessage = new net.minecraft.network.chat.PlayerChatMessage(
+// null, // TODO:
+// new net.minecraft.network.chat.MessageSignature(signedMessage.signature().bytes()),
+// null, // TODO
+// io.papermc.paper.adventure.PaperAdventure.asVanilla(signedMessage.unsignedContent()),
+// net.minecraft.network.chat.FilterMask.PASS_THROUGH
+// );
+//
+// this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(playerChatMessage), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
+ }
+
+ @Deprecated(forRemoval = true)
+ @Override
2021-06-11 14:02:28 +02:00
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
+ if (getHandle().connection == null) return;
2023-06-08 00:12:41 +02:00
+ final net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().registryOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
2022-07-28 00:38:37 +02:00
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(message, false));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void sendActionBar(final net.kyori.adventure.text.Component message) {
+ final net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket((net.minecraft.network.chat.Component) null);
+ packet.adventure$text = message;
2021-06-11 14:02:28 +02:00
+ this.getHandle().connection.send(packet);
+ }
+
+ @Override
+ public void sendPlayerListHeader(final net.kyori.adventure.text.Component header) {
+ this.playerListHeader = header;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListFooter(final net.kyori.adventure.text.Component footer) {
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListHeaderAndFooter(final net.kyori.adventure.text.Component header, final net.kyori.adventure.text.Component footer) {
+ this.playerListHeader = header;
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ private void adventure$sendPlayerListHeaderAndFooter() {
+ final ServerGamePacketListenerImpl connection = this.getHandle().connection;
+ if (connection == null) return;
+ final ClientboundTabListPacket packet = new ClientboundTabListPacket(null, null);
+ packet.adventure$header = (this.playerListHeader == null) ? net.kyori.adventure.text.Component.empty() : this.playerListHeader;
+ packet.adventure$footer = (this.playerListFooter == null) ? net.kyori.adventure.text.Component.empty() : this.playerListFooter;
2021-06-11 14:02:28 +02:00
+ connection.send(packet);
+ }
+
+ @Override
+ public void showTitle(final net.kyori.adventure.title.Title title) {
+ final ServerGamePacketListenerImpl connection = this.getHandle().connection;
+ final net.kyori.adventure.title.Title.Times times = title.times();
+ if (times != null) {
2021-06-11 21:23:46 +02:00
+ connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
2021-06-11 14:02:28 +02:00
+ }
+ final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
+ sp.adventure$text = title.subtitle();
2021-06-11 14:02:28 +02:00
+ connection.send(sp);
+ final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
+ tp.adventure$text = title.title();
2021-06-11 14:02:28 +02:00
+ connection.send(tp);
+ }
+
+ @Override
+ public <T> void sendTitlePart(final net.kyori.adventure.title.TitlePart<T> part, T value) {
+ java.util.Objects.requireNonNull(part, "part");
+ java.util.Objects.requireNonNull(value, "value");
+ if (part == net.kyori.adventure.title.TitlePart.TITLE) {
+ final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
+ tp.adventure$text = (net.kyori.adventure.text.Component) value;
+ this.getHandle().connection.send(tp);
+ } else if (part == net.kyori.adventure.title.TitlePart.SUBTITLE) {
+ final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
+ sp.adventure$text = (net.kyori.adventure.text.Component) value;
+ this.getHandle().connection.send(sp);
+ } else if (part == net.kyori.adventure.title.TitlePart.TIMES) {
+ final net.kyori.adventure.title.Title.Times times = (net.kyori.adventure.title.Title.Times) value;
+ this.getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
+ } else {
+ throw new IllegalArgumentException("Unknown TitlePart");
+ }
+ }
+
2021-06-11 14:02:28 +02:00
+ private static int ticks(final java.time.Duration duration) {
+ if (duration == null) {
+ return -1;
+ }
+ return (int) (duration.toMillis() / 50L);
+ }
+
+ @Override
+ public void clearTitle() {
2021-06-11 21:23:46 +02:00
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundClearTitlesPacket(false));
2021-06-11 14:02:28 +02:00
+ }
+
+ // resetTitle implemented above
+
+ private @Nullable Set<net.kyori.adventure.bossbar.BossBar> activeBossBars;
+
+ @Override
+ public @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
+ if (this.activeBossBars != null) {
+ return java.util.Collections.unmodifiableSet(this.activeBossBars);
+ }
+ return Set.of();
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ public void showBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
+ net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerShow(this);
+ if (this.activeBossBars == null) {
+ this.activeBossBars = new HashSet<>();
+ }
+ this.activeBossBars.add(bar);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void hideBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
+ net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerHide(this);
+ if (this.activeBossBars != null) {
+ this.activeBossBars.remove(bar);
+ if (this.activeBossBars.isEmpty()) {
+ this.activeBossBars = null;
+ }
+ }
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound) {
+ final Vec3 pos = this.getHandle().position();
+ this.playSound(sound, pos.x, pos.y, pos.z);
+ }
+
+ @Override
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
+ this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
2021-06-17 00:57:49 +02:00
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
+ final Entity entity;
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
+ entity = this.getHandle();
+ } else if (emitter instanceof CraftEntity craftEntity) {
+ entity = craftEntity.getHandle();
2021-06-17 00:57:49 +02:00
+ } else {
+ throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
+ }
+ this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
2021-06-17 00:57:49 +02:00
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
+ this.getHandle().connection.send(new ClientboundStopSoundPacket(
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.sound()),
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.source())
+ ));
+ }
+
+ @Override
+ public void openBook(final net.kyori.adventure.inventory.Book book) {
+ final java.util.Locale locale = this.getHandle().adventure$locale;
+ final net.minecraft.world.item.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
+ final ServerPlayer player = this.getHandle();
+ final ServerGamePacketListenerImpl connection = player.connection;
2021-06-11 21:23:46 +02:00
+ final net.minecraft.world.entity.player.Inventory inventory = player.getInventory();
2021-06-11 14:02:28 +02:00
+ final int slot = inventory.items.size() + inventory.selected;
2021-07-07 08:52:40 +02:00
+ final int stateId = getHandle().containerMenu.getStateId();
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, item));
2021-06-11 14:02:28 +02:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundOpenBookPacket(net.minecraft.world.InteractionHand.MAIN_HAND));
2021-07-07 08:52:40 +02:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, inventory.getSelected()));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::displayName)
+ .withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .withDynamic(net.kyori.adventure.identity.Identity.LOCALE, this::locale)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftTextDisplay.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftTextDisplay.java
index 2becf197a5c2d94f23f72a9b20cb2cd05a0807df..99096c1e3f045e4a99335faedfb8e77e99690299 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftTextDisplay.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftTextDisplay.java
@@ -38,6 +38,17 @@ public class CraftTextDisplay extends CraftDisplay implements TextDisplay {
public void setText(String text) {
this.getHandle().setText(CraftChatMessage.fromString(text, true)[0]);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component text() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getText());
+ }
+
+ @Override
+ public void text(net.kyori.adventure.text.Component text) {
+ this.getHandle().setText(text == null ? net.minecraft.network.chat.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asVanilla(text));
+ }
+ // Paper end
@Override
public int getLineWidth() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index eb2b9aa73913ef6dde8e0909dbd4064f0147ead0..551fd24885cee87a3ca579f2f4bf0a18b9505e79 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -846,9 +846,9 @@ public class CraftEventFactory {
2021-06-11 14:02:28 +02:00
return event;
}
- public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
+ public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, String stringDeathMessage, boolean keepInventory) { // Paper - Adventure
CraftPlayer entity = victim.getBukkitEntity();
- PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage, stringDeathMessage); // Paper - Adventure
event.setKeepInventory(keepInventory);
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
2021-06-11 14:02:28 +02:00
org.bukkit.World world = entity.getWorld();
@@ -873,7 +873,7 @@ public class CraftEventFactory {
2021-06-11 14:02:28 +02:00
* Server methods
*/
2022-12-07 18:53:34 +01:00
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
- ServerListPingEvent event = new ServerListPingEvent("", address, motd, numPlayers, maxPlayers);
+ ServerListPingEvent event = new ServerListPingEvent("", address, craftServer.motd(), numPlayers, maxPlayers); // Paper - Adventure
2021-06-11 14:02:28 +02:00
craftServer.getPluginManager().callEvent(event);
return event;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
2023-06-07 19:18:05 +02:00
index 7cd70d53e5816938beab9019db40cd7faedba745..8ea031537c27b219c22316bff191670c48ebd602 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -72,6 +72,13 @@ public class CraftContainer extends AbstractContainerMenu {
2021-06-11 14:02:28 +02:00
return inventory.getType();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).title() : net.kyori.adventure.text.Component.text(inventory.getType().getDefaultTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
return title;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
index c9cc23757a9fcc58d30b2915d4c5cfbc7d1c767a..fc0e1212022d1aa3506699b60ef338196eb54eba 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
@@ -19,6 +19,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, type));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, type, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, String title) {
super(new MinecraftInventory(owner, type, title));
}
@@ -27,6 +33,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, size));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, size, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
super(new MinecraftInventory(owner, size, title));
}
@@ -36,9 +48,17 @@ public class CraftInventoryCustom extends CraftInventory {
private int maxStack = MAX_STACK;
private final List<HumanEntity> viewers;
private final String title;
+ private final net.kyori.adventure.text.Component adventure$title; // Paper
private InventoryType type;
private final InventoryHolder owner;
+ // Paper start
+ public MinecraftInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ this(owner, type.getDefaultSize(), title);
+ this.type = type;
+ }
+ // Paper end
+
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
this(owner, type.getDefaultSize(), type.getDefaultTitle());
this.type = type;
@@ -57,11 +77,24 @@ public class CraftInventoryCustom extends CraftInventory {
Preconditions.checkArgument(title != null, "title cannot be null");
2021-06-11 21:23:46 +02:00
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
2021-06-11 14:02:28 +02:00
this.title = title;
+ this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title);
2021-06-11 14:02:28 +02:00
this.viewers = new ArrayList<HumanEntity>();
this.owner = owner;
this.type = InventoryType.CHEST;
}
+ // Paper start
+ public MinecraftInventory(final InventoryHolder owner, final int size, final net.kyori.adventure.text.Component title) {
+ Preconditions.checkArgument(title != null, "Title cannot be null");
2021-06-12 00:37:16 +02:00
+ this.items = NonNullList.withSize(size, ItemStack.EMPTY);
+ this.title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
2021-06-11 14:02:28 +02:00
+ this.adventure$title = title;
+ this.viewers = new ArrayList<HumanEntity>();
+ this.owner = owner;
+ this.type = InventoryType.CHEST;
+ }
+ // Paper end
+
@Override
public int getContainerSize() {
2021-06-11 21:23:46 +02:00
return this.items.size();
2021-06-11 14:02:28 +02:00
@@ -183,6 +216,12 @@ public class CraftInventoryCustom extends CraftInventory {
return null;
}
+ // Paper start
+ public net.kyori.adventure.text.Component title() {
+ return this.adventure$title;
+ }
+ // Paper end
+
public String getTitle() {
2021-06-11 21:23:46 +02:00
return this.title;
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
index 4dd9a80af9901287ab6740b072f2b89678c3d0cb..b2586684295b295a3196a2a9cf724cec975b5a40 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
@@ -73,6 +73,13 @@ public class CraftInventoryView extends InventoryView {
2021-06-11 21:23:46 +02:00
return CraftItemStack.asCraftMirror(this.container.getSlot(slot).getItem());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9188) * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
2023-05-12 13:10:08 +02:00
return this.title;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
index fb58cfd68c8ababbf9486c9a5a1795b1ac9d5817..b187c4f436ac44a529675869dbf5bfddc4fac86f 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
@@ -437,4 +437,17 @@ public final class CraftItemFactory implements ItemFactory {
2021-06-11 14:02:28 +02:00
public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException {
return ((CraftMetaItem) meta).updateMaterial(material);
}
+
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
+ final net.minecraft.nbt.CompoundTag tag = CraftItemStack.asNMSCopy(item).getTag();
+ return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(net.kyori.adventure.text.event.HoverEvent.ShowItem.of(item.getType().getKey(), item.getAmount(), io.papermc.paper.adventure.PaperAdventure.asBinaryTagHolder(tag))));
+ }
+
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component displayName(@org.jetbrains.annotations.NotNull ItemStack itemStack) {
2021-06-16 19:48:25 +02:00
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
index 9e05a8515c5f6f340182e91150fcad8bbf80a22b..adf22ce4f0bcd3bd57dc2030c6c92d3df96566e3 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
@@ -13,10 +13,17 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
2021-06-11 14:02:28 +02:00
public class CraftMerchantCustom extends CraftMerchant {
+ @Deprecated // Paper - Adventure
public CraftMerchantCustom(String title) {
super(new MinecraftMerchant(title));
2021-06-11 21:23:46 +02:00
this.getMerchant().craftMerchant = this;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
+ super(new MinecraftMerchant(title));
+ getMerchant().craftMerchant = this;
+ }
+ // Paper end
@Override
public String toString() {
@@ -35,10 +42,17 @@ public class CraftMerchantCustom extends CraftMerchant {
private Player tradingPlayer;
2021-06-11 14:02:28 +02:00
protected CraftMerchant craftMerchant;
+ @Deprecated // Paper - Adventure
public MinecraftMerchant(String title) {
Preconditions.checkArgument(title != null, "Title cannot be null");
this.title = CraftChatMessage.fromString(title)[0];
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public MinecraftMerchant(net.kyori.adventure.text.Component title) {
+ Preconditions.checkArgument(title != null, "Title cannot be null");
2021-06-11 14:02:28 +02:00
+ this.title = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
+ }
+ // Paper end
@Override
public CraftMerchant getCraftMerchant() {
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
index bd4524fd987877a287680cfa5744ce12045ebfbd..cf928745c36af0e6fa0a95e177395c5fb1aa821a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.inventory;
2021-06-11 14:02:28 +02:00
import com.google.common.base.Preconditions;
2021-06-11 14:02:28 +02:00
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.Lists;
+
+import com.google.common.collect.ImmutableMap; // Paper
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -261,6 +262,145 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
2021-06-11 14:02:28 +02:00
this.generation = (generation == null) ? null : generation.ordinal();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return this.title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.title);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
+ this.setTitle(title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title));
2021-06-11 14:02:28 +02:00
+ return this;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component author() {
+ return this.author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.author);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
+ this.setAuthor(author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(author));
2021-06-11 14:02:28 +02:00
+ return this;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component page(final int page) {
+ Preconditions.checkArgument(isValidPage(page), "Invalid page number");
+ return this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(pages.get(page - 1)) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(pages.get(page - 1));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void page(final int page, net.kyori.adventure.text.Component data) {
+ if (!isValidPage(page)) {
+ throw new IllegalArgumentException("Invalid page number " + page + "/" + pages.size());
+ }
+ if (data == null) {
+ data = net.kyori.adventure.text.Component.empty();
+ }
+ pages.set(page - 1, this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(data) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(data));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public List<net.kyori.adventure.text.Component> pages() {
+ if (this.pages == null) return ImmutableList.of();
+ if (this instanceof CraftMetaBookSigned)
+ return pages.stream().map(net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson()::deserialize).collect(ImmutableList.toImmutableList());
+ else
+ return pages.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList());
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
+ if (this.pages != null) this.pages.clear();
+ for (net.kyori.adventure.text.Component page : pages) {
+ addPages(page);
+ }
+ return this;
+ }
+
+ @Override
+ public BookMeta pages(net.kyori.adventure.text.Component... pages) {
+ if (this.pages != null) this.pages.clear();
+ addPages(pages);
+ return this;
+ }
+
+ @Override
+ public void addPages(net.kyori.adventure.text.Component... pages) {
+ if (this.pages == null) this.pages = new ArrayList<>();
+ for (net.kyori.adventure.text.Component page : pages) {
+ if (this.pages.size() >= MAX_PAGES) {
+ return;
+ }
+
+ if (page == null) {
+ page = net.kyori.adventure.text.Component.empty();
+ }
+
+ this.pages.add(this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(page) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(page));
2021-06-11 14:02:28 +02:00
+ }
+ }
+
+ private CraftMetaBook(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages) {
+ super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK));
+ this.title = title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
+ this.author = author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(author);
+ this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).collect(java.util.stream.Collectors.toList());
2021-06-11 14:02:28 +02:00
+ }
+
+ static class CraftMetaBookBuilder implements BookMetaBuilder {
2021-06-11 14:02:28 +02:00
+ private net.kyori.adventure.text.Component title = null;
+ private net.kyori.adventure.text.Component author = null;
+ private final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
+
+ @Override
+ public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
+ this.title = title;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
+ this.author = author;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
+ this.pages.add(page);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
+ java.util.Collections.addAll(this.pages, pages);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
+ this.pages.addAll(pages);
+ return this;
+ }
+
+ @Override
+ public BookMeta build() {
+ return this.build(title, author, pages);
+ }
+
+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
2021-06-11 14:02:28 +02:00
+ return new CraftMetaBook(title, author, pages);
+ }
+ }
+
+ @Override
+ public BookMetaBuilder toBuilder() {
+ return new CraftMetaBookBuilder();
+ }
+
+ // Paper end
@Override
public String getPage(final int page) {
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s)", page);
@@ -402,7 +542,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
2021-06-11 14:02:28 +02:00
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
2021-06-11 21:23:46 +02:00
if (this.hasTitle()) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
index 507fa96a3fb904b74429df5756c9a6378ec8c5b7..abb9e88abc74135284b941e040d4058690a82b27 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.inventory;
-import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.ImmutableMap; // Paper
import java.util.Map;
import net.minecraft.nbt.CompoundTag;
import org.bukkit.Material;
@@ -78,8 +78,29 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
2021-06-11 14:02:28 +02:00
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
return builder;
}
+
+ // Paper start - adventure
+ private CraftMetaBookSigned(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
+ super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(Material.WRITABLE_BOOK));
+ this.title = title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
+ this.author = author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(author);
+ this.pages = io.papermc.paper.adventure.PaperAdventure.asJson(pages.subList(0, Math.min(MAX_PAGES, pages.size())));
+ }
+
+ static final class CraftMetaBookSignedBuilder extends CraftMetaBookBuilder {
+ @Override
+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
+ return new CraftMetaBookSigned(title, author, pages);
+ }
+ }
+
+ @Override
+ public BookMetaBuilder toBuilder() {
+ return new CraftMetaBookSignedBuilder();
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
index 03e5058810553be884c87f9f7b793cb5fadb7284..44244166ec4e8ac070404101219efbc0e5f1d168 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
@@ -749,6 +749,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
2021-06-11 21:23:46 +02:00
return !(this.hasDisplayName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isUnbreakable() || this.hasDamage() || this.hasAttributeModifiers());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(displayName);
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.displayName = displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(displayName);
+ }
+ // Paper end
+
@Override
public String getDisplayName() {
return CraftChatMessage.fromJSONComponent(displayName);
@@ -784,6 +796,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
2021-06-11 14:02:28 +02:00
return this.lore != null && !this.lore.isEmpty();
}
+ // Paper start
+ @Override
+ public List<net.kyori.adventure.text.Component> lore() {
+ return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventureFromJson(this.lore) : null;
+ }
+
+ @Override
+ public void lore(final List<? extends net.kyori.adventure.text.Component> lore) {
2021-06-11 14:02:28 +02:00
+ this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asJson(lore) : null;
+ }
+ // Paper end
+
@Override
public boolean hasRepairCost() {
2021-06-11 21:23:46 +02:00
return this.repairCost > 0;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
index ed4415f6dd588c08c922efd5beebb3b124beb9d6..78a7ac47f20e84ccd67ff44d0bc7a2f2faa0d476 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
@@ -12,6 +12,13 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(holder, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, type, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
return new CraftInventoryCustom(owner, type, title);
@@ -21,6 +28,12 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(owner, size);
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder owner, int size, String title) {
return new CraftInventoryCustom(owner, size, title);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
2023-03-14 19:05:23 +01:00
index e69d5635d1c81a3bed54d2cb1b0316efb522ab5d..d09fc01a20e8426f4094899060c70e011ff65887 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
2023-03-14 19:05:23 +01:00
@@ -44,6 +44,12 @@ public final class CraftInventoryCreator {
2021-06-11 21:23:46 +02:00
return this.converterMap.get(type).createInventory(holder, type);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
+ return converterMap.get(type).createInventory(holder, type, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
return this.converterMap.get(type).createInventory(holder, type, title);
2021-06-11 14:02:28 +02:00
}
2023-03-14 19:05:23 +01:00
@@ -52,6 +58,12 @@ public final class CraftInventoryCreator {
2021-06-11 21:23:46 +02:00
return this.DEFAULT_CONVERTER.createInventory(holder, size);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
+ return DEFAULT_CONVERTER.createInventory(holder, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, int size, String title) {
2021-06-11 21:23:46 +02:00
return this.DEFAULT_CONVERTER.createInventory(holder, size, title);
2021-06-11 14:02:28 +02:00
}
2023-03-14 19:05:23 +01:00
@@ -60,6 +72,10 @@ public final class CraftInventoryCreator {
2021-06-11 14:02:28 +02:00
Inventory createInventory(InventoryHolder holder, InventoryType type);
+ // Paper start
+ Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
+ // Paper end
+
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
2021-06-11 21:23:46 +02:00
index 1980240d3dc0331ddf2ff56e163e2bfbd3b231ab..7a7f3f53aef601f124d474d9890e23d87dd96900 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
@@ -31,6 +31,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
2021-06-11 21:23:46 +02:00
return this.getInventory(this.getTileEntity());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Container te = getTileEntity();
+ if (te instanceof RandomizableContainerBlockEntity) {
+ ((RandomizableContainerBlockEntity) te).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+
+ return getInventory(te);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
Container te = this.getTileEntity();
@@ -53,6 +65,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
2021-06-11 14:02:28 +02:00
return furnace;
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Container tileEntity = getTileEntity();
+ ((AbstractFurnaceBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
Container tileEntity = this.getTileEntity();
@@ -73,6 +94,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return new BrewingStandBlockEntity(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ // BrewingStand does not extend TileEntityLootable
+ Container tileEntity = getTileEntity();
+ if (tileEntity instanceof BrewingStandBlockEntity) {
+ ((BrewingStandBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
// BrewingStand does not extend TileEntityLootable
diff --git a/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java b/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java
index b47f18b1e448807a17ca9f2ae9609680233da837..9683d7d103af66fffd68c11abc38fb4fd2f99482 100644
--- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java
+++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java
@@ -42,7 +42,7 @@ public class CraftMapRenderer extends MapRenderer {
}
MapDecoration decoration = worldMap.decorations.get(key);
- cursors.addCursor(decoration.getX(), decoration.getY(), (byte) (decoration.getRot() & 15), decoration.getType().getIcon(), true, CraftChatMessage.fromComponent(decoration.getName()));
+ cursors.addCursor(decoration.getX(), decoration.getY(), (byte) (decoration.getRot() & 15), decoration.getType().getIcon(), true, decoration.getName() == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(decoration.getName())); // Paper
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
index b49cc2880fbecfd48d07c2e390c9e2aa2e09b848..de5f382656f9fd08f6ae1795c69743c604d62d5c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
@@ -31,6 +31,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
2021-06-11 21:23:46 +02:00
return this.objective.getName();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) {
+ displayName = net.kyori.adventure.text.Component.empty();
+ }
+ CraftScoreboard scoreboard = checkState();
+ objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ // Paper end
@Override
public String getDisplayName() throws IllegalStateException {
this.checkState();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
index f978617eaa74ff1fa0ab0acec3b6ccd14e2db55d..2471a6d0b7a8086cf4c0a41b10c05ed50d790d11 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
@@ -27,6 +27,33 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
2021-06-11 14:02:28 +02:00
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
2021-06-11 21:23:46 +02:00
return this.registerNewObjective(name, criteria, name);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName) {
+ return registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, RenderType.INTEGER);
2021-06-11 14:02:28 +02:00
+ }
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) {
+ return registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, renderType);
+ }
+ @Override
+ public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName) throws IllegalArgumentException {
+ return registerNewObjective(name, criteria, displayName, RenderType.INTEGER);
+ }
+ @Override
+ public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) throws IllegalArgumentException {
2021-06-11 14:02:28 +02:00
+ if (displayName == null) {
+ displayName = net.kyori.adventure.text.Component.empty();
+ }
+ Preconditions.checkArgument(name != null, "Objective name cannot be null");
+ Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
+ Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
+ Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
+ Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
+ net.minecraft.world.scores.Objective objective = board.addObjective(name, ((CraftCriteria) criteria).criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
2021-06-11 14:02:28 +02:00
+ return new CraftObjective(this, objective);
+ }
+ // Paper end
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
@@ -45,16 +72,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
2021-06-11 14:02:28 +02:00
@Override
public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) throws IllegalArgumentException {
- Preconditions.checkArgument(name != null, "Objective name cannot be null");
- Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
- Preconditions.checkArgument(displayName != null, "Display name cannot be null");
- Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
- Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
- Preconditions.checkArgument(displayName.length() <= 128, "The display name '%s' is longer than the limit of 128 characters (%s)", displayName, displayName.length());
- Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
-
- net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
2021-06-11 14:02:28 +02:00
- return new CraftObjective(this, objective);
+ return registerNewObjective(name, criteria, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(displayName), renderType); // Paper
2021-06-11 14:02:28 +02:00
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
index 4de9d57559e3787089a542fd912e5b28973fe73e..772206a43950db2726bd79911438e2aec2d7189c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
@@ -26,6 +26,63 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
return this.team.getName();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ @Override
+ public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerPrefix());
+ }
+ @Override
+ public void prefix(net.kyori.adventure.text.Component prefix) throws IllegalStateException, IllegalArgumentException {
+ if (prefix == null) prefix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setPlayerPrefix(io.papermc.paper.adventure.PaperAdventure.asVanilla(prefix));
+ }
+ @Override
+ public net.kyori.adventure.text.Component suffix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerSuffix());
+ }
+ @Override
+ public void suffix(net.kyori.adventure.text.Component suffix) throws IllegalStateException, IllegalArgumentException {
+ if (suffix == null) suffix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setPlayerSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
+ }
+ @Override
+ public boolean hasColor() {
+ CraftScoreboard scoreboard = checkState();
+ return this.team.getColor().getColor() != null;
+ }
+ @Override
2021-06-11 14:02:28 +02:00
+ public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
2021-06-16 19:48:25 +02:00
+ if (team.getColor().getColor() == null) throw new IllegalStateException("Team colors must have hex values");
+ net.kyori.adventure.text.format.TextColor color = net.kyori.adventure.text.format.TextColor.color(team.getColor().getColor());
2021-06-11 14:02:28 +02:00
+ if (!(color instanceof net.kyori.adventure.text.format.NamedTextColor)) throw new IllegalStateException("Team doesn't have a NamedTextColor");
+ return (net.kyori.adventure.text.format.NamedTextColor) color;
+ }
+ @Override
+ public void color(net.kyori.adventure.text.format.NamedTextColor color) {
+ CraftScoreboard scoreboard = checkState();
+ if (color == null) {
+ this.team.setColor(net.minecraft.ChatFormatting.RESET);
+ } else {
+ this.team.setColor(io.papermc.paper.adventure.PaperAdventure.asVanilla(color));
+ }
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
@Override
public String getDisplayName() throws IllegalStateException {
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
2022-06-07 20:12:34 +02:00
index 78ea79b66cc9e90402ef5cdc2e5e04e0c74b1c26..4fede2161792ba3e7cdf0cc5a1f533188becc6f7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
2022-06-07 20:12:34 +02:00
@@ -291,6 +291,7 @@ public final class CraftChatMessage {
2021-06-11 14:02:28 +02:00
public static String fromComponent(Component component) {
if (component == null) return "";
+ if (component instanceof io.papermc.paper.adventure.AdventureComponent) component = ((io.papermc.paper.adventure.AdventureComponent) component).deepConverted();
StringBuilder out = new StringBuilder();
boolean hadFormat = false;
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2023-06-13 09:10:07 +02:00
index 6deffd223ff995d83244e941576f8286e1171c1f..412dce72064533a260db591a94c8b39eb498331d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -74,6 +74,43 @@ public final class CraftMagicNumbers implements UnsafeValues {
2021-06-11 14:02:28 +02:00
private CraftMagicNumbers() {}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() {
+ return io.papermc.paper.adventure.PaperAdventure.FLATTENER;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() {
+ return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.colorDownsamplingGson();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
+ return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.PLAIN;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer plainTextSerializer() {
+ return net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection();
2021-06-11 14:02:28 +02:00
+ }
2022-11-23 05:53:50 +01:00
+
+ @Override
+ public net.kyori.adventure.text.Component resolveWithContext(final net.kyori.adventure.text.Component component, final org.bukkit.command.CommandSender context, final org.bukkit.entity.Entity scoreboardSubject, final boolean bypassPermissions) throws IOException {
+ return io.papermc.paper.adventure.PaperAdventure.resolveWithContext(component, context, scoreboardSubject, bypassPermissions);
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
+
public static BlockState getBlock(MaterialData material) {
2021-06-11 21:23:46 +02:00
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
2021-06-11 21:23:46 +02:00
index 62c66e3179b9557cdba46242df0fb15bce7e7710..73a37638abacdffbff8274291a64ea6cd0be7a5e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
@@ -80,7 +80,7 @@ public abstract class LazyHashSet<E> implements Set<E> {
2021-06-11 21:23:46 +02:00
return this.reference = this.makeReference();
2021-06-11 14:02:28 +02:00
}
- abstract Set<E> makeReference();
+ protected abstract Set<E> makeReference(); // Paper - protected
public boolean isLazy() {
2021-06-11 21:23:46 +02:00
return this.reference == null;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
index 75bc9ea10d80270217e4c75da98257a217b20097..673ab940fb53d42f6b6dbfe048d0281c4f508b0d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
@@ -16,9 +16,15 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
2021-06-11 14:02:28 +02:00
}
@Override
- HashSet<Player> makeReference() {
+ protected HashSet<Player> makeReference() { // Paper - protected
Preconditions.checkState(reference == null, "Reference already created!");
2021-06-11 21:23:46 +02:00
List<ServerPlayer> players = this.server.getPlayerList().players;
2021-06-11 14:02:28 +02:00
+ // Paper start
+ return makePlayerSet(this.server);
+ }
+ public static HashSet<Player> makePlayerSet(final MinecraftServer server) {
+ // Paper end
2021-06-11 21:23:46 +02:00
+ List<ServerPlayer> players = server.getPlayerList().players;
2021-06-11 14:02:28 +02:00
HashSet<Player> reference = new HashSet<Player>(players.size());
for (ServerPlayer player : players) {
2021-06-11 21:23:46 +02:00
reference.add(player.getBukkitEntity());
diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.bossbar.BossBarImplementation$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.bossbar.BossBarImplementation$Provider
new file mode 100644
index 0000000000000000000000000000000000000000..9b7119d0b88bf7f9d25fab37a15340cabc0c9b7b
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.bossbar.BossBarImplementation$Provider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.BossBarImplementationProvider
2023-03-15 13:19:54 +01:00
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
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.ComponentLoggerProviderImpl
diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.minimessage.MiniMessage$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.text.minimessage.MiniMessage$Provider
new file mode 100644
index 0000000000000000000000000000000000000000..6ce632b6c9dc5e4b3b978331df51c0ffd1526471
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.minimessage.MiniMessage$Provider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.MiniMessageProviderImpl
diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.gson.GsonComponentSerializer$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.gson.GsonComponentSerializer$Provider
new file mode 100644
index 0000000000000000000000000000000000000000..bc9f7398a0fe158af05b562a8ded9e74a22eae9b
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.gson.GsonComponentSerializer$Provider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.GsonComponentSerializerProviderImpl
diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer$Provider
new file mode 100644
index 0000000000000000000000000000000000000000..820f381981a91754b7f0c5106f93b773d885e321
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer$Provider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.LegacyComponentSerializerProviderImpl
diff --git a/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer$Provider b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer$Provider
new file mode 100644
index 0000000000000000000000000000000000000000..28d777610b52ba74f808bf3245d73b8333d01fa7
--- /dev/null
+++ b/src/main/resources/META-INF/services/net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer$Provider
@@ -0,0 +1 @@
+io.papermc.paper.adventure.providers.PlainTextComponentSerializerProviderImpl
diff --git a/src/test/java/io/papermc/paper/adventure/ComponentServicesTest.java b/src/test/java/io/papermc/paper/adventure/ComponentServicesTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..b6c4f8e2d375396a0ef3300a8bc324d77f23a768
--- /dev/null
+++ b/src/test/java/io/papermc/paper/adventure/ComponentServicesTest.java
@@ -0,0 +1,23 @@
+package io.papermc.paper.adventure;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ComponentServicesTest {
+
+ @Test
+ public void testPlainTextComponentSerializerProvider() {
+ assertEquals("Done", PlainTextComponentSerializer.plainText().serialize(Component.translatable("narrator.loading.done")));
+ }
+
+ @Test
+ public void testLegacyComponentSerializerProvider() {
+ assertEquals("§cDone", LegacyComponentSerializer.legacySection().serialize(Component.translatable("narrator.loading.done", NamedTextColor.RED)));
+ assertEquals("&cDone", LegacyComponentSerializer.legacyAmpersand().serialize(Component.translatable("narrator.loading.done", NamedTextColor.RED)));
+ }
+}