geforkt von Mirrors/Paper
4c6f66a6a3
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 CraftBukkit Changes: ead719a65 SPIGOT-7136: Cancelling PlayerInteractEntityEvent with the Allay desyncs 8468e167e SPIGOT-7137: StructureGrowEvent isFromBonemeal and getPlayer have incorrect values d45057c59 SPIGOT-7089: Crash when command blocks attempt to load worlds Spigot Changes: 450dcaa8 Rebuild patches
4552 Zeilen
232 KiB
Diff
4552 Zeilen
232 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Riley Park <rileysebastianpark@gmail.com>
|
|
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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
|
|
@@ -0,0 +0,0 @@
|
|
+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;
|
|
+import net.minecraft.network.chat.ComponentContents;
|
|
+import net.minecraft.network.chat.MutableComponent;
|
|
+import net.minecraft.network.chat.Style;
|
|
+import net.minecraft.network.chat.contents.LiteralContents;
|
|
+import net.minecraft.util.FormattedCharSequence;
|
|
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public final class AdventureComponent implements net.minecraft.network.chat.Component {
|
|
+ final Component adventure;
|
|
+ private net.minecraft.network.chat.@MonotonicNonNull Component vanilla;
|
|
+
|
|
+ public AdventureComponent(final Component adventure) {
|
|
+ this.adventure = adventure;
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ }
|
|
+ return vanilla;
|
|
+ }
|
|
+
|
|
+ public net.minecraft.network.chat.@Nullable Component deepConvertedIfPresent() {
|
|
+ return this.vanilla;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Style getStyle() {
|
|
+ return this.deepConverted().getStyle();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ComponentContents getContents() {
|
|
+ if (this.adventure instanceof TextComponent) {
|
|
+ return new LiteralContents(((TextComponent) this.adventure).content());
|
|
+ } else {
|
|
+ return this.deepConverted().getContents();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getString() {
|
|
+ return PlainTextComponentSerializer.plainText().serialize(this.adventure);
|
|
+ }
|
|
+
|
|
+ @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();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public FormattedCharSequence getVisualOrderText() {
|
|
+ return this.deepConverted().getVisualOrderText();
|
|
+ }
|
|
+
|
|
+ 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);
|
|
+ }
|
|
+ }
|
|
+}
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
|
@@ -0,0 +0,0 @@
|
|
+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;
|
|
+import net.minecraft.Util;
|
|
+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;
|
|
+ final boolean isPreview;
|
|
+
|
|
+ public ChatDecorationProcessor(final MinecraftServer server, final @Nullable ServerPlayer player, final @Nullable CommandSourceStack commandSourceStack, final net.minecraft.network.chat.Component originalMessage, final boolean isPreview) {
|
|
+ this.server = server;
|
|
+ this.player = player;
|
|
+ this.commandSourceStack = commandSourceStack;
|
|
+ this.originalMessage = PaperAdventure.asAdventure(originalMessage);
|
|
+ this.isPreview = isPreview;
|
|
+ }
|
|
+
|
|
+ public CompletableFuture<ChatDecorator.Result> process() {
|
|
+ return CompletableFuture.supplyAsync(() -> {
|
|
+ ChatDecorator.Result result = new ChatDecorator.ModernResult(this.originalMessage, true, false);
|
|
+ if (canYouHearMe(AsyncPlayerChatPreviewEvent.getHandlerList())) {
|
|
+ result = this.processLegacy(result);
|
|
+ }
|
|
+ return this.processModern(result);
|
|
+ }, this.server.chatExecutor);
|
|
+ }
|
|
+
|
|
+ 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) {
|
|
+ final @Nullable CraftPlayer player = Util.mapNullable(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, this.isPreview, initialResult);
|
|
+ } else {
|
|
+ event = new AsyncChatDecorateEvent(true, player, this.originalMessage, this.isPreview, 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);
|
|
+ }
|
|
+}
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import com.google.common.base.Suppliers;
|
|
+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.util.BitSet;
|
|
+import java.util.Collection;
|
|
+import java.util.HashSet;
|
|
+import java.util.Set;
|
|
+import java.util.concurrent.ExecutionException;
|
|
+import java.util.function.Function;
|
|
+import java.util.function.Supplier;
|
|
+import net.kyori.adventure.audience.Audience;
|
|
+import net.kyori.adventure.audience.MessageType;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.Util;
|
|
+import net.minecraft.network.chat.ChatDecorator;
|
|
+import net.minecraft.network.chat.ChatMessageContent;
|
|
+import net.minecraft.network.chat.ChatType;
|
|
+import net.minecraft.network.chat.OutgoingPlayerChatMessage;
|
|
+import net.minecraft.network.chat.PlayerChatMessage;
|
|
+import net.minecraft.resources.ResourceKey;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.command.ConsoleCommandSender;
|
|
+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;
|
|
+
|
|
+@DefaultQualifier(NonNull.class)
|
|
+public final class ChatProcessor {
|
|
+ static final String DEFAULT_LEGACY_FORMAT = "<%1$s> %2$s"; // copied from PlayerChatEvent/AsyncPlayerChatEvent
|
|
+ final MinecraftServer server;
|
|
+ final ServerPlayer player;
|
|
+ final PlayerChatMessage message;
|
|
+ final boolean async;
|
|
+ final String craftbukkit$originalMessage;
|
|
+ final Component paper$originalMessage;
|
|
+ final OutgoingPlayerChatMessage outgoing;
|
|
+
|
|
+ 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) {
|
|
+ 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()`.
|
|
+ */
|
|
+ this.message = message;
|
|
+ this.async = async;
|
|
+ if (this.message.signedContent().decorationResult().modernized()) {
|
|
+ this.craftbukkit$originalMessage = this.message.signedContent().decorationResult().message().legacyMessage();
|
|
+ } else {
|
|
+ this.craftbukkit$originalMessage = message.signedContent().plain();
|
|
+ }
|
|
+ /*
|
|
+ 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.
|
|
+ */
|
|
+ this.paper$originalMessage = this.message.signedContent().decorationResult().message().component();
|
|
+ this.outgoing = OutgoingPlayerChatMessage.create(this.message);
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings("deprecated")
|
|
+ public void process() {
|
|
+ final boolean listenersOnAsyncEvent = canYouHearMe(AsyncPlayerChatEvent.getHandlerList());
|
|
+ final boolean listenersOnSyncEvent = canYouHearMe(PlayerChatEvent.getHandlerList());
|
|
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
|
|
+ final CraftPlayer player = this.player.getBukkitEntity();
|
|
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.craftbukkit$originalMessage, new LazyPlayerSet(this.server));
|
|
+ this.post(ae);
|
|
+ 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() {
|
|
+ ChatProcessor.this.post(se);
|
|
+ return null;
|
|
+ }
|
|
+ });
|
|
+ this.readLegacyModifications(se.getMessage(), se.getFormat(), se.getPlayer());
|
|
+ this.processModern(
|
|
+ this.modernRenderer(se.getFormat()),
|
|
+ this.viewersFromLegacy(se.getRecipients()),
|
|
+ this.modernMessage(se.getMessage()),
|
|
+ se.getPlayer(),
|
|
+ se.isCancelled()
|
|
+ );
|
|
+ } else {
|
|
+ this.readLegacyModifications(ae.getMessage(), ae.getFormat(), ae.getPlayer());
|
|
+ this.processModern(
|
|
+ this.modernRenderer(ae.getFormat()),
|
|
+ this.viewersFromLegacy(ae.getRecipients()),
|
|
+ this.modernMessage(ae.getMessage()),
|
|
+ ae.getPlayer(),
|
|
+ ae.isCancelled()
|
|
+ );
|
|
+ }
|
|
+ } else {
|
|
+ this.processModern(
|
|
+ defaultRenderer(),
|
|
+ new LazyChatAudienceSet(this.server),
|
|
+ this.paper$originalMessage,
|
|
+ this.player.getBukkitEntity(),
|
|
+ false
|
|
+ );
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private ChatRenderer modernRenderer(final String format) {
|
|
+ if (this.flags.get(FORMAT_CHANGED)) {
|
|
+ return legacyRenderer(format);
|
|
+ } else if (this.message.signedContent().decorationResult() 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);
|
|
+ } else if (this.message.unsignedContent().isEmpty() && this.message.signedContent().decorationResult() 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) {
|
|
+ final ChatMessageContent content = this.message.signedContent();
|
|
+ if (content.decorationResult() instanceof ChatDecorator.LegacyResult result) {
|
|
+ if ((content.isDecorated() || this.message.unsignedContent().isPresent()) && !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 AsyncChatEvent ae = new AsyncChatEvent(this.async, player, viewers, renderer, message, this.paper$originalMessage);
|
|
+ ae.setCancelled(cancelled); // propagate cancelled state
|
|
+ this.post(ae);
|
|
+ final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList());
|
|
+ if (listenersOnSyncEvent) {
|
|
+ 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()*/);
|
|
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
|
+ ChatProcessor.this.post(se);
|
|
+ ChatProcessor.this.readModernModifications(se, renderer);
|
|
+ ChatProcessor.this.complete(se);
|
|
+ return null;
|
|
+ }
|
|
+ });
|
|
+ } else {
|
|
+ this.readModernModifications(ae, renderer);
|
|
+ this.complete(ae);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void readModernModifications(final AbstractChatEvent chatEvent, final ChatRenderer originalRenderer) {
|
|
+ if (this.message.signedContent().isDecorated()) {
|
|
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.message.signedContent().decorationResult().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?)
|
|
+ }
|
|
+
|
|
+ private void complete(final AbstractChatEvent event) {
|
|
+ if (event.isCancelled()) {
|
|
+ this.outgoing.sendHeadersToRemainingPlayers(this.server.getPlayerList());
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ final CraftPlayer player = ((CraftPlayer) event.getPlayer());
|
|
+ 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;
|
|
+ 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);
|
|
+ }
|
|
+ } 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);
|
|
+ } 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, player, 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, player, chatType, new ConstantFunction(renderedMessage));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType) {
|
|
+ this.broadcastToViewers(viewers, player, chatType, null);
|
|
+ }
|
|
+
|
|
+ private void broadcastToViewers(Collection<Audience> viewers, final Player source, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
|
+ final Supplier<Component> fallbackSupplier = Suppliers.memoize(() -> PaperAdventure.asAdventure(msgFunction instanceof ConstantFunction constantFunction ? constantFunction.component : ChatProcessor.this.message.serverContent()));
|
|
+ final Function<Audience, Component> audienceMsgFunction = !(msgFunction instanceof ConstantFunction || msgFunction == null) ? msgFunction.andThen(PaperAdventure::asAdventure) : viewer -> fallbackSupplier.get();
|
|
+ for (Audience viewer : viewers) {
|
|
+ if (viewer instanceof Player || viewer instanceof ConsoleCommandSender) {
|
|
+ // players and console have builtin PlayerChatMessage sending support while other audiences do not
|
|
+ this.sendToViewer((CommandSender) viewer, chatType, msgFunction);
|
|
+ } else {
|
|
+ viewer.sendMessage(source, audienceMsgFunction.apply(viewer), MessageType.CHAT);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Make sure to send remaining headers
|
|
+ ChatProcessor.this.outgoing.sendHeadersToRemainingPlayers(ChatProcessor.this.server.getPlayerList());
|
|
+ }
|
|
+
|
|
+ private void sendToViewer(final CommandSender 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) {
|
|
+ craftPlayer.getHandle().sendChatMessage(ChatProcessor.this.outgoing, ChatProcessor.this.player.shouldFilterMessageTo(craftPlayer.getHandle()), chatType, Util.mapNullable(msgFunction, f -> f.apply(viewer)));
|
|
+ } else {
|
|
+ throw new IllegalStateException("Should only be a Player or Console");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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));
|
|
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.serverContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage, ChatProcessor.this.player.asChatSender()) ? null : "Not Secure");
|
|
+ }
|
|
+
|
|
+ record ConstantFunction(net.minecraft.network.chat.Component component) implements Function<Audience, net.minecraft.network.chat.Component> {
|
|
+ @Override
|
|
+ public net.minecraft.network.chat.Component apply(Audience audience) {
|
|
+ return this.component;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ static String legacyDisplayName(final CraftPlayer player) {
|
|
+ return player.getDisplayName();
|
|
+ }
|
|
+
|
|
+ static Component displayName(final CraftPlayer player) {
|
|
+ return player.displayName();
|
|
+ }
|
|
+
|
|
+ private static ChatRenderer.Default defaultRenderer() {
|
|
+ return (ChatRenderer.Default) ChatRenderer.defaultRenderer();
|
|
+ }
|
|
+
|
|
+ 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);
|
|
+ }
|
|
+
|
|
+ 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());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private void post(final Event event) {
|
|
+ this.server.server.getPluginManager().callEvent(event);
|
|
+ }
|
|
+
|
|
+ static boolean canYouHearMe(final HandlerList handlers) {
|
|
+ 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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
+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());
|
|
+ }
|
|
+
|
|
+ public static String getLegacy(final ServerPlayer player) {
|
|
+ final String legacy = player.displayName;
|
|
+ if (legacy != null) {
|
|
+ // thank you for being worse than wet socks, Bukkit
|
|
+ return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName);
|
|
+ }
|
|
+ return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName);
|
|
+ }
|
|
+}
|
|
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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import java.util.HashSet;
|
|
+import java.util.Set;
|
|
+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;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected Set<Audience> makeReference() {
|
|
+ final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(this.server);
|
|
+ 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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -0,0 +0,0 @@
|
|
+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.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;
|
|
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
|
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
|
+import net.kyori.adventure.translation.GlobalTranslator;
|
|
+import net.kyori.adventure.translation.TranslationRegistry;
|
|
+import net.kyori.adventure.translation.Translator;
|
|
+import net.kyori.adventure.util.Codec;
|
|
+import net.minecraft.ChatFormatting;
|
|
+import net.minecraft.locale.Language;
|
|
+import net.minecraft.nbt.CompoundTag;
|
|
+import net.minecraft.nbt.ListTag;
|
|
+import net.minecraft.nbt.StringTag;
|
|
+import net.minecraft.nbt.TagParser;
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
+import net.minecraft.sounds.SoundSource;
|
|
+import net.minecraft.world.BossEvent;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import net.minecraft.world.item.WrittenBookItem;
|
|
+import org.bukkit.ChatColor;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public final class PaperAdventure {
|
|
+ public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale");
|
|
+ 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())) {
|
|
+ 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 @NotNull String translated = Language.getInstance().getOrDefault(translatable.key());
|
|
+
|
|
+ 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();
|
|
+ @Deprecated public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
|
|
+ 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 {
|
|
+ try {
|
|
+ return TagParser.parseTag(encoded);
|
|
+ } catch (final CommandSyntaxException e) {
|
|
+ throw new IOException(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NotNull String encode(final @NotNull CompoundTag decoded) {
|
|
+ return decoded.toString();
|
|
+ }
|
|
+ };
|
|
+ public static final ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer();
|
|
+
|
|
+ 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;
|
|
+ }
|
|
+ return asVanilla(key);
|
|
+ }
|
|
+
|
|
+ // 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);
|
|
+ }
|
|
+
|
|
+ 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<Component> adventures) {
|
|
+ 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;
|
|
+ if (true) return new AdventureComponent(component);
|
|
+ return net.minecraft.network.chat.Component.Serializer.fromJson(GsonComponentSerializer.gson().serializer().toJsonTree(component));
|
|
+ }
|
|
+
|
|
+ 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));
|
|
+ }
|
|
+
|
|
+ public static String asJsonString(final net.minecraft.network.chat.Component component, final Locale locale) {
|
|
+ if (component instanceof AdventureComponent) {
|
|
+ return asJsonString(((AdventureComponent) component).adventure, locale);
|
|
+ }
|
|
+ return net.minecraft.network.chat.Component.Serializer.toJson(component);
|
|
+ }
|
|
+
|
|
+ public static String asPlain(final Component component, final Locale locale) {
|
|
+ return PlainTextComponentSerializer.plainText().serialize(translated(component, locale));
|
|
+ }
|
|
+
|
|
+ private static Component translated(final Component component, final Locale locale) {
|
|
+ return GlobalTranslator.render(
|
|
+ component,
|
|
+ // play it safe
|
|
+ locale != null
|
|
+ ? locale
|
|
+ : Locale.US
|
|
+ );
|
|
+ }
|
|
+
|
|
+ // 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;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ 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));
|
|
+ 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);
|
|
+ }
|
|
+ for (final Component page : book.pages()) {
|
|
+ pages.add(StringTag.valueOf(validateField(asJsonString(page, locale), WrittenBookItem.PAGE_LENGTH, "page")));
|
|
+ }
|
|
+ tag.put(WrittenBookItem.TAG_PAGES, pages);
|
|
+ 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;
|
|
+ }
|
|
+
|
|
+ // Sounds
|
|
+
|
|
+ public static SoundSource asVanilla(final Sound.Source source) {
|
|
+ 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;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ public static @Nullable SoundSource asVanillaNullable(final Sound.@Nullable Source source) {
|
|
+ if (source == null) {
|
|
+ return null;
|
|
+ }
|
|
+ return asVanilla(source);
|
|
+ }
|
|
+
|
|
+ // 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) {
|
|
+ throw new IllegalArgumentException("Not a valid color");
|
|
+ }
|
|
+ return TextColor.color(color);
|
|
+ }
|
|
+
|
|
+ public static @Nullable ChatFormatting asVanilla(final TextColor color) {
|
|
+ return ChatFormatting.getByHexValue(color.value());
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
|
|
@@ -0,0 +0,0 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import java.util.Set;
|
|
+import java.util.function.Consumer;
|
|
+import java.util.function.Function;
|
|
+
|
|
+import net.kyori.adventure.bossbar.BossBar;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
|
|
+import net.minecraft.world.BossEvent;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+
|
|
+public final class VanillaBossBarListener implements BossBar.Listener {
|
|
+ private final Consumer<Function<BossEvent, ClientboundBossEventPacket>> action;
|
|
+
|
|
+ public VanillaBossBarListener(final Consumer<Function<BossEvent, ClientboundBossEventPacket>> action) {
|
|
+ this.action = action;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
|
|
+ this.action.accept(ClientboundBossEventPacket::createUpdateNamePacket);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
|
|
+ this.action.accept(ClientboundBossEventPacket::createUpdateProgressPacket);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
|
|
+ this.action.accept(ClientboundBossEventPacket::createUpdateStylePacket);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
|
|
+ this.action.accept(ClientboundBossEventPacket::createUpdateStylePacket);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
|
|
+ this.action.accept(ClientboundBossEventPacket::createUpdatePropertiesPacket);
|
|
+ }
|
|
+}
|
|
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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
|
|
@@ -0,0 +0,0 @@
|
|
+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;
|
|
+
|
|
+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;
|
|
+ }
|
|
+ return GsonComponentSerializer.gson().serializer().fromJson(net.minecraft.network.chat.Component.Serializer.toJsonTree(input), Component.class);
|
|
+ }
|
|
+
|
|
+ @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/ComponentLoggerProviderImpl.java b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/ComponentLoggerProviderImpl.java
|
|
@@ -0,0 +0,0 @@
|
|
+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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/GsonComponentSerializerProviderImpl.java
|
|
@@ -0,0 +0,0 @@
|
|
+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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/LegacyComponentSerializerProviderImpl.java
|
|
@@ -0,0 +0,0 @@
|
|
+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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/MiniMessageProviderImpl.java
|
|
@@ -0,0 +0,0 @@
|
|
+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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/NBTLegacyHoverEventSerializer.java
|
|
@@ -0,0 +0,0 @@
|
|
+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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/providers/PlainTextComponentSerializerProviderImpl.java
|
|
@@ -0,0 +0,0 @@
|
|
+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);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java b/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java
|
|
@@ -0,0 +0,0 @@
|
|
+package net.kyori.adventure.bossbar;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import io.papermc.paper.adventure.VanillaBossBarListener;
|
|
+import net.minecraft.server.level.ServerBossEvent;
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
+
|
|
+public abstract class HackyBossBarPlatformBridge {
|
|
+ public ServerBossEvent vanilla$bar;
|
|
+ private VanillaBossBarListener vanilla$listener;
|
|
+
|
|
+ public final void paper$playerShow(final CraftPlayer player) {
|
|
+ if (this.vanilla$bar == null) {
|
|
+ final BossBar $this = (BossBar) this;
|
|
+ this.vanilla$bar = new ServerBossEvent(
|
|
+ PaperAdventure.asVanilla($this.name()),
|
|
+ PaperAdventure.asVanilla($this.color()),
|
|
+ PaperAdventure.asVanilla($this.overlay())
|
|
+ );
|
|
+ this.vanilla$bar.adventure = $this;
|
|
+ this.vanilla$listener = new VanillaBossBarListener(this.vanilla$bar::broadcast);
|
|
+ $this.addListener(this.vanilla$listener);
|
|
+ }
|
|
+ this.vanilla$bar.addPlayer(player.getHandle());
|
|
+ }
|
|
+
|
|
+ public final void paper$playerHide(final CraftPlayer player) {
|
|
+ if (this.vanilla$bar != null) {
|
|
+ this.vanilla$bar.removePlayer(player.getHandle());
|
|
+ if (this.vanilla$bar.getPlayers().isEmpty()) {
|
|
+ ((BossBar) this).removeListener(this.vanilla$listener);
|
|
+ this.vanilla$bar = null;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/ChatFormatting.java b/src/main/java/net/minecraft/ChatFormatting.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/ChatFormatting.java
|
|
+++ b/src/main/java/net/minecraft/ChatFormatting.java
|
|
@@ -0,0 +0,0 @@ public enum ChatFormatting implements StringRepresentable {
|
|
return name == null ? null : FORMATTING_BY_NAME.get(cleanName(name));
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Nullable public static ChatFormatting getByHexValue(int i) {
|
|
+ for (ChatFormatting value : values()) {
|
|
+ if (value.getColor() != null && value.getColor() == i) {
|
|
+ return value;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Nullable
|
|
public static ChatFormatting getById(int colorIndex) {
|
|
if (colorIndex < 0) {
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
|
@@ -0,0 +0,0 @@ public class MessageArgument implements SignedArgument<MessageArgument.Message>
|
|
MinecraftServer minecraftServer = source.getServer();
|
|
source.getChatMessageChainer().append(() -> {
|
|
CompletableFuture<FilteredText> completableFuture = this.filterPlainText(source, this.signedArgument.signedContent().plain());
|
|
- CompletableFuture<PlayerChatMessage> completableFuture2 = minecraftServer.getChatDecorator().decorate(source.getPlayer(), this.signedArgument);
|
|
+ CompletableFuture<PlayerChatMessage> completableFuture2 = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source,this.signedArgument); // Paper
|
|
return CompletableFuture.allOf(completableFuture, completableFuture2).thenAcceptAsync((void_) -> {
|
|
PlayerChatMessage playerChatMessage = completableFuture2.join().filter(completableFuture.join().mask());
|
|
callback.accept(playerChatMessage);
|
|
@@ -0,0 +0,0 @@ public class MessageArgument implements SignedArgument<MessageArgument.Message>
|
|
|
|
CompletableFuture<Component> resolveDecoratedComponent(CommandSourceStack source) throws CommandSyntaxException {
|
|
Component component = this.resolveComponent(source);
|
|
- CompletableFuture<Component> completableFuture = source.getServer().getChatDecorator().decorate(source.getPlayer(), component);
|
|
+ CompletableFuture<Component> completableFuture = source.getServer().getChatDecorator().decorate(source.getPlayer(), source, component, true).thenApply(net.minecraft.network.chat.ChatDecorator.Result::component); // Paper
|
|
MessageArgument.logResolutionFailure(source, completableFuture);
|
|
return completableFuture;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
@@ -0,0 +0,0 @@ import io.netty.handler.codec.EncoderException;
|
|
import io.netty.util.ByteProcessor;
|
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
|
import it.unimi.dsi.fastutil.ints.IntList;
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import java.io.DataOutput;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
@@ -0,0 +0,0 @@ public class FriendlyByteBuf extends ByteBuf {
|
|
private static final int MAX_VARLONG_SIZE = 10;
|
|
private static final int DEFAULT_NBT_QUOTA = 2097152;
|
|
private final ByteBuf source;
|
|
+ public java.util.Locale adventure$locale; // Paper
|
|
public static final short MAX_STRING_LENGTH = 32767;
|
|
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
|
|
private static final int PUBLIC_KEY_SIZE = 256;
|
|
@@ -0,0 +0,0 @@ public class FriendlyByteBuf extends ByteBuf {
|
|
}
|
|
}
|
|
|
|
+ // 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
|
|
}
|
|
|
|
public <T extends Enum<T>> T readEnum(Class<T> enumClass) {
|
|
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
|
|
@@ -0,0 +0,0 @@ import com.mojang.logging.LogUtils;
|
|
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;
|
|
@@ -0,0 +0,0 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
|
} else {
|
|
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
|
|
friendlyByteBuf.writeVarInt(integer);
|
|
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
|
|
|
|
try {
|
|
int i = friendlyByteBuf.writerIndex();
|
|
diff --git a/src/main/java/net/minecraft/network/chat/ChatDecorator.java b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
|
+++ b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
|
@@ -0,0 +0,0 @@ public interface ChatDecorator {
|
|
return CompletableFuture.completedFuture(message);
|
|
};
|
|
|
|
+ @io.papermc.paper.annotation.DoNotUse // Paper
|
|
CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message);
|
|
|
|
+ @io.papermc.paper.annotation.DoNotUse // Paper
|
|
default CompletableFuture<PlayerChatMessage> decorate(@Nullable ServerPlayer sender, PlayerChatMessage message) {
|
|
- return message.signedContent().isDecorated() ? CompletableFuture.completedFuture(message) : this.decorate(sender, message.serverContent()).thenApply(message::withUnsignedContent);
|
|
+ return this.decorate(sender, null, message); // Paper
|
|
}
|
|
|
|
+ // Paper start
|
|
+ default CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message, boolean isPreview) {
|
|
+ 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) {
|
|
+ return this.decorate(sender, null, message, true).thenApply(Result::component);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message, boolean isPreview) {
|
|
+ return delegate.decorate(sender, commandSourceStack, message, isPreview);
|
|
+ }
|
|
+ };
|
|
+ }
|
|
+
|
|
+ @FunctionalInterface
|
|
+ interface ImprovedChatDecorator {
|
|
+ CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message, boolean isPreview);
|
|
+ }
|
|
+
|
|
+ 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;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ record ModernResult(Component maybeAdventureComponent, 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 Component component() {
|
|
+ return this.maybeAdventureComponent instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent ? adventureComponent.deepConverted() : this.maybeAdventureComponent;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public MessagePair message() {
|
|
+ final net.kyori.adventure.text.Component adventureComponent = io.papermc.paper.adventure.PaperAdventure.WRAPPER_AWARE_SERIALIZER.deserialize(this.maybeAdventureComponent);
|
|
+ return new MessagePair(adventureComponent, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(adventureComponent));
|
|
+ }
|
|
+ }
|
|
+ default CompletableFuture<PlayerChatMessage> decorate(@Nullable ServerPlayer serverPlayer, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, PlayerChatMessage playerChatMessage) {
|
|
+ return playerChatMessage.signedContent().isDecorated() ? CompletableFuture.completedFuture(playerChatMessage) : this.decorate(serverPlayer, commandSourceStack, playerChatMessage.serverContent(), false).thenApply(result -> {
|
|
+ return new PlayerChatMessage(playerChatMessage.signedHeader(), playerChatMessage.headerSignature(), playerChatMessage.signedBody().withContent(playerChatMessage.signedContent().withDecorationResult(result)), playerChatMessage.unsignedContent(), playerChatMessage.filterMask()).withUnsignedContent(result.component());
|
|
+ });
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
static PlayerChatMessage attachIfNotDecorated(PlayerChatMessage message, Component attached) {
|
|
return !message.signedContent().isDecorated() ? message.withUnsignedContent(attached) : message;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/chat/ChatMessageContent.java b/src/main/java/net/minecraft/network/chat/ChatMessageContent.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/chat/ChatMessageContent.java
|
|
+++ b/src/main/java/net/minecraft/network/chat/ChatMessageContent.java
|
|
@@ -0,0 +0,0 @@ package net.minecraft.network.chat;
|
|
import java.util.Objects;
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
|
|
-public record ChatMessageContent(String plain, Component decorated) {
|
|
+// Paper start
|
|
+public record ChatMessageContent(String plain, Component decorated, ChatDecorator.Result decorationResult) {
|
|
+
|
|
+ public ChatMessageContent(String plain, Component decorated) {
|
|
+ this(plain, decorated, new ChatDecorator.ModernResult(decorated, true, false));
|
|
+ }
|
|
+
|
|
+ public ChatMessageContent withDecorationResult(ChatDecorator.Result result) {
|
|
+ return new ChatMessageContent(this.plain, this.decorated, result);
|
|
+ }
|
|
+ // Paper end
|
|
public ChatMessageContent(String content) {
|
|
this(content, Component.literal(content));
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/chat/ChatPreviewCache.java b/src/main/java/net/minecraft/network/chat/ChatPreviewCache.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/chat/ChatPreviewCache.java
|
|
+++ b/src/main/java/net/minecraft/network/chat/ChatPreviewCache.java
|
|
@@ -0,0 +0,0 @@
|
|
package net.minecraft.network.chat;
|
|
|
|
import javax.annotation.Nullable;
|
|
+import net.minecraft.Util;
|
|
|
|
public class ChatPreviewCache {
|
|
@Nullable
|
|
private ChatPreviewCache.Result result;
|
|
|
|
public void set(String query, Component preview) {
|
|
- this.result = new ChatPreviewCache.Result(query, preview);
|
|
+ // Paper start
|
|
+ this.set(query, new ChatDecorator.ModernResult(java.util.Objects.requireNonNull(preview), true, false));
|
|
+ }
|
|
+ public void set(String query, ChatDecorator.Result decoratorResult) {
|
|
+ this.result = new ChatPreviewCache.Result(query, java.util.Objects.requireNonNull(decoratorResult));
|
|
+ // Paper end
|
|
}
|
|
|
|
@Nullable
|
|
public Component pull(String query) {
|
|
+ // Paper start
|
|
+ return net.minecraft.Util.mapNullable(this.pullFull(query), Result::preview);
|
|
+ }
|
|
+ public @Nullable Result pullFull(String query) {
|
|
+ // Paper end
|
|
ChatPreviewCache.Result result = this.result;
|
|
if (result != null && result.matches(query)) {
|
|
this.result = null;
|
|
- return result.preview();
|
|
+ return result; // Paper
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
- static record Result(String query, Component preview) {
|
|
+ // Paper start
|
|
+ public record Result(String query, ChatDecorator.Result decoratorResult) {
|
|
+
|
|
+ public Component preview() {
|
|
+ return this.decoratorResult.component();
|
|
+ }
|
|
+ // Paper end
|
|
public boolean matches(String query) {
|
|
return this.query.equals(query);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/network/chat/Component.java b/src/main/java/net/minecraft/network/chat/Component.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/chat/Component.java
|
|
+++ b/src/main/java/net/minecraft/network/chat/Component.java
|
|
@@ -0,0 +0,0 @@
|
|
package net.minecraft.network.chat;
|
|
|
|
import com.google.common.collect.Lists;
|
|
+import io.papermc.paper.adventure.AdventureComponent; // Paper
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import com.google.gson.JsonArray;
|
|
@@ -0,0 +0,0 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
|
|
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());
|
|
@@ -0,0 +0,0 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
|
|
}
|
|
|
|
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()) {
|
|
diff --git a/src/main/java/net/minecraft/network/chat/OutgoingPlayerChatMessage.java b/src/main/java/net/minecraft/network/chat/OutgoingPlayerChatMessage.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/chat/OutgoingPlayerChatMessage.java
|
|
+++ b/src/main/java/net/minecraft/network/chat/OutgoingPlayerChatMessage.java
|
|
@@ -0,0 +0,0 @@ public interface OutgoingPlayerChatMessage {
|
|
|
|
void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params);
|
|
|
|
+ // Paper start
|
|
+ default void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
|
+ this.sendToPlayer(sender, filterMaskEnabled, params);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
void sendHeadersToRemainingPlayers(PlayerList playerManager);
|
|
|
|
static OutgoingPlayerChatMessage create(PlayerChatMessage message) {
|
|
@@ -0,0 +0,0 @@ public interface OutgoingPlayerChatMessage {
|
|
|
|
@Override
|
|
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
|
|
+ // Paper start
|
|
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
|
+ // Paper end
|
|
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
|
|
+ playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
|
|
if (!playerChatMessage.isFullyFiltered()) {
|
|
RegistryAccess registryAccess = sender.level.registryAccess();
|
|
ChatType.BoundNetwork boundNetwork = params.toNetwork(registryAccess);
|
|
@@ -0,0 +0,0 @@ public interface OutgoingPlayerChatMessage {
|
|
|
|
@Override
|
|
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
|
|
+ // Paper start
|
|
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
|
+ // Paper end
|
|
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
|
|
+ playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
|
|
if (!playerChatMessage.isFullyFiltered()) {
|
|
this.playersWithFullMessage.add(sender);
|
|
RegistryAccess registryAccess = sender.level.registryAccess();
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ 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);
|
|
}
|
|
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
|
|
@@ -0,0 +0,0 @@ import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.protocol.Packet;
|
|
|
|
// Spigot start
|
|
-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
|
|
|
|
public ClientboundSystemChatPacket(Component content, boolean overlay) {
|
|
- this(Component.Serializer.toJson(content), overlay);
|
|
+ this(null, Component.Serializer.toJson(content), overlay); // Paper - Adventure
|
|
}
|
|
|
|
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
|
|
}
|
|
// Spigot end
|
|
+ // 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");
|
|
+ }
|
|
+
|
|
+ public ClientboundSystemChatPacket(net.kyori.adventure.text.Component content, boolean overlay) {
|
|
+ this(content, null, overlay);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public ClientboundSystemChatPacket(FriendlyByteBuf buf) {
|
|
this(buf.readComponent(), buf.readBoolean());
|
|
@@ -0,0 +0,0 @@ public record ClientboundSystemChatPacket(String content, boolean overlay) imple
|
|
|
|
@Override
|
|
public void write(FriendlyByteBuf buf) {
|
|
+ // Paper start
|
|
+ if (this.adventure$content != null) {
|
|
+ buf.writeComponent(this.adventure$content);
|
|
+ } else if (this.content != null) {
|
|
buf.writeUtf(this.content, 262144); // Spigot
|
|
+ } else {
|
|
+ throw new IllegalArgumentException("Must supply either adventure component or string json content");
|
|
+ }
|
|
+ // Paper end
|
|
buf.writeBoolean(this.overlay);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
|
|
@@ -0,0 +0,0 @@ import net.minecraft.network.protocol.Packet;
|
|
public class ClientboundTabListPacket implements Packet<ClientGamePacketListener> {
|
|
public final Component header;
|
|
public final Component footer;
|
|
+ // Paper start
|
|
+ public net.kyori.adventure.text.Component adventure$header;
|
|
+ public net.kyori.adventure.text.Component adventure$footer;
|
|
+ // Paper end
|
|
|
|
public ClientboundTabListPacket(Component header, Component footer) {
|
|
this.header = header;
|
|
@@ -0,0 +0,0 @@ public class ClientboundTabListPacket implements Packet<ClientGamePacketListener
|
|
|
|
@Override
|
|
public void write(FriendlyByteBuf buf) {
|
|
+ // 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);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
private boolean allowFlight;
|
|
@Nullable
|
|
private String motd;
|
|
+ @Nullable private net.kyori.adventure.text.Component cachedMotd; // Paper
|
|
private int playerIdleTimeout;
|
|
public final long[] tickTimes;
|
|
@Nullable
|
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
return this.motd;
|
|
}
|
|
|
|
+ public net.kyori.adventure.text.Component getComponentMotd() {
|
|
+ net.kyori.adventure.text.Component component = cachedMotd;
|
|
+ if (this.motd != null && this.cachedMotd == null) {
|
|
+ component = cachedMotd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.motd);
|
|
+ }
|
|
+
|
|
+ return component != null ? component : net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+
|
|
public void setMotd(String motd) {
|
|
this.motd = motd;
|
|
+ this.cachedMotd = null; // Paper
|
|
}
|
|
|
|
public boolean previewsChat() {
|
|
@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
|
|
// 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
|
|
+ return ChatDecorator.create((sender, commandSourceStack, message, isPreview) -> {
|
|
+ final io.papermc.paper.adventure.ChatDecorationProcessor processor = new io.papermc.paper.adventure.ChatDecorationProcessor(this, sender, commandSourceStack, message, isPreview);
|
|
+ return processor.process();
|
|
+ });
|
|
+ // Paper end
|
|
// CraftBukkit end
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -0,0 +0,0 @@ import net.minecraft.world.scores.Score;
|
|
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;
|
|
import org.bukkit.WeatherType;
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
|
|
// 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;
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
|
|
// CraftBukkit start
|
|
this.displayName = this.getScoreboardName();
|
|
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
|
|
this.bukkitPickUpLoot = true;
|
|
this.maxHealthCache = this.getMaxHealth();
|
|
}
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
|
|
String deathmessage = defaultMessage.getString();
|
|
this.keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
|
|
- 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
|
|
|
|
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
|
|
boolean flag1 = true;
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
public void sendChatMessage(OutgoingPlayerChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
|
|
+ // Paper start
|
|
+ this.sendChatMessage(message, filterMaskEnabled, params, null);
|
|
+ }
|
|
+ public void sendChatMessage(OutgoingPlayerChatMessage message, boolean filterMaskEnabled, ChatType.Bound params, @Nullable Component unsigned) {
|
|
+ // Paper end
|
|
if (this.acceptsChatMessages()) {
|
|
- message.sendToPlayer(this, filterMaskEnabled, params);
|
|
+ message.sendToPlayer(this, filterMaskEnabled, params, unsigned); // Paper
|
|
}
|
|
|
|
}
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
}
|
|
|
|
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
|
|
if (getMainArm() != packet.mainHand()) {
|
|
@@ -0,0 +0,0 @@ public class ServerPlayer extends Player {
|
|
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
|
|
this.chatVisibility = packet.chatVisibility();
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -0,0 +0,0 @@ import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.ChatProcessor; // Paper
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import java.util.Arrays;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
return this.server.isSingleplayerOwner(this.player.getGameProfile());
|
|
}
|
|
|
|
- // CraftBukkit start
|
|
- @Deprecated
|
|
- public void disconnect(Component reason) {
|
|
- this.disconnect(CraftChatMessage.fromComponent(reason));
|
|
+ public void disconnect(String s) {
|
|
+ // Paper start
|
|
+ this.disconnect(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(s));
|
|
}
|
|
- // CraftBukkit end
|
|
|
|
- public void disconnect(String s) {
|
|
+ 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;
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
Waitable waitable = new Waitable() {
|
|
@Override
|
|
protected Object evaluate() {
|
|
- ServerGamePacketListenerImpl.this.disconnect(s);
|
|
+ ServerGamePacketListenerImpl.this.disconnect(reason, cause); // Paper - adventure
|
|
return null;
|
|
}
|
|
};
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
return;
|
|
}
|
|
|
|
- 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
|
|
|
|
- PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), s, leaveMessage);
|
|
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), reason, leaveMessage); // Paper - Adventure
|
|
|
|
if (this.cserver.getServer().isRunning()) {
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
}
|
|
this.player.kickLeaveMessage = event.getLeaveMessage(); // CraftBukkit - SPIGOT-3034: Forward leave message to PlayerQuitEvent
|
|
// Send the possibly modified leave message
|
|
- final Component ichatbasecomponent = CraftChatMessage.fromString(event.getReason(), true)[0];
|
|
+ final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
|
|
// CraftBukkit end
|
|
|
|
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), PacketSendListener.thenRun(() -> {
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
*/
|
|
|
|
this.player.disconnect();
|
|
- String quitMessage = this.server.getPlayerList().remove(this.player);
|
|
- if ((quitMessage != null) && (quitMessage.length() > 0)) {
|
|
- this.server.getPlayerList().broadcastMessage(CraftChatMessage.fromString(quitMessage));
|
|
+ // Paper start - Adventure
|
|
+ net.kyori.adventure.text.Component quitMessage = this.server.getPlayerList().remove(this.player);
|
|
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
|
|
+ this.server.getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(quitMessage), false);
|
|
+ // Paper end
|
|
}
|
|
// CraftBukkit end
|
|
this.player.getTextFilter().leave();
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
if (this.verifyChatMessage(playerchatmessage)) {
|
|
this.chatMessageChain.append(() -> {
|
|
CompletableFuture<FilteredText> completablefuture = this.filterTextPacket(playerchatmessage.signedContent().plain());
|
|
- CompletableFuture<PlayerChatMessage> completablefuture1 = this.server.getChatDecorator().decorate(this.player, playerchatmessage);
|
|
+ CompletableFuture<PlayerChatMessage> completablefuture1 = this.server.getChatDecorator().decorate(this.player, null, playerchatmessage); // Paper
|
|
|
|
return CompletableFuture.allOf(completablefuture, completablefuture1).thenAcceptAsync((ovoid) -> {
|
|
FilterMask filtermask = ((FilteredText) completablefuture.join()).mask();
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
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);
|
|
+ cp.process();
|
|
+ // Paper end
|
|
+ } else if (false) { // Paper
|
|
Player player = this.getCraftPlayer();
|
|
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(this.server));
|
|
String originalFormat = event.getFormat(), originalMessage = event.getMessage();
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
}
|
|
|
|
private ChatMessageContent getSignedContent(ServerboundChatPacket packet) {
|
|
- Component ichatbasecomponent = this.chatPreviewCache.pull(packet.message());
|
|
+ // Paper start
|
|
+ final net.minecraft.network.chat.ChatPreviewCache.Result result = this.chatPreviewCache.pullFull(packet.message());
|
|
+ Component ichatbasecomponent = result != null ? result.preview() : null;
|
|
+ // Paper end
|
|
|
|
- return packet.signedPreview() && ichatbasecomponent != null ? new ChatMessageContent(packet.message(), ichatbasecomponent) : new ChatMessageContent(packet.message());
|
|
+ return packet.signedPreview() && ichatbasecomponent != null ? new ChatMessageContent(packet.message(), ichatbasecomponent, result.decoratorResult()) : new ChatMessageContent(packet.message()); // Paper end
|
|
}
|
|
|
|
private void broadcastChatMessage(PlayerChatMessage message) {
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
|
|
private CompletableFuture<Component> queryChatPreview(String query) {
|
|
MutableComponent ichatmutablecomponent = Component.literal(query);
|
|
- CompletableFuture<Component> completablefuture = this.server.getChatDecorator().decorate(this.player, (Component) ichatmutablecomponent).thenApply((ichatbasecomponent) -> {
|
|
- return !ichatmutablecomponent.equals(ichatbasecomponent) ? ichatbasecomponent : null;
|
|
+ // Paper start
|
|
+ final CompletableFuture<net.minecraft.network.chat.ChatDecorator.Result> result = this.server.getChatDecorator().decorate(this.player, null, ichatmutablecomponent, true);
|
|
+ CompletableFuture<net.minecraft.network.chat.ChatDecorator.Result> completablefuture = result.thenApply((res) -> {
|
|
+ return !ichatmutablecomponent.equals(res.component()) ? res : null;
|
|
+ // Paper end
|
|
});
|
|
|
|
completablefuture.thenAcceptAsync((ichatbasecomponent) -> {
|
|
- this.chatPreviewCache.set(query, ichatbasecomponent);
|
|
+ if (ichatbasecomponent != null) this.chatPreviewCache.set(query, ichatbasecomponent); // Paper
|
|
}, this.server);
|
|
- return completablefuture;
|
|
+ return completablefuture.thenApply(net.minecraft.network.chat.ChatDecorator.Result::component); // paper
|
|
}
|
|
|
|
private CompletableFuture<Component> queryCommandPreview(String query) {
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
CompletableFuture<Component> completablefuture = this.getPreviewedArgument(commandlistenerwrapper, PreviewableCommand.of(parseresults));
|
|
|
|
completablefuture.thenAcceptAsync((ichatbasecomponent) -> {
|
|
- this.chatPreviewCache.set(query, ichatbasecomponent);
|
|
+ if (ichatbasecomponent != null) this.chatPreviewCache.set(query, ichatbasecomponent); // Paper
|
|
}, this.server);
|
|
return completablefuture;
|
|
}
|
|
@@ -0,0 +0,0 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
return;
|
|
}
|
|
|
|
- // CraftBukkit start
|
|
+ // CraftBukkit start // Paper start - Adventure
|
|
Player player = this.player.getBukkitEntity();
|
|
int x = packet.getPos().getX();
|
|
int y = packet.getPos().getY();
|
|
int z = packet.getPos().getZ();
|
|
- String[] lines = new String[4];
|
|
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>();
|
|
|
|
for (int i = 0; i < signText.size(); ++i) {
|
|
FilteredText filteredtext = (FilteredText) signText.get(i);
|
|
|
|
if (this.player.isTextFilteringEnabled()) {
|
|
- lines[i] = ChatFormatting.stripFormatting(filteredtext.filteredOrEmpty());
|
|
+ lines.add(net.kyori.adventure.text.Component.text(filteredtext.filteredOrEmpty())); // Paper - adventure
|
|
} else {
|
|
- lines[i] = ChatFormatting.stripFormatting(filteredtext.raw());
|
|
+ lines.add(net.kyori.adventure.text.Component.text(filteredtext.raw())); // Paper - adventure
|
|
}
|
|
}
|
|
SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.player.getBukkitEntity(), lines);
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
- Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
|
|
- for (int i = 0; i < components.length; i++) {
|
|
- tileentitysign.setMessage(i, components[i]);
|
|
+ for (int i = 0; i < 4; i++) {
|
|
+ tileentitysign.setMessage(i, PaperAdventure.asVanilla(event.line(i)));
|
|
}
|
|
+ // Paper end
|
|
tileentitysign.isEditable = false;
|
|
}
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se
|
|
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
|
|
@@ -0,0 +0,0 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se
|
|
|
|
ServerLoginPacketListenerImpl.this.server.processQueue.add(waitable);
|
|
if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
|
|
- ServerLoginPacketListenerImpl.this.disconnect(event.getKickMessage());
|
|
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
|
return;
|
|
}
|
|
} else {
|
|
if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
|
- ServerLoginPacketListenerImpl.this.disconnect(asyncEvent.getKickMessage());
|
|
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
|
|
return;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
|
|
@@ -0,0 +0,0 @@ public class ServerStatusPacketListenerImpl implements ServerStatusPacketListene
|
|
CraftIconCache icon = server.server.getServerIcon();
|
|
|
|
ServerListPingEvent() {
|
|
- super(((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), ServerStatusPacketListenerImpl.this.server.getMotd(), ServerStatusPacketListenerImpl.this.server.previewsChat(), ServerStatusPacketListenerImpl.this.server.getPlayerList().getMaxPlayers());
|
|
+ super(((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), ServerStatusPacketListenerImpl.this.server.server.getMotd(), ServerStatusPacketListenerImpl.this.server.previewsChat(), ServerStatusPacketListenerImpl.this.server.getPlayerList().getMaxPlayers()); // Paper - Adventure
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -0,0 +0,0 @@ import com.mojang.logging.LogUtils;
|
|
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;
|
|
import java.nio.file.Path;
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
}
|
|
// CraftBukkit start
|
|
ichatmutablecomponent.withStyle(ChatFormatting.YELLOW);
|
|
- String joinMessage = CraftChatMessage.fromComponent(ichatmutablecomponent);
|
|
+ Component joinMessage = ichatmutablecomponent; // Paper - Adventure
|
|
|
|
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
|
this.players.add(player);
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
// Ensure that player inventory is populated with its viewer
|
|
player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
|
|
|
|
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, joinMessage);
|
|
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
this.cserver.getPluginManager().callEvent(playerJoinEvent);
|
|
|
|
if (!player.connection.connection.isConnected()) {
|
|
return;
|
|
}
|
|
|
|
- joinMessage = playerJoinEvent.getJoinMessage();
|
|
+ final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
|
|
|
- if (joinMessage != null && joinMessage.length() > 0) {
|
|
- for (Component line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
|
|
- this.server.getPlayerList().broadcastSystemMessage(line, false);
|
|
- }
|
|
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
|
|
+ joinMessage = PaperAdventure.asVanilla(jm); // Paper - Adventure
|
|
+ this.server.getPlayerList().broadcastSystemMessage(joinMessage, false); // Paper - Adventure
|
|
}
|
|
// CraftBukkit end
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
|
|
}
|
|
|
|
- public String remove(ServerPlayer entityplayer) { // CraftBukkit - return string
|
|
+ public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // Paper - return Component
|
|
ServerLevel worldserver = entityplayer.getLevel();
|
|
|
|
entityplayer.awardStat(Stats.LEAVE_GAME);
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
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() : net.kyori.adventure.text.Component.text(entityplayer.getScoreboardName())));
|
|
this.cserver.getPluginManager().callEvent(playerQuitEvent);
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
this.cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
|
|
// CraftBukkit end
|
|
|
|
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
|
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
|
|
}
|
|
|
|
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
// return chatmessage;
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
} else if (!this.isWhiteListed(gameprofile)) {
|
|
ichatmutablecomponent = Component.translatable("multiplayer.disconnect.not_whitelisted");
|
|
- 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
|
|
} else if (this.getIpBans().isBanned(socketaddress) && !this.getIpBans().get(socketaddress).hasExpired()) {
|
|
IpBanListEntry ipbanentry = this.ipBans.get(socketaddress);
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
// return chatmessage;
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
} else {
|
|
// return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
|
|
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
|
|
}
|
|
}
|
|
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
|
- loginlistener.disconnect(event.getKickMessage());
|
|
+ loginlistener.disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
|
return null;
|
|
}
|
|
return entity;
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
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
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
|
|
+ // Paper start
|
|
+ this.broadcastChatMessage(message, sender, params, null);
|
|
+ }
|
|
+ public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
|
+ // Paper end
|
|
Objects.requireNonNull(sender);
|
|
- this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, sender.asChatSender(), params);
|
|
+ this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, sender.asChatSender(), params, unsignedFunction); // Paper
|
|
}
|
|
|
|
private void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatSender sourceProfile, ChatType.Bound params) {
|
|
+ // Paper start
|
|
+ this.broadcastChatMessage(message, shouldSendFiltered, sender, sourceProfile, params, null);
|
|
+ }
|
|
+
|
|
+ private void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatSender sourceProfile, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
|
+ // Paper end
|
|
boolean flag = this.verifyChatTrusted(message, sourceProfile);
|
|
|
|
- this.server.logChatMessage(message.serverContent(), params, flag ? null : "Not Secure");
|
|
+ this.server.logChatMessage((unsignedFunction == null ? message : message.withUnsignedContent(unsignedFunction.apply(this.server.console))).serverContent(), params, flag ? null : "Not Secure"); // Paper
|
|
OutgoingPlayerChatMessage outgoingplayerchatmessage = OutgoingPlayerChatMessage.create(message);
|
|
boolean flag1 = message.isFullyFiltered();
|
|
boolean flag2 = false;
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
ServerPlayer entityplayer1 = (ServerPlayer) iterator.next();
|
|
boolean flag3 = shouldSendFiltered.test(entityplayer1);
|
|
|
|
- entityplayer1.sendChatMessage(outgoingplayerchatmessage, flag3, params);
|
|
+ entityplayer1.sendChatMessage(outgoingplayerchatmessage, flag3, params, unsignedFunction == null ? null : unsignedFunction.apply(entityplayer1.getBukkitEntity())); // Paper
|
|
if (sender != entityplayer1) {
|
|
flag2 |= flag1 && flag3;
|
|
}
|
|
@@ -0,0 +0,0 @@ public abstract class PlayerList {
|
|
|
|
}
|
|
|
|
- private boolean verifyChatTrusted(PlayerChatMessage message, ChatSender profile) {
|
|
+ public boolean verifyChatTrusted(PlayerChatMessage message, ChatSender profile) { // Paper - private -> public
|
|
return !message.hasExpiredServer(Instant.now()) && message.verify(profile);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/BossEvent.java b/src/main/java/net/minecraft/world/BossEvent.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/BossEvent.java
|
|
+++ b/src/main/java/net/minecraft/world/BossEvent.java
|
|
@@ -0,0 +0,0 @@ public abstract class BossEvent {
|
|
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;
|
|
@@ -0,0 +0,0 @@ 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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
|
@@ -0,0 +0,0 @@ import net.minecraft.world.level.saveddata.SavedData;
|
|
import org.slf4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import java.util.UUID;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
@@ -0,0 +0,0 @@ public class MapItemSavedData extends SavedData {
|
|
|
|
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
|
|
}
|
|
}
|
|
collection = icons;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
}
|
|
|
|
@Override
|
|
+ @Deprecated // Paper start
|
|
public int broadcastMessage(String message) {
|
|
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
|
|
+ // Paper end
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
return this.configuration.getInt("settings.spawn-radius", -1);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component shutdownMessage() {
|
|
+ String msg = getShutdownMessage();
|
|
+ return msg != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(msg) : null;
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
+ @Deprecated // Paper
|
|
public String getShutdownMessage() {
|
|
return this.configuration.getString("settings.shutdown-message");
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
}
|
|
|
|
@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);
|
|
+ }
|
|
+
|
|
+ @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<>();
|
|
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
|
|
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
}
|
|
}
|
|
|
|
- BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
|
|
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
|
|
this.getPluginManager().callEvent(broadcastMessageEvent);
|
|
|
|
if (broadcastMessageEvent.isCancelled()) {
|
|
return 0;
|
|
}
|
|
|
|
- message = broadcastMessageEvent.getMessage();
|
|
+ message = broadcastMessageEvent.message(); // Paper - Adventure
|
|
|
|
for (CommandSender recipient : recipients) {
|
|
recipient.sendMessage(message);
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
|
|
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
|
Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
|
|
+ Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
|
|
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
|
|
Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Merchant createMerchant(net.kyori.adventure.text.Component title) {
|
|
+ return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
+ @Deprecated // Paper
|
|
public Merchant createMerchant(String title) {
|
|
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
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)
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component motd() {
|
|
+ return console.getComponentMotd();
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getMotd() {
|
|
return this.console.getMotd();
|
|
@@ -0,0 +0,0 @@ public final class CraftServer implements Server {
|
|
return this.spigot;
|
|
}
|
|
// Spigot end
|
|
+
|
|
+ // 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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -0,0 +0,0 @@ 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();
|
|
|
|
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
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.NAME, this::getName)
|
|
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUID)
|
|
+ .build();
|
|
+ }
|
|
+
|
|
+ return this.adventure$pointers;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
|
|
@@ -0,0 +0,0 @@ public class Main {
|
|
public static boolean useConsole = true;
|
|
|
|
public static void main(String[] args) {
|
|
+ // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
|
|
@@ -0,0 +0,0 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
|
|
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();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
|
|
@@ -0,0 +0,0 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
|
|
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) {
|
|
+ getSnapshot().getCommandBlock().setName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
@@ -0,0 +0,0 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
|
|
@@ -0,0 +0,0 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantmentTable
|
|
super(world, tileEntity);
|
|
}
|
|
|
|
+ // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
@@ -0,0 +0,0 @@ import org.bukkit.entity.Player;
|
|
public class CraftSign extends CraftBlockEntityState<SignBlockEntity> implements Sign {
|
|
|
|
// 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
|
|
|
|
public CraftSign(World world, SignBlockEntity tileEntity) {
|
|
super(world, tileEntity);
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
- public String[] getLines() {
|
|
- if (this.lines == null) {
|
|
- // Lazy initialization:
|
|
- SignBlockEntity sign = this.getSnapshot();
|
|
- this.lines = new String[sign.messages.length];
|
|
- System.arraycopy(CraftSign.revertComponents(sign.messages), 0, lines, 0, lines.length);
|
|
- this.originalLines = new String[lines.length];
|
|
- System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
|
|
- }
|
|
+ public java.util.List<net.kyori.adventure.text.Component> lines() {
|
|
+ this.loadLines();
|
|
return this.lines;
|
|
}
|
|
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component line(int index) {
|
|
+ this.loadLines();
|
|
+ return this.lines.get(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void line(int index, net.kyori.adventure.text.Component line) {
|
|
+ this.loadLines();
|
|
+ this.lines.set(index, line);
|
|
+ }
|
|
+
|
|
+ private void loadLines() {
|
|
+ if (lines != null) {
|
|
+ return;
|
|
+ }
|
|
+ // Lazy initialization:
|
|
+ SignBlockEntity sign = this.getSnapshot();
|
|
+ lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(sign.messages));
|
|
+ originalLines = new java.util.ArrayList<>(lines);
|
|
+ }
|
|
+ // Paper end
|
|
+ @Override
|
|
+ public String[] getLines() {
|
|
+ this.loadLines();
|
|
+ return this.lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
|
|
+ }
|
|
+
|
|
@Override
|
|
public String getLine(int index) throws IndexOutOfBoundsException {
|
|
- return this.getLines()[index];
|
|
+ this.loadLines();
|
|
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.lines.get(index)); // Paper
|
|
}
|
|
|
|
@Override
|
|
public void setLine(int index, String line) throws IndexOutOfBoundsException {
|
|
- this.getLines()[index] = line;
|
|
+ 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
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ public class CraftSign extends CraftBlockEntityState<SignBlockEntity> implements
|
|
super.applyTo(sign);
|
|
|
|
if (this.lines != null) {
|
|
- for (int i = 0; i < lines.length; i++) {
|
|
- String line = (this.lines[i] == null) ? "" : this.lines[i];
|
|
- if (line.equals(this.originalLines[i])) {
|
|
+ // 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.
|
|
}
|
|
- sign.setMessage(i, CraftChatMessage.fromString(line)[0]);
|
|
+ sign.setMessage(i, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
|
|
}
|
|
+ // Paper end
|
|
}
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public class CraftSign extends CraftBlockEntityState<SignBlockEntity> implements
|
|
((CraftPlayer) player).getHandle().openTextEdit(handle);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public static Component[] sanitizeLines(java.util.List<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/command/CraftBlockCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
|
public boolean isConversing() {
|
|
return this.conversationTracker.isConversing();
|
|
}
|
|
+
|
|
+ // 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));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
|
|
@@ -0,0 +0,0 @@ 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) {
|
|
@@ -0,0 +0,0 @@ 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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
@@ -0,0 +0,0 @@ public class CraftEnchantment extends Enchantment {
|
|
CraftEnchantment ench = (CraftEnchantment) other;
|
|
return !this.target.isCompatibleWith(ench.target);
|
|
}
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component displayName(int level) {
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
|
|
return this.target;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
return this.getHandle().getVehicle().getBukkitEntity();
|
|
}
|
|
|
|
+ // 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;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void setCustomName(String name) {
|
|
// sane limit for name length
|
|
@@ -0,0 +0,0 @@ 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) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -0,0 +0,0 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
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
|
|
|
|
- player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
|
|
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
|
|
+ player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
|
player.containerMenu = container;
|
|
player.initMenu(container);
|
|
}
|
|
@@ -0,0 +0,0 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
|
|
// 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
|
|
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
|
|
+ player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
|
player.containerMenu = container;
|
|
player.initMenu(container);
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
|
|
@@ -0,0 +0,0 @@ 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;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
@Override
|
|
public String getDisplayName() {
|
|
+ if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
|
|
return this.getHandle().displayName;
|
|
}
|
|
|
|
@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
|
|
this.getHandle().displayName = name == null ? getName() : name;
|
|
}
|
|
|
|
+ // 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 ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, getHandle()));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ @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() {
|
|
return this.getHandle().listName == null ? getName() : CraftChatMessage.fromComponent(this.getHandle().listName);
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
}
|
|
|
|
- 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() {
|
|
- return (this.playerListHeader == null) ? null : CraftChatMessage.fromComponent(playerListHeader);
|
|
+ return (this.playerListHeader == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(playerListHeader);
|
|
}
|
|
|
|
@Override
|
|
public String getPlayerListFooter() {
|
|
- 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
|
|
}
|
|
|
|
@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
|
|
this.updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
@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
|
|
this.updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
@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
|
|
this.updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
private void updatePlayerListHeaderFooter() {
|
|
if (this.getHandle().connection == null) return;
|
|
|
|
- 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
|
|
this.getHandle().connection.send(packet);
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
this.getHandle().connection.disconnect(message == null ? "" : message);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ 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);
|
|
+ }
|
|
+
|
|
+ @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) {
|
|
if (this.getHandle().connection == null) return;
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
this.getHandle().connection.send(packet);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public void sendSignChange(Location loc, @Nullable List<net.kyori.adventure.text.Component> lines, DyeColor dyeColor, boolean hasGlowingText) {
|
|
+ if (getHandle().connection == null) {
|
|
+ return;
|
|
+ }
|
|
+ if (lines == null) {
|
|
+ lines = new java.util.ArrayList<>(4);
|
|
+ }
|
|
+ Validate.notNull(loc, "Location cannot be null");
|
|
+ Validate.notNull(dyeColor, "DyeColor cannot be null");
|
|
+ if (lines.size() < 4) {
|
|
+ throw new IllegalArgumentException("Must have at least 4 lines");
|
|
+ }
|
|
+ Component[] components = CraftSign.sanitizeLines(lines);
|
|
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
|
|
+ }
|
|
+
|
|
+ private void sendSignChange0(Component[] components, Location loc, DyeColor dyeColor, boolean hasGlowingText) {
|
|
+ SignBlockEntity sign = new SignBlockEntity(new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Blocks.OAK_SIGN.defaultBlockState());
|
|
+ sign.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
|
|
+ sign.setHasGlowingText(hasGlowingText);
|
|
+ for (int i = 0; i < components.length; i++) {
|
|
+ sign.setMessage(i, components[i]);
|
|
+ }
|
|
+
|
|
+ getHandle().connection.send(sign.getUpdatePacket());
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public void sendSignChange(Location loc, String[] lines) {
|
|
this.sendSignChange(loc, lines, DyeColor.BLACK);
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
Component[] components = CraftSign.sanitizeLines(lines);
|
|
- SignBlockEntity sign = new SignBlockEntity(new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Blocks.OAK_SIGN.defaultBlockState());
|
|
+ /*SignBlockEntity sign = new SignBlockEntity(new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Blocks.OAK_SIGN.defaultBlockState());
|
|
sign.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
|
|
sign.setHasGlowingText(hasGlowingText);
|
|
for (int i = 0; i < components.length; i++) {
|
|
sign.setMessage(i, components[i]);
|
|
}
|
|
|
|
- this.getHandle().connection.send(sign.getUpdatePacket());
|
|
+ this.getHandle().connection.send(sign.getUpdatePacket());*/ // Paper
|
|
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
@Override
|
|
public void setResourcePack(String url) {
|
|
- this.setResourcePack(url, null);
|
|
+ this.setResourcePack(url, (byte[]) null);
|
|
}
|
|
|
|
@Override
|
|
@@ -0,0 +0,0 @@ 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
|
|
@@ -0,0 +0,0 @@ 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) {
|
|
+ Validate.notNull(url, "Resource pack URL cannot be null");
|
|
+ final String hash;
|
|
+ if (hashBytes != null) {
|
|
+ Validate.isTrue(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);
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return (this.getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : this.getHandle().clientViewDistance;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public java.util.Locale locale() {
|
|
+ return getHandle().adventure$locale;
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public int getPing() {
|
|
return this.getHandle().latency;
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return this.getHandle().allowsListing();
|
|
}
|
|
|
|
+ // 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
|
|
+ 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;
|
|
+ final net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level.registryAccess().registryOrThrow(net.minecraft.core.Registry.CHAT_TYPE_REGISTRY);
|
|
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(message, false));
|
|
+ }
|
|
+
|
|
+ @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;
|
|
+ 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;
|
|
+ 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) {
|
|
+ connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
|
|
+ }
|
|
+ final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
|
|
+ sp.adventure$text = title.subtitle();
|
|
+ connection.send(sp);
|
|
+ final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
|
|
+ tp.adventure$text = title.title();
|
|
+ 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");
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static int ticks(final java.time.Duration duration) {
|
|
+ if (duration == null) {
|
|
+ return -1;
|
|
+ }
|
|
+ return (int) (duration.toMillis() / 50L);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clearTitle() {
|
|
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundClearTitlesPacket(false));
|
|
+ }
|
|
+
|
|
+ // resetTitle implemented above
|
|
+
|
|
+ @Override
|
|
+ public void showBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
|
|
+ ((net.kyori.adventure.bossbar.HackyBossBarPlatformBridge) bar).paper$playerShow(this);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void hideBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
|
|
+ ((net.kyori.adventure.bossbar.HackyBossBarPlatformBridge) bar).paper$playerHide(this);
|
|
+ }
|
|
+
|
|
+ @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) {
|
|
+ final ResourceLocation name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
|
|
+ final java.util.Optional<net.minecraft.sounds.SoundEvent> event = net.minecraft.core.Registry.SOUND_EVENT.getOptional(name);
|
|
+ if (event.isPresent()) {
|
|
+ this.getHandle().connection.send(new ClientboundSoundPacket(event.get(), io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), x, y, z, sound.volume(), sound.pitch(), this.getHandle().getRandom().nextLong())); // TODO adventure sound seed
|
|
+ } else {
|
|
+ this.getHandle().connection.send(new ClientboundCustomSoundPacket(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), new Vec3(x, y, z), sound.volume(), sound.pitch(), this.getHandle().getRandom().nextLong())); // TODO adventure sound seed
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ 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 org.bukkit.entity.Entity) {
|
|
+ entity = ((CraftEntity) emitter).getHandle();
|
|
+ } else {
|
|
+ throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
|
|
+ }
|
|
+
|
|
+ final ResourceLocation name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
|
|
+ final java.util.Optional<net.minecraft.sounds.SoundEvent> event = net.minecraft.core.Registry.SOUND_EVENT.getOptional(name);
|
|
+ if (event.isPresent()) {
|
|
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(event.get(), io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), entity, sound.volume(), sound.pitch(), this.getHandle().getRandom().nextLong())); // TODO adventure sound seed
|
|
+ } else {
|
|
+ this.getHandle().connection.send(new ClientboundCustomSoundPacket(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), entity.position(), sound.volume(), sound.pitch(), this.getHandle().getRandom().nextLong())); // TODO adventure sound seed
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ 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;
|
|
+ final net.minecraft.world.entity.player.Inventory inventory = player.getInventory();
|
|
+ final int slot = inventory.items.size() + inventory.selected;
|
|
+ final int stateId = getHandle().containerMenu.getStateId();
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, item));
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundOpenBookPacket(net.minecraft.world.InteractionHand.MAIN_HAND));
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, inventory.getSelected()));
|
|
+ }
|
|
+
|
|
+ @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;
|
|
+ }
|
|
+ // Paper end
|
|
// Spigot start
|
|
private final Player.Spigot spigot = new Player.Spigot()
|
|
{
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
|
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
|
|
org.bukkit.World world = entity.getWorld();
|
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
|
* Server methods
|
|
*/
|
|
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, boolean shouldSendChatPreviews, int numPlayers, int maxPlayers) {
|
|
- ServerListPingEvent event = new ServerListPingEvent(address, motd, shouldSendChatPreviews, numPlayers, maxPlayers);
|
|
+ ServerListPingEvent event = new ServerListPingEvent(address, craftServer.motd(), shouldSendChatPreviews, numPlayers, maxPlayers); // Paper - Adventure
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
|
|
@@ -0,0 +0,0 @@ public class CraftContainer extends AbstractContainerMenu {
|
|
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() {
|
|
return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).getTitle() : inventory.getType().getDefaultTitle();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
@@ -0,0 +0,0 @@ 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));
|
|
}
|
|
@@ -0,0 +0,0 @@ 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));
|
|
}
|
|
@@ -0,0 +0,0 @@ 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;
|
|
@@ -0,0 +0,0 @@ public class CraftInventoryCustom extends CraftInventory {
|
|
Validate.notNull(title, "Title cannot be null");
|
|
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
|
|
this.title = title;
|
|
+ this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title);
|
|
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) {
|
|
+ Validate.notNull(title, "Title cannot be null");
|
|
+ this.items = NonNullList.withSize(size, ItemStack.EMPTY);
|
|
+ this.title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
|
|
+ this.adventure$title = title;
|
|
+ this.viewers = new ArrayList<HumanEntity>();
|
|
+ this.owner = owner;
|
|
+ this.type = InventoryType.CHEST;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public int getContainerSize() {
|
|
return this.items.size();
|
|
@@ -0,0 +0,0 @@ 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() {
|
|
return this.title;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
|
|
@@ -0,0 +0,0 @@ public class CraftInventoryView extends InventoryView {
|
|
return CraftItemStack.asCraftMirror(this.container.getSlot(slot).getItem());
|
|
}
|
|
|
|
+ // 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() {
|
|
return CraftChatMessage.fromComponent(this.container.getTitle());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
@@ -0,0 +0,0 @@ public final class CraftItemFactory implements ItemFactory {
|
|
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) {
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
|
|
+ }
|
|
+ // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
|
|
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
|
|
public class CraftMerchantCustom extends CraftMerchant {
|
|
|
|
+ @Deprecated // Paper - Adventure
|
|
public CraftMerchantCustom(String title) {
|
|
super(new MinecraftMerchant(title));
|
|
this.getMerchant().craftMerchant = this;
|
|
}
|
|
+ // Paper start
|
|
+ public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
|
|
+ super(new MinecraftMerchant(title));
|
|
+ getMerchant().craftMerchant = this;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public String toString() {
|
|
@@ -0,0 +0,0 @@ public class CraftMerchantCustom extends CraftMerchant {
|
|
private Player tradingPlayer;
|
|
protected CraftMerchant craftMerchant;
|
|
|
|
+ @Deprecated // Paper - Adventure
|
|
public MinecraftMerchant(String title) {
|
|
Validate.notNull(title, "Title cannot be null");
|
|
this.title = CraftChatMessage.fromString(title)[0];
|
|
}
|
|
+ // Paper start
|
|
+ public MinecraftMerchant(net.kyori.adventure.text.Component title) {
|
|
+ Validate.notNull(title, "Title cannot be null");
|
|
+ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
@@ -0,0 +0,0 @@
|
|
package org.bukkit.craftbukkit.inventory;
|
|
|
|
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;
|
|
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
|
import org.bukkit.inventory.meta.BookMeta;
|
|
import org.bukkit.inventory.meta.BookMeta.Generation;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
// Spigot start
|
|
import static org.spigotmc.ValidateUtils.*;
|
|
+
|
|
import java.util.AbstractList;
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
|
import net.md_5.bungee.chat.ComponentSerializer;
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
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);
|
|
+ }
|
|
+
|
|
+ @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));
|
|
+ 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);
|
|
+ }
|
|
+
|
|
+ @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));
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component page(final int page) {
|
|
+ Validate.isTrue(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));
|
|
+ }
|
|
+
|
|
+ @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));
|
|
+ }
|
|
+
|
|
+ @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());
|
|
+ }
|
|
+
|
|
+ @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));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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());
|
|
+ }
|
|
+
|
|
+ static class CraftMetaBookBuilder implements BookMetaBuilder {
|
|
+ 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) {
|
|
+ return new CraftMetaBook(title, author, pages);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder toBuilder() {
|
|
+ return new CraftMetaBookBuilder();
|
|
+ }
|
|
+
|
|
+ // Paper end
|
|
@Override
|
|
public String getPage(final int page) {
|
|
Validate.isTrue(this.isValidPage(page), "Invalid page number");
|
|
@@ -0,0 +0,0 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
}
|
|
|
|
@Override
|
|
- Builder<String, Object> serialize(Builder<String, Object> builder) {
|
|
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
|
super.serialize(builder);
|
|
|
|
if (this.hasTitle()) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
@@ -0,0 +0,0 @@
|
|
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;
|
|
@@ -0,0 +0,0 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
|
|
}
|
|
|
|
@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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
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());
|
|
}
|
|
|
|
+ // 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);
|
|
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
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<net.kyori.adventure.text.Component> lore) {
|
|
+ this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asJson(lore) : null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public boolean hasRepairCost() {
|
|
return this.repairCost > 0;
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
|
|
@@ -0,0 +0,0 @@ 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);
|
|
@@ -0,0 +0,0 @@ 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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
|
|
@@ -0,0 +0,0 @@ public final class CraftInventoryCreator {
|
|
return this.converterMap.get(type).createInventory(holder, type);
|
|
}
|
|
|
|
+ // 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) {
|
|
return this.converterMap.get(type).createInventory(holder, type, title);
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftInventoryCreator {
|
|
return this.DEFAULT_CONVERTER.createInventory(holder, size);
|
|
}
|
|
|
|
+ // 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) {
|
|
return this.DEFAULT_CONVERTER.createInventory(holder, size, title);
|
|
}
|
|
@@ -0,0 +0,0 @@ public final class CraftInventoryCreator {
|
|
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
|
|
@@ -0,0 +0,0 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
|
return this.getInventory(this.getTileEntity());
|
|
}
|
|
|
|
+ // 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) {
|
|
Container te = this.getTileEntity();
|
|
@@ -0,0 +0,0 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
|
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) {
|
|
Container tileEntity = this.getTileEntity();
|
|
@@ -0,0 +0,0 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
|
return new BrewingStandBlockEntity(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
|
|
}
|
|
|
|
+ // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java
|
|
@@ -0,0 +0,0 @@ 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
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
|
|
@@ -0,0 +0,0 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
|
|
return this.objective.getName();
|
|
}
|
|
|
|
+ // 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 {
|
|
CraftScoreboard scoreboard = this.checkState();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
@@ -0,0 +0,0 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
|
|
return this.registerNewObjective(name, criteria, name);
|
|
}
|
|
+ // 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);
|
|
+ }
|
|
+ @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 {
|
|
+ if (displayName == null) {
|
|
+ displayName = net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+ Validate.notNull(name, "Objective name cannot be null");
|
|
+ Validate.notNull(criteria, "Criteria cannot be null");
|
|
+ Validate.notNull(displayName, "Display name cannot be null");
|
|
+ Validate.notNull(renderType, "RenderType cannot be null");
|
|
+ Validate.isTrue(name.length() <= Short.MAX_VALUE, "The name '" + name + "' is longer than the limit of 32767 characters");
|
|
+ Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
|
|
+ net.minecraft.world.scores.Objective objective = board.addObjective(name, ((CraftCriteria) criteria).criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
|
|
+ return new CraftObjective(this, objective);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
|
|
@@ -0,0 +0,0 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|
|
|
@Override
|
|
public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) throws IllegalArgumentException {
|
|
- Validate.notNull(name, "Objective name cannot be null");
|
|
- Validate.notNull(criteria, "Criteria cannot be null");
|
|
- Validate.notNull(displayName, "Display name cannot be null");
|
|
- Validate.notNull(renderType, "RenderType cannot be null");
|
|
- Validate.isTrue(name.length() <= Short.MAX_VALUE, "The name '" + name + "' is longer than the limit of 32767 characters");
|
|
- Validate.isTrue(displayName.length() <= 128, "The display name '" + displayName + "' is longer than the limit of 128 characters");
|
|
- Validate.isTrue(this.board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
|
|
-
|
|
- net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
|
|
- return new CraftObjective(this, objective);
|
|
+ return registerNewObjective(name, criteria, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(displayName), renderType); // Paper
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
@@ -0,0 +0,0 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
|
|
|
return this.team.getName();
|
|
}
|
|
+ // 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
|
|
+ public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ 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());
|
|
+ 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));
|
|
+ }
|
|
+ }
|
|
+ // 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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
|
|
@@ -0,0 +0,0 @@ public final class CraftChatMessage {
|
|
|
|
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
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
|
|
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();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
|
|
+ return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson();
|
|
+ }
|
|
+
|
|
+ @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();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
|
|
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection();
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public static BlockState getBlock(MaterialData material) {
|
|
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
|
|
@@ -0,0 +0,0 @@ public abstract class LazyHashSet<E> implements Set<E> {
|
|
return this.reference = this.makeReference();
|
|
}
|
|
|
|
- abstract Set<E> makeReference();
|
|
+ protected abstract Set<E> makeReference(); // Paper - protected
|
|
|
|
public boolean isLazy() {
|
|
return this.reference == null;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
|
|
@@ -0,0 +0,0 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
|
|
}
|
|
|
|
@Override
|
|
- HashSet<Player> makeReference() {
|
|
+ protected HashSet<Player> makeReference() { // Paper - protected
|
|
if (reference != null) {
|
|
throw new IllegalStateException("Reference already created!");
|
|
}
|
|
List<ServerPlayer> players = this.server.getPlayerList().players;
|
|
+ // Paper start
|
|
+ return makePlayerSet(this.server);
|
|
+ }
|
|
+ public static HashSet<Player> makePlayerSet(final MinecraftServer server) {
|
|
+ // Paper end
|
|
+ List<ServerPlayer> players = server.getPlayerList().players;
|
|
HashSet<Player> reference = new HashSet<Player>(players.size());
|
|
for (ServerPlayer player : players) {
|
|
reference.add(player.getBukkitEntity());
|
|
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..0000000000000000000000000000000000000000
|
|
--- /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..0000000000000000000000000000000000000000
|
|
--- /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..0000000000000000000000000000000000000000
|
|
--- /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..0000000000000000000000000000000000000000
|
|
--- /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..0000000000000000000000000000000000000000
|
|
--- /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..0000000000000000000000000000000000000000
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/adventure/ComponentServicesTest.java
|
|
@@ -0,0 +0,0 @@
|
|
+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)));
|
|
+ }
|
|
+}
|