2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Riley Park <riley.park@meino.net>
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/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2022-03-01 06:43:03 +01:00
index cc4c008a99bf5a16614d445d2a5e75ce2d5dedb5..043fd38598e36bb96e6d3ab1ab0966435c9aa61b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-11-09 08:59:15 +01:00
@@ -225,4 +225,13 @@ public class PaperConfig {
2021-06-11 14:02:28 +02:00
" - Length: " + timeSummary(Timings.getHistoryLength() / 20) +
" - Server Name: " + timingsServerName);
}
+
+ public static boolean useDisplayNameInQuit = false;
+ private static void useDisplayNameInQuit() {
2021-07-26 01:11:44 +02:00
+ if (version < 21) {
+ boolean oldValue = getBoolean("use-display-name-in-quit-message", useDisplayNameInQuit);
+ set("settings.use-display-name-in-quit-message", oldValue);
+ }
+ useDisplayNameInQuit = getBoolean("settings.use-display-name-in-quit-message", useDisplayNameInQuit);
2021-06-11 14:02:28 +02:00
+ }
}
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
2021-12-22 08:07:17 +01:00
index 0000000000000000000000000000000000000000..85546e1ac1d1ed7f70c3c0a1bf49937f865ad091
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
2021-06-12 00:37:16 +02:00
@@ -0,0 +1,82 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonSerializationContext;
+import com.google.gson.JsonSerializer;
+import java.lang.reflect.Type;
+import java.util.List;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.chat.Style;
2021-06-12 00:37:16 +02:00
+import net.minecraft.util.FormattedCharSequence;
2021-06-11 14:02:28 +02:00
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
2021-12-22 08:07:17 +01:00
+import org.jetbrains.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+public final class AdventureComponent implements net.minecraft.network.chat.Component {
2021-12-22 08:07:17 +01:00
+ final Component adventure;
+ private net.minecraft.network.chat.@MonotonicNonNull Component vanilla;
2021-06-11 14:02:28 +02:00
+
2021-12-22 08:07:17 +01:00
+ public AdventureComponent(final Component adventure) {
+ this.adventure = adventure;
2021-06-11 14:02:28 +02:00
+ }
+
+ public net.minecraft.network.chat.Component deepConverted() {
2021-12-22 08:07:17 +01:00
+ net.minecraft.network.chat.Component vanilla = this.vanilla;
+ if (vanilla == null) {
+ vanilla = PaperAdventure.WRAPPER_AWARE_SERIALIZER.serialize(this.adventure);
+ this.vanilla = vanilla;
2021-06-11 14:02:28 +02:00
+ }
2021-12-22 08:07:17 +01:00
+ return vanilla;
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-12 00:37:16 +02:00
+ public net.minecraft.network.chat.@Nullable Component deepConvertedIfPresent() {
2021-12-22 08:07:17 +01:00
+ return this.vanilla;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public Style getStyle() {
+ return this.deepConverted().getStyle();
+ }
+
+ @Override
+ public String getContents() {
2021-12-22 08:07:17 +01:00
+ if (this.adventure instanceof TextComponent) {
+ return ((TextComponent) this.adventure).content();
2021-06-11 14:02:28 +02:00
+ } else {
+ return this.deepConverted().getContents();
+ }
+ }
+
+ @Override
+ public String getString() {
2021-12-22 08:07:17 +01:00
+ return PaperAdventure.PLAIN.serialize(this.adventure);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public List<net.minecraft.network.chat.Component> getSiblings() {
+ return this.deepConverted().getSiblings();
+ }
+
+ @Override
+ public MutableComponent plainCopy() {
+ return this.deepConverted().plainCopy();
+ }
+
+ @Override
+ public MutableComponent copy() {
+ return this.deepConverted().copy();
+ }
+
2021-06-12 00:37:16 +02:00
+ @Override
+ public FormattedCharSequence getVisualOrderText() {
+ return this.deepConverted().getVisualOrderText();
+ }
+
2021-06-11 14:02:28 +02:00
+ public static class Serializer implements JsonSerializer<AdventureComponent> {
+ @Override
+ public JsonElement serialize(final AdventureComponent src, final Type type, final JsonSerializationContext context) {
2021-12-22 08:07:17 +01:00
+ return PaperAdventure.GSON.serializer().toJsonTree(src.adventure, Component.class);
2021-06-11 14:02:28 +02:00
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
new file mode 100644
2021-10-17 18:57:00 +02:00
index 0000000000000000000000000000000000000000..0bc2c2ef9312ebcc32dacdd2ba9f17d2ba072586
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
2021-10-13 11:00:40 +02:00
@@ -0,0 +1,228 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import io.papermc.paper.chat.ChatRenderer;
+import io.papermc.paper.event.player.AbstractChatEvent;
+import io.papermc.paper.event.player.AsyncChatEvent;
+import io.papermc.paper.event.player.ChatEvent;
2021-06-19 00:47:40 +02:00
+import java.util.HashSet;
2021-06-11 14:02:28 +02:00
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
+
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.audience.MessageType;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextReplacementConfig;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.Bukkit;
+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;
+
+public final class ChatProcessor {
+ // <-- copied from adventure-text-serializer-legacy
+ private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
+ private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*:");
+ private static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder()
+ .match(DEFAULT_URL_PATTERN)
+ .replacement(url -> {
+ String clickUrl = url.content();
+ if (!URL_SCHEME_PATTERN.matcher(clickUrl).find()) {
+ clickUrl = "http://" + clickUrl;
+ }
+ return url.clickEvent(ClickEvent.openUrl(clickUrl));
+ })
+ .build();
+ // copied from adventure-text-serializer-legacy -->
2021-10-13 11:00:40 +02:00
+ private static final String DEFAULT_LEGACY_FORMAT = "<%1$s> %2$s"; // copied from PlayerChatEvent/AsyncPlayerChatEvent
2021-06-11 14:02:28 +02:00
+ final MinecraftServer server;
+ final ServerPlayer player;
+ final String message;
+ final boolean async;
+ final Component originalMessage;
+
+ public ChatProcessor(final MinecraftServer server, final ServerPlayer player, final String message, final boolean async) {
+ this.server = server;
+ this.player = player;
+ this.message = message;
+ this.async = async;
+ this.originalMessage = Component.text(message);
+ }
+
+ @SuppressWarnings({"CodeBlock2Expr", "deprecated"})
+ public void process() {
+ this.processingLegacyFirst(
+ // continuing from AsyncPlayerChatEvent (without PlayerChatEvent)
+ event -> {
+ this.processModern(
+ legacyRenderer(event.getFormat()),
2021-06-19 00:47:40 +02:00
+ this.viewersFromLegacy(event.getRecipients()),
2021-06-11 14:02:28 +02:00
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
+ event.isCancelled()
+ );
+ },
+ // continuing from AsyncPlayerChatEvent and PlayerChatEvent
+ event -> {
+ this.processModern(
+ legacyRenderer(event.getFormat()),
2021-06-19 00:47:40 +02:00
+ this.viewersFromLegacy(event.getRecipients()),
2021-06-11 14:02:28 +02:00
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
+ event.isCancelled()
+ );
+ },
+ // no legacy events called, all nice and fresh!
+ () -> {
+ this.processModern(
+ ChatRenderer.defaultRenderer(),
2021-06-19 00:47:40 +02:00
+ new LazyChatAudienceSet(this.server),
2021-06-11 14:02:28 +02:00
+ Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG),
+ false
+ );
+ }
+ );
+ }
+
2021-06-19 00:47:40 +02:00
+ private Set<Audience> viewersFromLegacy(final Set<Player> recipients) {
+ if (recipients instanceof LazyPlayerSet lazyPlayerSet && lazyPlayerSet.isLazy()) {
+ return new LazyChatAudienceSet(this.server);
+ }
+ final HashSet<Audience> viewers = new HashSet<>(recipients);
+ viewers.add(this.server.console);
+ return viewers;
+ }
+
2021-06-11 14:02:28 +02:00
+ @SuppressWarnings("deprecation")
+ private void processingLegacyFirst(
+ final Consumer<AsyncPlayerChatEvent> continueAfterAsync,
+ final Consumer<PlayerChatEvent> continueAfterAsyncAndSync,
+ final Runnable modernOnly
+ ) {
+ final boolean listenersOnAsyncEvent = anyListeners(AsyncPlayerChatEvent.getHandlerList());
+ final boolean listenersOnSyncEvent = anyListeners(PlayerChatEvent.getHandlerList());
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
+ final CraftPlayer player = this.player.getBukkitEntity();
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.message, new LazyPlayerSet(this.server));
+ 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() {
+ post(se);
+ return null;
+ }
+ });
+ continueAfterAsyncAndSync.accept(se);
+ } else {
+ continueAfterAsync.accept(ae);
+ }
+ } else {
+ modernOnly.run();
+ }
+ }
+
2021-06-19 00:47:40 +02:00
+ private void processModern(final ChatRenderer renderer, final Set<Audience> viewers, final Component message, final boolean cancelled) {
+ final AsyncChatEvent ae = this.createAsync(renderer, viewers, message);
2021-06-11 14:02:28 +02:00
+ ae.setCancelled(cancelled); // propagate cancelled state
+ post(ae);
+ final boolean listenersOnSyncEvent = anyListeners(ChatEvent.getHandlerList());
+ if (listenersOnSyncEvent) {
+ this.continueWithSyncFromWhereAsyncLeftOff(ae);
+ } else {
+ this.complete(ae);
+ }
+ }
+
+ private void continueWithSyncFromWhereAsyncLeftOff(final AsyncChatEvent ae) {
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
2021-06-19 00:47:40 +02:00
+ final ChatEvent se = ChatProcessor.this.createSync(ae.renderer(), ae.viewers(), ae.message());
2021-06-11 14:02:28 +02:00
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ post(se);
+ ChatProcessor.this.complete(se);
+ return null;
+ }
+ });
+ }
+
+ private void complete(final AbstractChatEvent event) {
+ if (event.isCancelled()) {
+ return;
+ }
+
+ final CraftPlayer player = this.player.getBukkitEntity();
+ final Component displayName = displayName(player);
+ final Component message = event.message();
+ final ChatRenderer renderer = event.renderer();
+
+ final Set<Audience> viewers = event.viewers();
2021-06-19 00:47:40 +02:00
+
+ if (viewers instanceof LazyChatAudienceSet lazyAudienceSet && lazyAudienceSet.isLazy()) {
+ this.server.console.sendMessage(player, renderer.render(player, displayName, message, this.server.console), MessageType.CHAT);
+ for (final ServerPlayer viewer : this.server.getPlayerList().getPlayers()) {
+ final Player bukkit = viewer.getBukkitEntity();
+ bukkit.sendMessage(player, renderer.render(player, displayName, message, bukkit), MessageType.CHAT);
2021-06-11 14:02:28 +02:00
+ }
+ } else {
2021-06-19 00:47:40 +02:00
+ for (final Audience viewer : viewers) {
+ viewer.sendMessage(player, renderer.render(player, displayName, message, viewer), MessageType.CHAT);
2021-06-11 14:02:28 +02:00
+ }
+ }
+ }
+
2021-06-19 00:47:40 +02:00
+ private AsyncChatEvent createAsync(final ChatRenderer renderer, final Set<Audience> viewers, final Component message) {
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), viewers, renderer, message, this.originalMessage);
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-19 00:47:40 +02:00
+ private ChatEvent createSync(final ChatRenderer renderer, final Set<Audience> viewers, final Component message) {
+ return new ChatEvent(this.player.getBukkitEntity(), viewers, renderer, message, this.originalMessage);
2021-06-11 14:02:28 +02:00
+ }
+
+ private static String legacyDisplayName(final CraftPlayer player) {
+ return player.getDisplayName();
+ }
+
+ private static Component displayName(final CraftPlayer player) {
+ return player.displayName();
+ }
+
+ private static ChatRenderer legacyRenderer(final String format) {
2021-10-13 11:00:40 +02:00
+ if (DEFAULT_LEGACY_FORMAT.equals(format)) {
+ return ChatRenderer.defaultRenderer();
+ }
2021-10-02 20:43:03 +02:00
+ return ChatRenderer.viewerUnaware((player, displayName, message) -> PaperAdventure.LEGACY_SECTION_UXRC.deserialize(String.format(format, legacyDisplayName((CraftPlayer) player), PaperAdventure.LEGACY_SECTION_UXRC.serialize(message))).replaceText(URL_REPLACEMENT_CONFIG));
2021-06-11 14:02:28 +02:00
+ }
+
+ private void queueIfAsyncOrRunImmediately(final Waitable<Void> waitable) {
+ if (this.async) {
+ this.server.processQueue.add(waitable);
+ } else {
+ waitable.run();
+ }
+ try {
+ waitable.get();
+ } catch (final InterruptedException e) {
+ Thread.currentThread().interrupt(); // tag, you're it
+ } catch (final ExecutionException e) {
+ throw new RuntimeException("Exception processing chat", e.getCause());
+ }
+ }
+
+ private static void post(final Event event) {
+ Bukkit.getPluginManager().callEvent(event);
+ }
+
+ private static boolean anyListeners(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..bfaf5d3c5aae8a587c2b11d90089c588b2a2aba0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/DisplayNames.java
@@ -0,0 +1,22 @@
+package io.papermc.paper.adventure;
+
+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) {
+ return PaperAdventure.LEGACY_SECTION_UXRC.serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName);
+ }
+ return PaperAdventure.LEGACY_SECTION_UXRC.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
2021-06-19 00:47:40 +02:00
index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559b6e105ce
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
2021-06-19 00:47:40 +02:00
@@ -0,0 +1,26 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
2021-06-19 00:47:40 +02:00
+import java.util.HashSet;
+import java.util.Set;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.audience.Audience;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.util.LazyHashSet;
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
+import org.bukkit.entity.Player;
+
+final class LazyChatAudienceSet extends LazyHashSet<Audience> {
2021-06-19 00:47:40 +02:00
+ private final MinecraftServer server;
+
+ public LazyChatAudienceSet(final MinecraftServer server) {
+ this.server = server;
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ protected Set<Audience> makeReference() {
2021-06-19 00:47:40 +02:00
+ final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(this.server);
2021-06-11 14:02:28 +02:00
+ final HashSet<Audience> audiences = new HashSet<>(playerSet);
+ audiences.add(Bukkit.getConsoleSender());
+ return audiences;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java b/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java
new file mode 100644
index 0000000000000000000000000000000000000000..eeedc30a45d9637d68f04f185b3dd90dd711b9e0
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/NBTLegacyHoverEventSerializer.java
@@ -0,0 +1,88 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import java.io.IOException;
+import java.util.UUID;
+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.PlainComponentSerializer;
+import net.kyori.adventure.util.Codec;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.Tag;
+import net.minecraft.nbt.TagParser;
+
+final class NBTLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
+ public static final NBTLegacyHoverEventSerializer INSTANCE = new NBTLegacyHoverEventSerializer();
+ private static final Codec<CompoundTag, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.of(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 = PlainComponentSerializer.plain().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 = PlainComponentSerializer.plain().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/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
new file mode 100644
2021-12-22 23:56:37 +01:00
index 0000000000000000000000000000000000000000..3661ac5e3bfdebb2911cb1b118942b9fc7884140
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
2021-12-22 23:56:37 +01:00
@@ -0,0 +1,361 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.netty.util.AttributeKey;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.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.gson.GsonComponentSerializer;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
2021-12-22 23:56:37 +01:00
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
2021-12-22 08:07:17 +01:00
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.translation.GlobalTranslator;
2021-09-03 19:01:05 +02:00
+import net.kyori.adventure.translation.TranslationRegistry;
+import net.kyori.adventure.translation.Translator;
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.util.Codec;
+import net.minecraft.ChatFormatting;
2021-09-01 23:03:00 +02:00
+import net.minecraft.locale.Language;
2021-06-11 14:02:28 +02:00
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.nbt.StringTag;
+import net.minecraft.nbt.TagParser;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.sounds.SoundSource;
+import net.minecraft.world.BossEvent;
+import net.minecraft.world.item.ItemStack;
2021-07-20 01:11:06 +02:00
+import net.minecraft.world.item.WrittenBookItem;
2021-06-11 14:02:28 +02:00
+import org.bukkit.ChatColor;
2021-12-22 08:07:17 +01:00
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
2021-06-11 14:02:28 +02:00
+
+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) -> {
2021-09-01 23:03:00 +02:00
+ if (!Language.getInstance().has(translatable.key())) {
2021-09-03 19:01:05 +02:00
+ for (final Translator source : GlobalTranslator.get().sources()) {
+ if (source instanceof TranslationRegistry registry && registry.contains(translatable.key())) {
+ consumer.accept(GlobalTranslator.render(translatable, Locale.US));
+ return;
+ }
+ }
2021-09-01 23:03:00 +02:00
+ }
2021-12-22 08:07:17 +01:00
+ final @NotNull String translated = Language.getInstance().getOrDefault(translatable.key());
2021-06-11 14:02:28 +02:00
+
+ final Matcher matcher = LOCALIZATION_PATTERN.matcher(translated);
+ final List<Component> args = translatable.args();
+ int argPosition = 0;
+ int lastIdx = 0;
+ while (matcher.find()) {
+ // append prior
+ if (lastIdx < matcher.start()) {
+ consumer.accept(Component.text(translated.substring(lastIdx, matcher.start())));
+ }
+ lastIdx = matcher.end();
+
+ final @Nullable String argIdx = matcher.group(1);
+ // calculate argument position
+ if (argIdx != null) {
+ try {
+ final int idx = Integer.parseInt(argIdx) - 1;
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ } catch (final NumberFormatException ex) {
+ // ignore, drop the format placeholder
+ }
+ } else {
+ final int idx = argPosition++;
+ if (idx < args.size()) {
+ consumer.accept(args.get(idx));
+ }
+ }
+ }
+
+ // append tail
+ if (lastIdx < translated.length()) {
+ consumer.accept(Component.text(translated.substring(lastIdx)));
+ }
+ })
+ .build();
+ public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().flattener(FLATTENER).hexColors().useUnusualXRepeatedCharacterHexFormat().build();
2021-12-22 23:56:37 +01:00
+ public static final PlainComponentSerializer PLAIN_COMPONENT = PlainComponentSerializer.builder().flattener(FLATTENER).build();
2021-12-22 08:07:17 +01:00
+ public static final PlainTextComponentSerializer PLAIN = PlainTextComponentSerializer.builder().flattener(FLATTENER).build();
2021-06-11 14:02:28 +02:00
+ public static final GsonComponentSerializer GSON = GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .build();
+ public static final GsonComponentSerializer COLOR_DOWNSAMPLING_GSON = GsonComponentSerializer.builder()
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
+ .downsampleColors()
+ .build();
+ private static final Codec<CompoundTag, String, IOException, IOException> NBT_CODEC = new Codec<CompoundTag, String, IOException, IOException>() {
+ @Override
2021-12-22 08:07:17 +01:00
+ public @NotNull CompoundTag decode(final @NotNull String encoded) throws IOException {
2021-06-11 14:02:28 +02:00
+ try {
+ return TagParser.parseTag(encoded);
+ } catch (final CommandSyntaxException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
2021-12-22 08:07:17 +01:00
+ public @NotNull String encode(final @NotNull CompoundTag decoded) {
2021-06-11 14:02:28 +02:00
+ return decoded.toString();
+ }
+ };
+ static final WrapperAwareSerializer 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 new ResourceLocation(key.namespace(), key.value());
+ }
+
+ // Component
+
+ public static Component asAdventure(final net.minecraft.network.chat.Component component) {
+ return component == null ? Component.empty() : 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) {
2021-12-22 08:07:17 +01:00
+ if (component == null) return null;
2021-06-11 14:02:28 +02:00
+ if (true) return new AdventureComponent(component);
2021-06-16 19:48:25 +02:00
+ return net.minecraft.network.chat.Component.Serializer.fromJson(GSON.serializer().toJsonTree(component));
2021-06-11 14:02:28 +02:00
+ }
+
+ public static List<net.minecraft.network.chat.Component> asVanilla(final List<Component> adventures) {
+ final List<net.minecraft.network.chat.Component> vanillas = new ArrayList<>(adventures.size());
+ for (final Component adventure : adventures) {
+ vanillas.add(asVanilla(adventure));
+ }
+ return vanillas;
+ }
+
+ public static String asJsonString(final Component component, final Locale locale) {
+ return GSON.serialize(
+ GlobalTranslator.render(
+ component,
+ // play it safe
+ locale != null
+ ? locale
+ : Locale.US
+ )
+ );
+ }
+
+ public static String asJsonString(final net.minecraft.network.chat.Component component, final Locale locale) {
+ if (component instanceof AdventureComponent) {
2021-12-22 08:07:17 +01:00
+ return asJsonString(((AdventureComponent) component).adventure, locale);
2021-06-11 14:02:28 +02:00
+ }
2021-06-16 19:48:25 +02:00
+ return net.minecraft.network.chat.Component.Serializer.toJson(component);
2021-06-11 14:02:28 +02:00
+ }
+
2021-07-20 01:11:06 +02:00
+ public static String asPlain(final Component component, final Locale locale) {
+ return PLAIN.serialize(
+ GlobalTranslator.render(
+ component,
+ // play it safe
+ locale != null
+ ? locale
+ : Locale.US
+ )
+ );
+ }
+
2021-06-11 14:02:28 +02:00
+ // thank you for being worse than wet socks, Bukkit
+ public static String superHackyLegacyRepresentationOfComponent(final Component component, final String string) {
+ return LEGACY_SECTION_UXRC.serialize(component) + ChatColor.getLastColors(string);
+ }
+
+ // BossBar
+
+ public static BossEvent.BossBarColor asVanilla(final BossBar.Color color) {
2021-12-22 08:07:17 +01:00
+ return switch (color) {
+ case PINK -> BossEvent.BossBarColor.PINK;
+ case BLUE -> BossEvent.BossBarColor.BLUE;
+ case RED -> BossEvent.BossBarColor.RED;
+ case GREEN -> BossEvent.BossBarColor.GREEN;
+ case YELLOW -> BossEvent.BossBarColor.YELLOW;
+ case PURPLE -> BossEvent.BossBarColor.PURPLE;
+ case WHITE -> BossEvent.BossBarColor.WHITE;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossBar.Color asAdventure(final BossEvent.BossBarColor color) {
2021-12-22 08:07:17 +01:00
+ return switch (color) {
+ case PINK -> BossBar.Color.PINK;
+ case BLUE -> BossBar.Color.BLUE;
+ case RED -> BossBar.Color.RED;
+ case GREEN -> BossBar.Color.GREEN;
+ case YELLOW -> BossBar.Color.YELLOW;
+ case PURPLE -> BossBar.Color.PURPLE;
+ case WHITE -> BossBar.Color.WHITE;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossEvent.BossBarOverlay asVanilla(final BossBar.Overlay overlay) {
2021-12-22 08:07:17 +01:00
+ return switch (overlay) {
+ case PROGRESS -> BossEvent.BossBarOverlay.PROGRESS;
+ case NOTCHED_6 -> BossEvent.BossBarOverlay.NOTCHED_6;
+ case NOTCHED_10 -> BossEvent.BossBarOverlay.NOTCHED_10;
+ case NOTCHED_12 -> BossEvent.BossBarOverlay.NOTCHED_12;
+ case NOTCHED_20 -> BossEvent.BossBarOverlay.NOTCHED_20;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static BossBar.Overlay asAdventure(final BossEvent.BossBarOverlay overlay) {
2021-12-22 08:07:17 +01:00
+ return switch (overlay) {
+ case PROGRESS -> BossBar.Overlay.PROGRESS;
+ case NOTCHED_6 -> BossBar.Overlay.NOTCHED_6;
+ case NOTCHED_10 -> BossBar.Overlay.NOTCHED_10;
+ case NOTCHED_12 -> BossBar.Overlay.NOTCHED_12;
+ case NOTCHED_20 -> BossBar.Overlay.NOTCHED_20;
+ };
2021-06-11 14:02:28 +02:00
+ }
+
+ public static void setFlag(final BossBar bar, final BossBar.Flag flag, final boolean value) {
+ if (value) {
+ bar.addFlag(flag);
+ } else {
+ bar.removeFlag(flag);
+ }
+ }
+
+ // Book
+
+ public static ItemStack asItemStack(final Book book, final Locale locale) {
+ final ItemStack item = new ItemStack(net.minecraft.world.item.Items.WRITTEN_BOOK, 1);
+ final CompoundTag tag = item.getOrCreateTag();
2021-07-20 01:11:06 +02:00
+ tag.putString(WrittenBookItem.TAG_TITLE, validateField(asPlain(book.title(), locale), WrittenBookItem.TITLE_MAX_LENGTH, WrittenBookItem.TAG_TITLE));
+ tag.putString(WrittenBookItem.TAG_AUTHOR, asPlain(book.author(), locale));
2021-06-11 14:02:28 +02:00
+ final ListTag pages = new ListTag();
2021-07-20 01:11:06 +02:00
+ if (book.pages().size() > WrittenBookItem.MAX_PAGES) {
+ throw new IllegalArgumentException("Book provided had " + book.pages().size() + " pages, but is only allowed a maximum of " + WrittenBookItem.MAX_PAGES);
+ }
2021-06-11 14:02:28 +02:00
+ for (final Component page : book.pages()) {
2021-07-20 01:11:06 +02:00
+ pages.add(StringTag.valueOf(validateField(asJsonString(page, locale), WrittenBookItem.PAGE_LENGTH, "page")));
2021-06-11 14:02:28 +02:00
+ }
2021-07-20 01:11:06 +02:00
+ tag.put(WrittenBookItem.TAG_PAGES, pages);
2021-06-11 14:02:28 +02:00
+ return item;
+ }
+
2021-07-20 01:11:06 +02:00
+ private static String validateField(final String content, final int length, final String name) {
+ if (content == null) {
+ return content;
+ }
+
+ final int actual = content.length();
+ if (actual > length) {
+ throw new IllegalArgumentException("Field '" + name + "' has a maximum length of " + length + " but was passed '" + content + "', which was " + actual + " characters long.");
+ }
+ return content;
+ }
+
2021-06-11 14:02:28 +02:00
+ // Sounds
+
+ public static SoundSource asVanilla(final Sound.Source source) {
+ if (source == Sound.Source.MASTER) {
+ return SoundSource.MASTER;
+ } else if (source == Sound.Source.MUSIC) {
+ return SoundSource.MUSIC;
+ } else if (source == Sound.Source.RECORD) {
+ return SoundSource.RECORDS;
+ } else if (source == Sound.Source.WEATHER) {
+ return SoundSource.WEATHER;
+ } else if (source == Sound.Source.BLOCK) {
+ return SoundSource.BLOCKS;
+ } else if (source == Sound.Source.HOSTILE) {
+ return SoundSource.HOSTILE;
+ } else if (source == Sound.Source.NEUTRAL) {
+ return SoundSource.NEUTRAL;
+ } else if (source == Sound.Source.PLAYER) {
+ return SoundSource.PLAYERS;
+ } else if (source == Sound.Source.AMBIENT) {
+ return SoundSource.AMBIENT;
+ } else if (source == Sound.Source.VOICE) {
+ return SoundSource.VOICE;
+ }
+ throw new IllegalArgumentException(source.name());
+ }
+
+ 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
+
2021-12-22 08:07:17 +01:00
+ public static @NotNull TextColor asAdventure(final ChatFormatting formatting) {
+ final Integer color = formatting.getColor();
+ if (color == null) {
2021-06-11 14:02:28 +02:00
+ throw new IllegalArgumentException("Not a valid color");
+ }
2021-12-22 08:07:17 +01:00
+ return TextColor.color(color);
2021-06-11 14:02:28 +02:00
+ }
+
2021-12-22 08:07:17 +01:00
+ public static @Nullable ChatFormatting asVanilla(final TextColor color) {
2021-06-11 14:02:28 +02:00
+ return ChatFormatting.getByHexValue(color.value());
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
new file mode 100644
2021-06-12 00:37:16 +02:00
index 0000000000000000000000000000000000000000..7493efba31403cbe7f26e493f165f1b83aa847bb
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
2021-06-12 00:37:16 +02:00
@@ -0,0 +1,44 @@
2021-06-11 14:02:28 +02:00
+package io.papermc.paper.adventure;
+
+import java.util.Set;
+import java.util.function.Consumer;
2021-06-12 00:37:16 +02:00
+import java.util.function.Function;
+
2021-06-11 14:02:28 +02:00
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.text.Component;
+import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
2021-06-12 00:37:16 +02:00
+import net.minecraft.world.BossEvent;
2021-06-11 14:02:28 +02:00
+import org.checkerframework.checker.nullness.qual.NonNull;
+
+public final class VanillaBossBarListener implements BossBar.Listener {
2021-06-12 00:37:16 +02:00
+ private final Consumer<Function<BossEvent, ClientboundBossEventPacket>> action;
2021-06-11 14:02:28 +02:00
+
2021-06-12 00:37:16 +02:00
+ public VanillaBossBarListener(final Consumer<Function<BossEvent, ClientboundBossEventPacket>> action) {
2021-06-11 14:02:28 +02:00
+ this.action = action;
+ }
+
+ @Override
+ public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
2021-06-12 00:37:16 +02:00
+ this.action.accept(ClientboundBossEventPacket::createUpdateNamePacket);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
2021-06-12 00:37:16 +02:00
+ this.action.accept(ClientboundBossEventPacket::createUpdateProgressPacket);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
2021-06-12 00:37:16 +02:00
+ this.action.accept(ClientboundBossEventPacket::createUpdateStylePacket);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
2021-06-12 00:37:16 +02:00
+ this.action.accept(ClientboundBossEventPacket::createUpdateStylePacket);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
2021-06-12 00:37:16 +02:00
+ this.action.accept(ClientboundBossEventPacket::createUpdatePropertiesPacket);
2021-06-11 14:02:28 +02:00
+ }
+}
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
2021-12-22 08:07:17 +01:00
index 0000000000000000000000000000000000000000..76be058996599dd798d26a166d1a5139ee72761a
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
@@ -0,0 +1,19 @@
+package io.papermc.paper.adventure;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
+
+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) {
2021-12-22 08:07:17 +01:00
+ return ((AdventureComponent) input).adventure;
2021-06-11 14:02:28 +02:00
+ }
+ return PaperAdventure.GSON.serializer().fromJson(net.minecraft.network.chat.Component.Serializer.toJsonTree(input), Component.class);
+ }
+
+ @Override
+ public net.minecraft.network.chat.Component serialize(final Component component) {
2021-06-16 19:48:25 +02:00
+ return net.minecraft.network.chat.Component.Serializer.fromJson(PaperAdventure.GSON.serializer().toJsonTree(component));
2021-06-11 14:02:28 +02:00
+ }
+}
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..2dc92d8d2764d3e9b621d5c7d5e30c30367b3117
--- /dev/null
+++ b/src/main/java/net/kyori/adventure/bossbar/HackyBossBarPlatformBridge.java
@@ -0,0 +1,36 @@
+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
2021-11-26 23:58:39 +01:00
index 9143392884801e952a96cb5e7b761c7a827fa648..3a13544bc3b8f8dc6a38aacb6af99b25365dd6d1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/ChatFormatting.java
+++ b/src/main/java/net/minecraft/ChatFormatting.java
2021-06-16 19:48:25 +02:00
@@ -110,6 +110,18 @@ public enum ChatFormatting {
2021-06-11 21:23:46 +02:00
return name == null ? null : FORMATTING_BY_NAME.get(cleanName(name));
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Nullable public static ChatFormatting getByHexValue(int i) {
+ for (ChatFormatting value : values()) {
2021-06-16 19:48:25 +02:00
+ if (value.getColor() != null && value.getColor() == i) {
2021-06-11 14:02:28 +02:00
+ return value;
+ }
+ }
+
+ return null;
+ }
+ // Paper end
+
@Nullable
public static ChatFormatting getById(int colorIndex) {
if (colorIndex < 0) {
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2021-11-23 12:27:39 +01:00
index d5d94ea8070ab5f66f0a3244a5a953b9c9d5c527..0053474ab7c25de6d86c16e3079feb21f75d1c11 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
2021-06-11 21:23:46 +02:00
@@ -14,6 +14,7 @@ import io.netty.handler.codec.EncoderException;
2021-06-11 14:02:28 +02:00
import io.netty.util.ByteProcessor;
2021-06-11 21:23:46 +02:00
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
2021-06-11 14:02:28 +02:00
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.DataOutput;
import java.io.IOException;
2021-11-23 12:27:39 +01:00
import java.io.InputStream;
@@ -61,6 +62,7 @@ public class FriendlyByteBuf extends ByteBuf {
2021-06-11 21:23:46 +02:00
private static final int MAX_VARLONG_SIZE = 10;
private static final int DEFAULT_NBT_QUOTA = 2097152;
2021-06-11 14:02:28 +02:00
private final ByteBuf source;
+ public java.util.Locale adventure$locale; // Paper
2021-06-11 21:23:46 +02:00
public static final short MAX_STRING_LENGTH = 32767;
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
2021-06-11 14:02:28 +02:00
2021-11-23 12:27:39 +01:00
@@ -350,8 +352,15 @@ public class FriendlyByteBuf extends ByteBuf {
2021-06-11 14:02:28 +02:00
return Component.Serializer.fromJson(this.readUtf(262144));
}
+ // Paper start
+ public FriendlyByteBuf writeComponent(final net.kyori.adventure.text.Component component) {
+ return this.writeUtf(PaperAdventure.asJsonString(component, this.adventure$locale), 262144);
+ }
+ // Paper end
+
public FriendlyByteBuf writeComponent(Component text) {
- return this.writeUtf(Component.Serializer.toJson(text), 262144);
+ //return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144); // Paper - comment
+ return this.writeUtf(PaperAdventure.asJsonString(text, this.adventure$locale), 262144); // Paper
}
2021-06-11 21:23:46 +02:00
public <T extends Enum<T>> T readEnum(Class<T> enumClass) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/PacketEncoder.java b/src/main/java/net/minecraft/network/PacketEncoder.java
2022-03-01 06:43:03 +01:00
index 021a26a6b1c258deffc26c035ab52a4ea027d9a1..00d432bd395e7f7fb6ee24e371818d13892b2f0c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/PacketEncoder.java
+++ b/src/main/java/net/minecraft/network/PacketEncoder.java
2022-03-01 06:43:03 +01:00
@@ -4,6 +4,7 @@ import com.mojang.logging.LogUtils;
2021-06-11 14:02:28 +02:00
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.io.IOException;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketFlow;
2022-03-01 06:43:03 +01:00
@@ -33,6 +34,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
2021-06-11 14:02:28 +02:00
} else {
2021-06-11 21:23:46 +02:00
FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(byteBuf);
friendlyByteBuf.writeVarInt(integer);
+ friendlyByteBuf.adventure$locale = channelHandlerContext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
try {
int i = friendlyByteBuf.writerIndex();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/chat/Component.java b/src/main/java/net/minecraft/network/chat/Component.java
2021-11-23 12:27:39 +01:00
index 4d664338f3d5570fd0133ace6b297d70045b34a7..984105c226f16746b43bb2d2932e0b87f3a6a70c 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/chat/Component.java
+++ b/src/main/java/net/minecraft/network/chat/Component.java
2021-06-11 21:23:46 +02:00
@@ -1,6 +1,7 @@
2021-06-11 14:02:28 +02:00
package net.minecraft.network.chat;
2021-06-11 21:23:46 +02:00
import com.google.common.collect.Lists;
2021-06-11 14:02:28 +02:00
+import io.papermc.paper.adventure.AdventureComponent; // Paper
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
2021-06-11 21:23:46 +02:00
@@ -161,6 +162,7 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
2021-06-11 14:02:28 +02:00
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.disableHtmlEscaping();
+ gsonbuilder.registerTypeAdapter(AdventureComponent.class, new AdventureComponent.Serializer()); // Paper
gsonbuilder.registerTypeHierarchyAdapter(Component.class, new Component.Serializer());
gsonbuilder.registerTypeHierarchyAdapter(Style.class, new Style.Serializer());
gsonbuilder.registerTypeAdapterFactory(new LowerCaseEnumTypeAdapterFactory());
2021-06-11 21:23:46 +02:00
@@ -320,6 +322,7 @@ public interface Component extends Message, FormattedText, Iterable<Component> {
2021-06-11 14:02:28 +02:00
}
public JsonElement serialize(Component ichatbasecomponent, Type type, JsonSerializationContext jsonserializationcontext) {
+ if (ichatbasecomponent instanceof AdventureComponent) return jsonserializationcontext.serialize(ichatbasecomponent); // Paper
JsonObject jsonobject = new JsonObject();
if (!ichatbasecomponent.getStyle().isEmpty()) {
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundChatPacket.java
2021-11-26 23:58:39 +01:00
index 743db7bfc58ff9e90a1b6d20d1bf64ecb6906327..f4f52e43852d2b0b56770c3f747a655a3a6dd683 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundChatPacket.java
2021-06-11 21:23:46 +02:00
@@ -10,6 +10,7 @@ import net.minecraft.network.protocol.Packet;
2021-06-11 14:02:28 +02:00
public class ClientboundChatPacket implements Packet<ClientGamePacketListener> {
2021-06-11 21:23:46 +02:00
private final Component message;
2021-06-11 14:02:28 +02:00
+ public net.kyori.adventure.text.Component adventure$message; // Paper
public net.md_5.bungee.api.chat.BaseComponent[] components; // Spigot
2021-06-11 21:23:46 +02:00
private final ChatType type;
private final UUID sender;
@@ -28,6 +29,11 @@ public class ClientboundChatPacket implements Packet<ClientGamePacketListener> {
2021-06-11 14:02:28 +02:00
@Override
2021-06-11 21:23:46 +02:00
public void write(FriendlyByteBuf buf) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (this.adventure$message != null) {
+ buf.writeComponent(this.adventure$message);
+ } else
+ // Paper end
// Spigot start
2021-06-11 21:23:46 +02:00
if (this.components != null) {
buf.writeUtf(net.md_5.bungee.chat.ComponentSerializer.toString(components));
2021-06-16 01:41:38 +02:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
index 02183c810f9968621b9b20c1f7b54258b620c507..32ef3edebe94a2014168b7e438752a80b2687e5f 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetActionBarTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetActionBarTextPacket(Component message) {
this.text = message;
@@ -17,6 +18,11 @@ public class ClientboundSetActionBarTextPacket implements Packet<ClientGamePacke
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
index bea682c52a95863c474b8283bd4ae795e525a94f..c44a276d201fdfa5144d45d319d7761583c60639 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetSubtitleTextPacket(Component subtitle) {
this.text = subtitle;
@@ -17,6 +18,11 @@ public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacket
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
index 1fb62779527a228f748b49a4d2ddfc57ccb80cf8..bd808eb312ade7122973a47f4b96505829511da5 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
@@ -6,6 +6,7 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketListener> {
private final Component text;
+ public net.kyori.adventure.text.Component adventure$text; // Paper
public ClientboundSetTitleTextPacket(Component title) {
this.text = title;
@@ -17,6 +18,11 @@ public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketLis
@Override
public void write(FriendlyByteBuf buf) {
+ // Paper start
+ if (this.adventure$text != null) {
+ buf.writeComponent(this.adventure$text);
+ } else
+ // Paper end
buf.writeComponent(this.text);
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
2021-06-11 21:23:46 +02:00
index 762a9392ffac3042356709dddd15bb3516048bed..3544e2dc2522e9d6305d727d56e73490015662c2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundTabListPacket.java
2021-06-11 21:23:46 +02:00
@@ -7,6 +7,10 @@ import net.minecraft.network.protocol.Packet;
public class ClientboundTabListPacket implements Packet<ClientGamePacketListener> {
public final Component header;
public final Component footer;
2021-06-11 14:02:28 +02:00
+ // Paper start
+ public net.kyori.adventure.text.Component adventure$header;
+ public net.kyori.adventure.text.Component adventure$footer;
+ // Paper end
2021-06-11 21:23:46 +02:00
public ClientboundTabListPacket(Component header, Component footer) {
this.header = header;
2021-06-11 14:02:28 +02:00
@@ -20,6 +24,13 @@ public class ClientboundTabListPacket implements Packet<ClientGamePacketListener
@Override
2021-06-11 21:23:46 +02:00
public void write(FriendlyByteBuf buf) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ if (this.adventure$header != null && this.adventure$footer != null) {
+ buf.writeComponent(this.adventure$header);
+ buf.writeComponent(this.adventure$footer);
+ return;
+ }
+ // Paper end
buf.writeComponent(this.header);
buf.writeComponent(this.footer);
}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2022-03-01 06:43:03 +01:00
index 9d7d7a44616b2b7849c1abd3b9ac77305fdb0815..592b288c5ded992dc3fdf0db5ed0845884c5be93 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2021-11-23 12:27:39 +01:00
@@ -145,6 +145,7 @@ import net.minecraft.world.scores.Score;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.Team;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import org.bukkit.Bukkit;
import org.bukkit.Location;
2021-11-23 12:27:39 +01:00
import org.bukkit.WeatherType;
@@ -220,6 +221,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
public String displayName;
+ public net.kyori.adventure.text.Component adventure$displayName; // Paper
public Component listName;
public org.bukkit.Location compassTarget;
public int newExp = 0;
2021-11-23 12:27:39 +01:00
@@ -301,6 +303,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
// CraftBukkit start
this.displayName = this.getScoreboardName();
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
2021-06-11 21:23:46 +02:00
this.bukkitPickUpLoot = true;
2021-06-11 14:02:28 +02:00
this.maxHealthCache = this.getMaxHealth();
}
2021-11-23 12:27:39 +01:00
@@ -772,22 +775,17 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
2021-08-13 19:08:34 +02:00
String deathmessage = defaultMessage.getString();
this.keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
2021-06-11 14:02:28 +02:00
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, PaperAdventure.asAdventure(defaultMessage), defaultMessage.getString(), keepInventory); // Paper - Adventure
// SPIGOT-943 - only call if they have an inventory open
if (this.containerMenu != this.inventoryMenu) {
this.closeContainer();
}
- String deathMessage = event.getDeathMessage();
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
- if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
- Component ichatbasecomponent;
- if (deathMessage.equals(deathmessage)) {
- ichatbasecomponent = this.getCombatTracker().getDeathMessage();
- } else {
- ichatbasecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromStringOrNull(deathMessage);
- }
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
+ Component ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure
2021-11-23 12:27:39 +01:00
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getCombatTracker(), ichatbasecomponent), (future) -> {
2021-06-11 14:02:28 +02:00
if (!future.isSuccess()) {
2021-11-23 12:27:39 +01:00
@@ -1729,6 +1727,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
}
public String locale = "en_us"; // CraftBukkit - add, lowercase
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
public void updateOptions(ServerboundClientInformationPacket packet) {
// CraftBukkit start
2021-11-23 12:27:39 +01:00
if (getMainArm() != packet.mainHand()) {
@@ -1740,6 +1739,10 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
this.server.server.getPluginManager().callEvent(event);
}
this.locale = packet.language;
+ // Paper start
+ this.adventure$locale = net.kyori.adventure.translation.Translator.parseLocale(this.locale);
+ this.connection.connection.channel.attr(PaperAdventure.LOCALE_ATTRIBUTE).set(this.adventure$locale);
+ // Paper end
this.clientViewDistance = packet.viewDistance;
// CraftBukkit end
2021-11-23 12:27:39 +01:00
this.chatVisibility = packet.chatVisibility();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-03-01 06:43:03 +01:00
index 443124a72eef9f60e2941b932a13471dbf1c4f72..9b47d8ab57c3b290173247ba25ad7668f3529903 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2022-03-01 06:43:03 +01:00
@@ -155,6 +155,8 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
2021-06-11 14:02:28 +02:00
// CraftBukkit start
+import io.papermc.paper.adventure.ChatProcessor; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.util.concurrent.ExecutionException;
2021-06-11 21:23:46 +02:00
import java.util.concurrent.atomic.AtomicInteger;
2022-01-01 04:05:42 +01:00
import net.minecraft.world.entity.animal.Bucketable;
2022-03-01 06:43:03 +01:00
@@ -383,21 +385,24 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
return this.server.isSingleplayerOwner(this.player.getGameProfile());
}
- // CraftBukkit start
- @Deprecated
- public void disconnect(Component reason) {
2021-06-11 21:23:46 +02:00
- this.disconnect(CraftChatMessage.fromComponent(reason));
2021-06-11 14:02:28 +02:00
+ public void disconnect(String s) {
+ // Paper start
+ this.disconnect(PaperAdventure.LEGACY_SECTION_UXRC.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;
}
- 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, this.player.getBukkitEntity().displayName()); // Paper - Adventure
2021-06-20 21:25:59 +02:00
- PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), s, leaveMessage);
2021-06-11 21:23:46 +02:00
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), reason, leaveMessage); // Paper - Adventure
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
if (this.cserver.getServer().isRunning()) {
this.cserver.getPluginManager().callEvent(event);
2022-03-01 06:43:03 +01:00
@@ -408,8 +413,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
return;
}
// Send the possibly modified leave message
- s = event.getReason();
- final Component ichatbasecomponent = CraftChatMessage.fromString(s, true)[0];
+ final Component ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
// CraftBukkit end
this.connection.send(new ClientboundDisconnectPacket(ichatbasecomponent), (future) -> {
2022-03-01 06:43:03 +01:00
@@ -1684,9 +1688,11 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
*/
this.player.disconnect();
2021-11-23 12:27:39 +01:00
- String quitMessage = this.server.getPlayerList().remove(this.player);
2021-06-11 14:02:28 +02:00
- if ((quitMessage != null) && (quitMessage.length() > 0)) {
2021-11-23 12:27:39 +01:00
- this.server.getPlayerList().broadcastMessage(CraftChatMessage.fromString(quitMessage));
2021-06-11 14:02:28 +02:00
+ // Paper start - Adventure
2021-11-23 12:27:39 +01:00
+ net.kyori.adventure.text.Component quitMessage = this.server.getPlayerList().remove(this.player);
2021-06-11 14:02:28 +02:00
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
2021-06-11 21:23:46 +02:00
+ this.server.getPlayerList().broadcastMessage(PaperAdventure.asVanilla(quitMessage), ChatType.SYSTEM, Util.NIL_UUID);
2021-06-11 14:02:28 +02:00
+ // Paper end
}
// CraftBukkit end
2021-06-11 21:23:46 +02:00
this.player.getTextFilter().leave();
2022-03-01 06:43:03 +01:00
@@ -1868,7 +1874,12 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
this.handleCommand(s);
} else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) {
// Do nothing, this is coming from a plugin
- } else {
+ // Paper start
+ } else if (true) {
+ final ChatProcessor cp = new ChatProcessor(this.server, this.player, s, async);
+ cp.process();
2021-06-11 21:23:46 +02:00
+ // Paper end
2021-06-11 14:02:28 +02:00
+ } else if (false) { // Paper
2021-06-11 21:23:46 +02:00
Player player = this.getCraftPlayer();
AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(this.server));
this.cserver.getPluginManager().callEvent(event);
2022-03-01 06:43:03 +01:00
@@ -2667,30 +2678,30 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
2021-06-11 14:02:28 +02:00
return;
}
- // CraftBukkit start
+ // CraftBukkit start // Paper start - Adventure
2021-06-20 21:25:59 +02:00
Player player = this.player.getBukkitEntity();
2021-11-17 06:00:14 +01:00
int x = packet.getPos().getX();
int y = packet.getPos().getY();
int z = packet.getPos().getZ();
2021-06-11 21:23:46 +02:00
- String[] lines = new String[4];
2021-06-11 14:02:28 +02:00
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>();
2021-11-17 06:00:14 +01:00
for (int i = 0; i < signText.size(); ++i) {
- TextFilter.FilteredText itextfilter_a = (TextFilter.FilteredText) signText.get(i);
+ TextFilter.FilteredText currentLine = signText.get(i);
2021-06-11 21:23:46 +02:00
if (this.player.isTextFilteringEnabled()) {
- lines[i] = ChatFormatting.stripFormatting(new TextComponent(ChatFormatting.stripFormatting(itextfilter_a.getFiltered())).getString());
2021-11-17 06:00:14 +01:00
+ lines.add(net.kyori.adventure.text.Component.text(currentLine.getFiltered()));
2021-06-11 21:23:46 +02:00
} else {
- lines[i] = ChatFormatting.stripFormatting(new TextComponent(ChatFormatting.stripFormatting(itextfilter_a.getRaw())).getString());
2021-11-17 06:00:14 +01:00
+ lines.add(net.kyori.adventure.text.Component.text(currentLine.getRaw()));
2021-06-11 21:23:46 +02:00
}
2021-06-11 14:02:28 +02:00
}
2021-06-20 21:25:59 +02:00
SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.player.getBukkitEntity(), lines);
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
if (!event.isCancelled()) {
2021-06-11 21:23:46 +02:00
- Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
- for (int i = 0; i < components.length; i++) {
- tileentitysign.setMessage(i, components[i]);
2021-06-11 14:02:28 +02:00
+ for (int i = 0; i < 4; i++) {
+ tileentitysign.setMessage(i, PaperAdventure.asVanilla(event.line(i)));
2021-06-11 21:23:46 +02:00
}
2021-06-11 14:02:28 +02:00
+ // Paper end
tileentitysign.isEditable = false;
2021-06-11 21:23:46 +02:00
}
2021-06-11 14:02:28 +02:00
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2022-03-01 06:43:03 +01:00
index 2b9b60c0010069916dbecd22efdb9cec71180363..627931ec09bfb1a84f0659981491cf3b6425aa32 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2022-03-01 06:43:03 +01:00
@@ -323,7 +323,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
2021-06-11 14:02:28 +02:00
if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
- event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
+ event.disallow(asyncEvent.getResult(), asyncEvent.kickMessage()); // Paper - Adventure
}
Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
@Override
2022-03-01 06:43:03 +01:00
@@ -334,12 +334,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
2021-06-11 14:02:28 +02:00
ServerLoginPacketListenerImpl.this.server.processQueue.add(waitable);
if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
2021-06-11 21:23:46 +02:00
- ServerLoginPacketListenerImpl.this.disconnect(event.getKickMessage());
2022-03-01 06:43:03 +01:00
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
return;
}
} else {
if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
2021-06-11 21:23:46 +02:00
- ServerLoginPacketListenerImpl.this.disconnect(asyncEvent.getKickMessage());
2022-03-01 06:43:03 +01:00
+ ServerLoginPacketListenerImpl.this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
2021-06-11 14:02:28 +02:00
return;
}
}
diff --git a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
2021-11-24 02:09:49 +01:00
index c9a8d64ef23def0ad8e986a97c34331b8d54c205..2b24a41587fbe1fba70a0ab42d3dc33358f2ba2e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerStatusPacketListenerImpl.java
@@ -55,7 +55,7 @@ public class ServerStatusPacketListenerImpl implements ServerStatusPacketListene
CraftIconCache icon = server.server.getServerIcon();
ServerListPingEvent() {
2021-06-11 21:23:46 +02:00
- super(((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), ServerStatusPacketListenerImpl.this.server.getMotd(), ServerStatusPacketListenerImpl.this.server.getPlayerList().getMaxPlayers());
+ super(((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), ServerStatusPacketListenerImpl.this.server.server.getMotd(), ServerStatusPacketListenerImpl.this.server.getPlayerList().getMaxPlayers()); // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
@Override
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2022-03-01 06:43:03 +01:00
index 5fa0ce6a7f6b8df8993315a9784764f57d59bcf4..bfec1beb0af39e2af6be7c6423bf1eaab32e1062 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2022-03-01 06:43:03 +01:00
@@ -9,6 +9,7 @@ import com.mojang.logging.LogUtils;
2021-06-11 14:02:28 +02:00
import com.mojang.serialization.DataResult;
import com.mojang.serialization.Dynamic;
import io.netty.buffer.Unpooled;
+import io.papermc.paper.adventure.PaperAdventure;
import java.io.File;
import java.net.SocketAddress;
2021-07-07 08:52:40 +02:00
import java.nio.file.Path;
2022-03-01 06:43:03 +01:00
@@ -91,6 +92,7 @@ import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
2021-06-11 14:02:28 +02:00
// CraftBukkit start
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import com.google.common.base.Predicate;
2021-06-11 21:23:46 +02:00
import java.util.stream.Collectors;
2021-06-11 14:02:28 +02:00
import net.minecraft.server.dedicated.DedicatedServer;
2021-11-23 12:27:39 +01:00
@@ -259,7 +261,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// CraftBukkit start
chatmessage.withStyle(ChatFormatting.YELLOW);
- String joinMessage = CraftChatMessage.fromComponent(chatmessage);
+ Component joinMessage = chatmessage; // Paper - Adventure
2021-06-11 21:23:46 +02:00
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
2021-06-11 14:02:28 +02:00
this.players.add(player);
2021-11-23 12:27:39 +01:00
@@ -273,19 +275,18 @@ public abstract class PlayerList {
2021-06-20 21:25:59 +02:00
// Ensure that player inventory is populated with its viewer
player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
2021-06-11 14:02:28 +02:00
2021-06-20 21:25:59 +02:00
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, joinMessage);
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(playerJoinEvent);
2021-06-11 14:02:28 +02:00
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)) {
2021-06-11 21:23:46 +02:00
- this.server.getPlayerList().broadcastAll(new ClientboundChatPacket(line, ChatType.SYSTEM, Util.NIL_UUID));
2021-06-11 14:02:28 +02:00
- }
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
+ joinMessage = PaperAdventure.asVanilla(jm); // Paper - Adventure
2021-06-11 21:23:46 +02:00
+ this.server.getPlayerList().broadcastAll(new ClientboundChatPacket(joinMessage, ChatType.SYSTEM, Util.NIL_UUID)); // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
2021-11-23 12:27:39 +01:00
@@ -482,7 +483,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
2021-11-23 12:27:39 +01:00
- public String remove(ServerPlayer entityplayer) { // CraftBukkit - return string
+ public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // Paper - return Component
2021-06-11 14:02:28 +02:00
ServerLevel worldserver = entityplayer.getLevel();
entityplayer.awardStat(Stats.LEAVE_GAME);
2021-11-23 12:27:39 +01:00
@@ -493,7 +494,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
entityplayer.closeContainer();
}
2021-06-20 21:25:59 +02:00
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), "\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, com.destroystokyo.paper.PaperConfig.useDisplayNameInQuit ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getScoreboardName())));
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(playerQuitEvent);
2021-06-11 14:02:28 +02:00
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
2021-11-23 12:27:39 +01:00
@@ -546,7 +547,7 @@ public abstract class PlayerList {
2021-06-11 21:23:46 +02:00
this.cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
2021-06-11 14:02:28 +02:00
// CraftBukkit end
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
}
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
2021-11-23 12:27:39 +01:00
@@ -592,10 +593,10 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// return chatmessage;
2021-06-20 21:25:59 +02:00
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
2021-06-11 14:02:28 +02:00
} else if (!this.isWhiteListed(gameprofile)) {
chatmessage = new TranslatableComponent("multiplayer.disconnect.not_whitelisted");
- event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, PaperAdventure.LEGACY_SECTION_UXRC.deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure
2021-06-11 21:23:46 +02:00
} else if (this.getIpBans().isBanned(socketaddress) && !this.getIpBans().get(socketaddress).hasExpired()) {
2021-06-11 14:02:28 +02:00
IpBanListEntry ipbanentry = this.ipBans.get(socketaddress);
2021-11-23 12:27:39 +01:00
@@ -605,17 +606,17 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
// return chatmessage;
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
} else {
2021-11-23 12:27:39 +01:00
// return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full") : null;
2021-06-11 14:02:28 +02:00
if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
- event.disallow(PlayerLoginEvent.Result.KICK_FULL, org.spigotmc.SpigotConfig.serverFullMessage); // Spigot
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, PaperAdventure.LEGACY_SECTION_UXRC.deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
}
}
2021-06-11 21:23:46 +02:00
this.cserver.getPluginManager().callEvent(event);
2021-06-11 14:02:28 +02:00
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
- loginlistener.disconnect(event.getKickMessage());
+ loginlistener.disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
return null;
}
return entity;
2021-11-23 12:27:39 +01:00
@@ -1124,7 +1125,7 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
public void removeAll() {
// CraftBukkit start - disconnect safely
for (ServerPlayer player : this.players) {
- player.connection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
+ player.connection.disconnect(this.server.server.shutdownMessage()); // CraftBukkit - add custom shutdown message // Paper - Adventure
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/BossEvent.java b/src/main/java/net/minecraft/world/BossEvent.java
2022-03-01 06:43:03 +01:00
index 4c62df5a3781ec9df4a5c5f1b528649e6e8a62d1..affd1b8c7589ba59330dc0b6fc803cce4ee57397 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/BossEvent.java
+++ b/src/main/java/net/minecraft/world/BossEvent.java
2021-07-04 01:26:13 +02:00
@@ -13,6 +13,7 @@ public abstract class BossEvent {
2021-06-11 14:02:28 +02:00
protected boolean darkenScreen;
protected boolean playBossMusic;
protected boolean createWorldFog;
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
public BossEvent(UUID uuid, Component name, BossEvent.BossBarColor color, BossEvent.BossBarOverlay style) {
this.id = uuid;
2021-07-04 01:26:13 +02:00
@@ -27,61 +28,75 @@ public abstract class BossEvent {
}
public Component getName() {
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.name()); // Paper
return this.name;
}
public void setName(Component name) {
+ if (this.adventure != null) this.adventure.name(io.papermc.paper.adventure.PaperAdventure.asAdventure(name)); // Paper
this.name = name;
}
public float getProgress() {
+ if (this.adventure != null) return this.adventure.progress(); // Paper
return this.progress;
}
2022-03-01 06:43:03 +01:00
public void setProgress(float percent) {
+ if (this.adventure != null) this.adventure.progress(percent); // Paper
this.progress = percent;
2021-07-04 01:26:13 +02:00
}
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;
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
2022-03-01 06:43:03 +01:00
index 595b56b2ab9a813ba71399d306117294fa90dc65..3527d40102d512d0e276edc969ea3c189aa34ec2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
+++ b/src/main/java/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
2022-03-01 06:43:03 +01:00
@@ -33,6 +33,7 @@ import net.minecraft.world.level.saveddata.SavedData;
import org.slf4j.Logger;
2021-06-11 14:02:28 +02:00
// CraftBukkit start
+import io.papermc.paper.adventure.PaperAdventure; // Paper
import java.util.UUID;
2021-06-11 21:23:46 +02:00
import org.bukkit.Bukkit;
2021-11-23 12:27:39 +01:00
import org.bukkit.craftbukkit.CraftServer;
@@ -598,7 +599,7 @@ public class MapItemSavedData extends SavedData {
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
for (org.bukkit.map.MapCursor cursor : render.cursors) {
if (cursor.isVisible()) {
- icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
+ icons.add(new MapDecoration(MapDecoration.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), PaperAdventure.asVanilla(cursor.caption()))); // Paper - Adventure
}
2021-06-11 14:02:28 +02:00
}
2021-06-11 21:23:46 +02:00
collection = icons;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-03-01 06:43:03 +01:00
index 1fe657645c118bc381aeeda0265893a3d4644025..e577c2fb100c217faeaf2d85d6a4374d6de047e1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2022-03-01 06:43:03 +01:00
@@ -619,8 +619,10 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
@Override
+ @Deprecated // Paper start
public int broadcastMessage(String message) {
2021-06-11 21:23:46 +02:00
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
2021-06-11 14:02:28 +02:00
+ // Paper end
}
2021-06-20 21:25:59 +02:00
@Override
2022-03-01 06:43:03 +01:00
@@ -1449,7 +1451,15 @@ public final class CraftServer implements Server {
2021-06-11 21:23:46 +02:00
return this.configuration.getInt("settings.spawn-radius", -1);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
@Override
+ public net.kyori.adventure.text.Component shutdownMessage() {
+ String msg = getShutdownMessage();
+ return msg != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(msg) : null;
+ }
+ // Paper end
+ @Override
+ @Deprecated // Paper
public String getShutdownMessage() {
2021-06-11 21:23:46 +02:00
return this.configuration.getString("settings.shutdown-message");
2021-06-11 14:02:28 +02:00
}
2022-03-01 06:43:03 +01:00
@@ -1607,7 +1617,20 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
@Override
+ @Deprecated // Paper
public int broadcast(String message, String permission) {
+ // Paper start - Adventure
+ return this.broadcast(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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<>();
2021-06-11 21:23:46 +02:00
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
2021-06-11 14:02:28 +02:00
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
2022-03-01 06:43:03 +01:00
@@ -1615,14 +1638,14 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
}
}
- BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.getPluginManager().callEvent(broadcastMessageEvent);
2021-06-11 14:02:28 +02:00
if (broadcastMessageEvent.isCancelled()) {
return 0;
}
- message = broadcastMessageEvent.getMessage();
+ message = broadcastMessageEvent.message(); // Paper - Adventure
for (CommandSender recipient : recipients) {
recipient.sendMessage(message);
2022-03-01 06:43:03 +01:00
@@ -1873,6 +1896,14 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ 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);
2022-03-01 06:43:03 +01:00
@@ -1885,13 +1916,28 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
+ 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);
}
2022-03-01 06:43:03 +01:00
@@ -1951,6 +1997,12 @@ public final class CraftServer implements Server {
2021-06-11 21:23:46 +02:00
return Thread.currentThread().equals(console.serverThread) || this.console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component motd() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(new net.minecraft.network.chat.TextComponent(console.getMotd()));
+ }
+ // Paper end
@Override
public String getMotd() {
2021-06-11 21:23:46 +02:00
return this.console.getMotd();
2022-03-01 06:43:03 +01:00
@@ -2394,5 +2446,15 @@ public final class CraftServer implements Server {
2021-06-11 14:02:28 +02:00
return null;
}
}
+
+ // Paper start
+ private Iterable<? extends net.kyori.adventure.audience.Audience> adventure$audiences;
+ @Override
+ public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
+ if (this.adventure$audiences == null) {
+ this.adventure$audiences = com.google.common.collect.Iterables.concat(java.util.Collections.singleton(this.getConsoleSender()), this.getOnlinePlayers());
+ }
+ return this.adventure$audiences;
+ }
// Paper end
}
2021-09-23 23:07:44 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2022-03-01 06:43:03 +01:00
index 794ed40db102370338ee227ffa4e1801fd741284..5963fa56e7dcd61336a14fa1035c6c14143989ad 100644
2021-09-23 23:07:44 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2022-03-01 06:43:03 +01:00
@@ -142,6 +142,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2022-02-12 14:20:33 +01:00
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
2022-02-15 11:30:58 +01:00
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY);
2021-09-23 23:07:44 +02:00
+ private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
private static final Random rand = new Random();
2022-03-01 06:43:03 +01:00
@@ -1862,4 +1863,18 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2021-09-23 23:07:44 +02:00
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
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java
2022-03-01 06:43:03 +01:00
index cf85183a4026fca981fcb44896d7210b5fc31c2f..7e5fc58f43836edab3696b9644264434c5a95a2f 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/Main.java
+++ b/src/main/java/org/bukkit/craftbukkit/Main.java
2021-12-10 15:24:07 +01:00
@@ -19,6 +19,12 @@ public class Main {
public static boolean useConsole = true;
2021-12-09 21:59:59 +01:00
2021-12-10 15:24:07 +01:00
public static void main(String[] args) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");
+ if (false && System.getProperty(warnWhenLegacyFormattingDetected) == null) {
+ System.setProperty(warnWhenLegacyFormattingDetected, String.valueOf(true));
+ }
+ // Paper end
// Todo: Installation script
OptionParser parser = new OptionParser() {
{
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
2021-10-17 18:57:00 +02:00
index 9d55f36f146435f0cfb4e62ffa7c94eab404a596..c186a44b927188ed222f8b2f8f76aaef35d9c654 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
2021-10-02 19:21:49 +02:00
@@ -68,6 +68,19 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
2021-06-11 14:02:28 +02:00
this.getSnapshot().secondaryPower = (effect != null) ? MobEffect.byId(effect.getId()) : null;
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final BeaconBlockEntity be = this.getSnapshot();
+ return be.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.name) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
BeaconBlockEntity beacon = this.getSnapshot();
2021-09-30 23:28:02 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
2021-10-02 19:21:49 +02:00
index 02fc6b189541fdedd0acef6700722eb7e53346c4..5df1e8c7277759bda57253db449907eb1185cce3 100644
2021-09-30 23:28:02 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java
2021-10-02 19:21:49 +02:00
@@ -30,4 +30,16 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
2021-09-30 23:28:02 +02:00
public void setName(String name) {
getSnapshot().getCommandBlock().setName(CraftChatMessage.fromStringOrNull(name != null ? name : "@"));
}
+
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getSnapshot().getCommandBlock().getName());
+ }
+
+ @Override
+ public void name(net.kyori.adventure.text.Component name) {
+ getSnapshot().getCommandBlock().setName(name == null ? new net.minecraft.network.chat.TextComponent("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
2021-10-02 19:21:49 +02:00
index 05f37f306d623280823c7cf9516027189659f902..65104a0506131373b6b33433a118c7e1cd3696dc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
2021-10-02 19:21:49 +02:00
@@ -27,6 +27,19 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
2021-06-11 14:02:28 +02:00
this.getSnapshot().lockKey = (key == null) ? LockCode.NO_LOCK : new LockCode(key);
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final T be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
T container = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
2021-10-02 19:21:49 +02:00
index 0beb96dc896f63003e1b1ae458b73902bdbe648a..102eb86bad3000f258775ac06ecd1a6dad174b0a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
2021-10-02 19:21:49 +02:00
@@ -11,6 +11,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantmentTable
super(world, tileEntity);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final EnchantmentTableBlockEntity be = this.getSnapshot();
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
+ // Paper end
+
@Override
public String getCustomName() {
EnchantmentTableBlockEntity enchant = this.getSnapshot();
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
2022-01-03 10:17:27 +01:00
index 9e68893b189ad05e4d2a5e8788e93e10670ac824..9d513b3a1a50e67284ee7ebdc5607e4f44bd0a4b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
2021-12-05 08:11:59 +01:00
@@ -14,34 +14,60 @@ import org.bukkit.entity.Player;
2021-06-11 14:02:28 +02:00
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
2021-10-02 19:21:49 +02:00
public CraftSign(World world, SignBlockEntity tileEntity) {
super(world, tileEntity);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
@Override
- public String[] getLines() {
2021-06-11 21:23:46 +02:00
- if (this.lines == null) {
2021-06-11 14:02:28 +02:00
- // Lazy initialization:
- SignBlockEntity sign = this.getSnapshot();
2021-06-11 21:23:46 +02:00
- this.lines = new String[sign.messages.length];
- System.arraycopy(CraftSign.revertComponents(sign.messages), 0, lines, 0, lines.length);
- this.originalLines = new String[lines.length];
2021-06-11 14:02:28 +02:00
- System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
2021-06-11 21:23:46 +02:00
- }
2021-06-11 14:02:28 +02:00
+ public java.util.List<net.kyori.adventure.text.Component> lines() {
+ this.loadLines();
2021-06-11 21:23:46 +02:00
return this.lines;
}
2021-06-11 14:02:28 +02:00
+ @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;
2021-06-11 21:23:46 +02:00
+ }
2021-06-11 14:02:28 +02:00
+ // 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(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::serialize).toArray(String[]::new); // Paper
2021-06-11 21:23:46 +02:00
+ }
+
2021-06-11 14:02:28 +02:00
@Override
public String getLine(int index) throws IndexOutOfBoundsException {
2021-06-11 21:23:46 +02:00
- return this.getLines()[index];
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ return io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(this.lines.get(index)); // Paper
}
@Override
public void setLine(int index, String line) throws IndexOutOfBoundsException {
2021-06-11 21:23:46 +02:00
- this.getLines()[index] = line;
2021-06-11 14:02:28 +02:00
+ this.loadLines();
+ this.lines.set(index, line != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(line) : net.kyori.adventure.text.Component.empty()); // Paper
}
@Override
2021-12-05 08:11:59 +01:00
@@ -79,13 +105,16 @@ public class CraftSign extends CraftBlockEntityState<SignBlockEntity> implements
2021-06-11 14:02:28 +02:00
super.applyTo(sign);
2021-06-11 21:23:46 +02:00
if (this.lines != null) {
2021-06-11 14:02:28 +02:00
- for (int i = 0; i < lines.length; i++) {
2021-06-11 21:23:46 +02:00
- String line = (this.lines[i] == null) ? "" : this.lines[i];
- if (line.equals(this.originalLines[i])) {
2021-06-11 14:02:28 +02:00
+ // Paper start
+ for (int i = 0; i < this.lines.size(); ++i) {
+ net.kyori.adventure.text.Component component = this.lines.get(i);
+ net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
+ if (component.equals(origComp)) {
continue; // The line contents are still the same, skip.
}
2021-06-11 21:23:46 +02:00
- sign.setMessage(i, CraftChatMessage.fromString(line)[0]);
2022-01-03 10:17:27 +01:00
+ sign.setMessage(i, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
2021-06-11 14:02:28 +02:00
}
+ // Paper end
}
}
2021-12-05 08:11:59 +01:00
@@ -100,6 +129,20 @@ public class CraftSign extends CraftBlockEntityState<SignBlockEntity> implements
((CraftPlayer) player).getHandle().openTextEdit(handle);
}
2021-06-11 14:02:28 +02:00
+ // 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] = new TextComponent("");
+ }
+ }
+ return components;
+ }
+ // Paper end
2021-12-05 08:11:59 +01:00
+
2021-06-11 14:02:28 +02:00
public static Component[] sanitizeLines(String[] lines) {
Component[] components = new Component[4];
2021-09-22 20:34:40 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
index 83efca7144b4ce9cf7bd6bbbbf9c4426d2472315..bf4c5c83c3c6d710c9c40257087a2c744a7d00c6 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftBlockCommandSender.java
@@ -46,6 +46,13 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
return this.block.getTextName();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
2021-09-22 20:34:40 +02:00
index f3cb4102ab223f379f60dac317df7da1fab812a8..269738c499c6aab6f8c39ba4ffd12fa09f0d79dc 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
2021-09-22 20:34:40 +02:00
@@ -46,6 +46,13 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
return "CONSOLE";
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return net.kyori.adventure.text.Component.text(this.getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
@@ -80,4 +87,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
2021-06-11 14:02:28 +02:00
public boolean isConversing() {
2021-06-11 21:23:46 +02:00
return this.conversationTracker.isConversing();
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
2021-08-03 09:48:34 +02:00
+ this.sendRawMessage(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(message));
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
2021-09-22 20:34:40 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
index 02a8c522a25f1c3c8eb0245560757772e627d31e..07f7effaa46afdd8766e3e6bfd8cb923e55f68cf 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftRemoteConsoleCommandSender.java
@@ -30,6 +30,13 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
return "Rcon";
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return net.kyori.adventure.text.Component.text(this.getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
index 53d6950ad270ba901de5226b9daecb683248ad05..3e7d14564f11a3ed0b0766444e9d681804597e9a 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java
@@ -67,6 +67,13 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
return this.getCallee().getName();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component name() {
+ return this.getCallee().name();
+ }
+ // Paper end
+
@Override
public boolean isPermissionSet(String name) {
return this.getCaller().isPermissionSet(name);
2021-09-23 23:07:44 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
index 8107ed0d248ff2a1cf8e556b7610a68f6c197691..eaff8df6c8c12c64e005a68a02e2e35ed88f757c 100644
--- a/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
+++ b/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java
@@ -14,6 +14,7 @@ import org.bukkit.plugin.Plugin;
public abstract class ServerCommandSender implements CommandSender {
private static PermissibleBase blockPermInst;
private final PermissibleBase perm;
+ private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
public ServerCommandSender() {
if (this instanceof CraftBlockCommandSender) {
@@ -134,4 +135,18 @@ public abstract class ServerCommandSender implements CommandSender {
return this.spigot;
}
// Spigot end
+
+ // Paper start - implement pointers
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
2021-06-17 21:37:37 +02:00
index cf69a45f038c2b8336010f5fe277313fd0513b5b..eb99e0c2462a2d1ab4508a5c3f1580b6e31d7465 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
+++ b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
@@ -187,6 +187,12 @@ public class CraftEnchantment extends Enchantment {
CraftEnchantment ench = (CraftEnchantment) other;
2021-06-11 21:23:46 +02:00
return !this.target.isCompatibleWith(ench.target);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName(int level) {
2021-06-17 21:37:37 +02:00
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
2021-06-11 21:23:46 +02:00
return this.target;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2022-02-12 14:20:33 +01:00
index a4907dee676e9e9cc2725a3312831198a0db7b10..4b7ed15279bbdd116d993f190094f80c888aed69 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
2022-02-12 14:20:33 +01:00
@@ -191,6 +191,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-09-23 23:07:44 +02:00
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;
2022-02-12 14:20:33 +01:00
@@ -818,6 +819,32 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-06-11 21:23:46 +02:00
return this.getHandle().getVehicle().getBukkitEntity();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component customName() {
+ final Component name = this.getHandle().getCustomName();
+ return name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(name) : null;
+ }
+
+ @Override
+ public void customName(final net.kyori.adventure.text.Component customName) {
+ this.getHandle().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
+ }
2021-09-23 23:07:44 +02:00
+
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
+
@Override
public void setCustomName(String name) {
// sane limit for name length
2022-02-12 14:20:33 +01:00
@@ -873,6 +900,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
2021-09-22 20:34:40 +02:00
public String getName() {
return CraftChatMessage.fromComponent(this.getHandle().getName());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getName());
+ }
+
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getDisplayName());
+ }
+ // Paper end
@Override
public boolean isPermissionSet(String name) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
2022-02-01 00:56:54 +01:00
index b4d3f6358b8a762d44586fbded8844ba5485f2d0..ebd5372fdd7aa3e5e67a8b3b916176eeb6ff54bf 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -317,9 +317,12 @@ 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 = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(container.getBukkitView().getTitle()); // Paper
- player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
+ player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
2021-06-11 21:23:46 +02:00
player.containerMenu = container;
player.initMenu(container);
2021-06-11 14:02:28 +02:00
}
@@ -388,8 +391,12 @@ 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 = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(inventory.getTitle()); // Paper
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, 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;
2021-06-11 21:23:46 +02:00
player.initMenu(container);
2021-06-11 14:02:28 +02:00
}
2021-09-22 20:34:40 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
index 446fdca49a5a6999626a7ee3a1d5c168b15a09dd..f9863e138994f6c7a7975a852f106faa96d52315 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java
@@ -65,6 +65,13 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca
return CraftChatMessage.fromComponent(this.getHandle().getCommandBlock().getName());
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getCommandBlock().getName());
+ }
+ // Paper end
+
@Override
public boolean isOp() {
return true;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2022-02-12 14:20:33 +01:00
index 74db150aed0744d62779e00cad8bfa25cede76ab..3710423e2181533056bb87c40e129eb5d17a9afd 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2022-02-12 14:20:33 +01:00
@@ -262,14 +262,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
@Override
public String getDisplayName() {
+ if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
2021-06-11 21:23:46 +02:00
return this.getHandle().displayName;
2021-06-11 14:02:28 +02:00
}
@Override
public void setDisplayName(final String name) {
+ this.getHandle().adventure$displayName = name != null ? io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(name) : net.kyori.adventure.text.Component.text(this.getName()); // Paper
2021-06-11 21:23:46 +02:00
this.getHandle().displayName = name == null ? getName() : name;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public void playerListName(net.kyori.adventure.text.Component name) {
+ getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
+ for (ServerPlayer player : server.getHandle().players) {
+ if (player.getBukkitEntity().canSee(this)) {
+ player.connection.send(new 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() {
2021-06-11 21:23:46 +02:00
return this.getHandle().listName == null ? getName() : CraftChatMessage.fromComponent(this.getHandle().listName);
2022-02-12 14:20:33 +01:00
@@ -288,42 +313,42 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
}
- private Component playerListHeader;
- private Component playerListFooter;
+ private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
+ private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
@Override
public String getPlayerListHeader() {
2021-06-11 21:23:46 +02:00
- return (this.playerListHeader == null) ? null : CraftChatMessage.fromComponent(playerListHeader);
+ return (this.playerListHeader == null) ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(playerListHeader);
2021-06-11 14:02:28 +02:00
}
@Override
public String getPlayerListFooter() {
2021-06-11 21:23:46 +02:00
- return (this.playerListFooter == null) ? null : CraftChatMessage.fromComponent(playerListFooter);
+ return (this.playerListFooter == null) ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(playerListFooter); // Paper - Adventure
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListHeader(String header) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
+ this.playerListHeader = header == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(header); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListFooter(String footer) {
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListFooter = footer == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(footer); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
@Override
public void setPlayerListHeaderFooter(String header, String footer) {
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
+ this.playerListHeader = header == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(header); // Paper - Adventure
+ this.playerListFooter = footer == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(footer); // Paper - Adventure
2021-06-11 21:23:46 +02:00
this.updatePlayerListHeaderFooter();
2021-06-11 14:02:28 +02:00
}
2021-06-11 21:23:46 +02:00
private void updatePlayerListHeaderFooter() {
if (this.getHandle().connection == null) return;
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
- ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? new TextComponent("") : this.playerListHeader, (this.playerListFooter == null) ? new TextComponent("") : this.playerListFooter);
+ ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? new TextComponent("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListHeader), (this.playerListFooter == null) ? new TextComponent("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListFooter));
this.getHandle().connection.send(packet);
2021-06-11 14:02:28 +02:00
}
2022-02-12 14:20:33 +01:00
@@ -355,6 +380,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
this.getHandle().connection.disconnect(message == null ? "" : message);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @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) {
2021-06-11 21:23:46 +02:00
if (this.getHandle().connection == null) return;
2022-02-12 14:20:33 +01:00
@@ -610,6 +646,33 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
this.getHandle().connection.send(packet);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
2021-08-05 21:53:50 +02:00
+ public void sendSignChange(Location loc, @Nullable List<net.kyori.adventure.text.Component> lines, DyeColor dyeColor, boolean hasGlowingText) {
2021-06-11 14:02:28 +02:00
+ if (getHandle().connection == null) {
+ return;
+ }
+ if (lines == null) {
+ lines = new java.util.ArrayList<>(4);
+ }
+ 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);
2021-08-05 21:53:50 +02:00
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
2021-06-11 14:02:28 +02:00
+ }
+
2021-08-05 21:53:50 +02:00
+ private void sendSignChange0(Component[] components, Location loc, DyeColor dyeColor, boolean hasGlowingText) {
2021-06-11 21:23:46 +02:00
+ SignBlockEntity sign = new SignBlockEntity(new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Blocks.OAK_SIGN.defaultBlockState());
2021-06-11 14:02:28 +02:00
+ sign.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
2021-08-05 21:53:50 +02:00
+ sign.setHasGlowingText(hasGlowingText);
2021-06-11 14:02:28 +02:00
+ System.arraycopy(components, 0, sign.messages, 0, sign.messages.length);
+
+ getHandle().connection.send(sign.getUpdatePacket());
+ }
+ // Paper end
@Override
public void sendSignChange(Location loc, String[] lines) {
2021-08-05 21:53:50 +02:00
this.sendSignChange(loc, lines, DyeColor.BLACK);
2022-02-12 14:20:33 +01:00
@@ -637,14 +700,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
Component[] components = CraftSign.sanitizeLines(lines);
2021-06-11 21:23:46 +02:00
- 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());
2021-08-05 21:53:50 +02:00
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]);
}
2021-06-11 14:02:28 +02:00
2021-06-11 21:23:46 +02:00
- this.getHandle().connection.send(sign.getUpdatePacket());
+ this.getHandle().connection.send(sign.getUpdatePacket());*/ // Paper
2021-08-05 21:53:50 +02:00
+ this.sendSignChange0(components, loc, dyeColor, hasGlowingText); // Paper
2021-06-11 14:02:28 +02:00
}
@Override
2022-02-12 14:20:33 +01:00
@@ -1339,7 +1403,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-12-22 08:07:17 +01:00
@Override
public void setResourcePack(String url) {
- this.setResourcePack(url, null);
+ this.setResourcePack(url, (byte[]) null);
}
@Override
2022-02-12 14:20:33 +01:00
@@ -1354,7 +1418,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-12-22 08:07:17 +01:00
@Override
public void setResourcePack(String url, byte[] hash, boolean force) {
- this.setResourcePack(url, hash, null, force);
+ this.setResourcePack(url, hash, (String) null, force);
}
@Override
2022-02-12 14:20:33 +01:00
@@ -1370,6 +1434,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-12-22 08:07:17 +01:00
}
}
+ // 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);
2022-02-12 14:20:33 +01:00
@@ -1774,6 +1853,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 21:23:46 +02:00
return (this.getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : this.getHandle().clientViewDistance;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public java.util.Locale locale() {
+ return getHandle().adventure$locale;
+ }
+ // Paper end
@Override
public int getPing() {
2021-06-11 21:23:46 +02:00
return this.getHandle().latency;
2022-02-12 14:20:33 +01:00
@@ -1819,6 +1904,194 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-11-23 12:27:39 +01:00
return this.getHandle().allowsListing();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return this.getHandle().adventure$displayName;
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName());
+ this.getHandle().displayName = null;
+ }
+
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
2021-06-29 23:21:42 +02:00
+ if (getHandle().connection == null) return;
2021-06-11 14:02:28 +02:00
+ final ClientboundChatPacket packet = new ClientboundChatPacket(null, type == net.kyori.adventure.audience.MessageType.CHAT ? net.minecraft.network.chat.ChatType.CHAT : net.minecraft.network.chat.ChatType.SYSTEM, identity.uuid());
+ packet.adventure$message = message;
+ this.getHandle().connection.send(packet);
+ }
+
+ @Override
+ public void sendActionBar(final net.kyori.adventure.text.Component message) {
2021-06-16 01:41:38 +02:00
+ final net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket((net.minecraft.network.chat.Component) null);
+ packet.adventure$text = message;
2021-06-11 14:02:28 +02:00
+ this.getHandle().connection.send(packet);
+ }
+
+ @Override
+ public void sendPlayerListHeader(final net.kyori.adventure.text.Component header) {
+ this.playerListHeader = header;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListFooter(final net.kyori.adventure.text.Component footer) {
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ @Override
+ public void sendPlayerListHeaderAndFooter(final net.kyori.adventure.text.Component header, final net.kyori.adventure.text.Component footer) {
+ this.playerListHeader = header;
+ this.playerListFooter = footer;
+ this.adventure$sendPlayerListHeaderAndFooter();
+ }
+
+ private void adventure$sendPlayerListHeaderAndFooter() {
+ final ServerGamePacketListenerImpl connection = this.getHandle().connection;
+ if (connection == null) return;
2021-06-16 01:41:38 +02:00
+ final ClientboundTabListPacket packet = new ClientboundTabListPacket(null, null);
+ packet.adventure$header = (this.playerListHeader == null) ? net.kyori.adventure.text.Component.empty() : this.playerListHeader;
+ packet.adventure$footer = (this.playerListFooter == null) ? net.kyori.adventure.text.Component.empty() : this.playerListFooter;
2021-06-11 14:02:28 +02:00
+ connection.send(packet);
+ }
+
+ @Override
+ public void showTitle(final net.kyori.adventure.title.Title title) {
+ final ServerGamePacketListenerImpl connection = this.getHandle().connection;
+ final net.kyori.adventure.title.Title.Times times = title.times();
+ if (times != null) {
2021-06-11 21:23:46 +02:00
+ connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
2021-06-11 14:02:28 +02:00
+ }
2021-06-16 01:41:38 +02:00
+ final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
+ sp.adventure$text = title.subtitle();
2021-06-11 14:02:28 +02:00
+ connection.send(sp);
2021-06-16 01:41:38 +02:00
+ final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
+ tp.adventure$text = title.title();
2021-06-11 14:02:28 +02:00
+ connection.send(tp);
+ }
+
2021-09-23 23:07:44 +02:00
+ @Override
+ public <T> void sendTitlePart(final net.kyori.adventure.title.TitlePart<T> part, T value) {
+ java.util.Objects.requireNonNull(part, "part");
+ java.util.Objects.requireNonNull(value, "value");
+ if (part == net.kyori.adventure.title.TitlePart.TITLE) {
+ final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
+ tp.adventure$text = (net.kyori.adventure.text.Component) value;
+ this.getHandle().connection.send(tp);
+ } else if (part == net.kyori.adventure.title.TitlePart.SUBTITLE) {
+ final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
+ sp.adventure$text = (net.kyori.adventure.text.Component) value;
+ this.getHandle().connection.send(sp);
+ } else if (part == net.kyori.adventure.title.TitlePart.TIMES) {
+ final net.kyori.adventure.title.Title.Times times = (net.kyori.adventure.title.Title.Times) value;
+ this.getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
+ } else {
+ throw new IllegalArgumentException("Unknown TitlePart");
+ }
+ }
+
2021-06-11 14:02:28 +02:00
+ private static int ticks(final java.time.Duration duration) {
+ if (duration == null) {
+ return -1;
+ }
+ return (int) (duration.toMillis() / 50L);
+ }
+
+ @Override
+ public void clearTitle() {
2021-06-11 21:23:46 +02:00
+ this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundClearTitlesPacket(false));
2021-06-11 14:02:28 +02:00
+ }
+
+ // resetTitle implemented above
+
+ @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()));
+ } 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()));
+ }
+ }
+
+ @Override
2021-06-17 00:57:49 +02:00
+ public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
+ final Entity entity;
+ if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
+ entity = this.getHandle();
+ } else if (emitter instanceof 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()));
2021-06-17 19:11:00 +02:00
+ } else {
+ this.getHandle().connection.send(new ClientboundCustomSoundPacket(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), entity.position(), sound.volume(), sound.pitch()));
2021-06-17 00:57:49 +02:00
+ }
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
+ this.getHandle().connection.send(new ClientboundStopSoundPacket(
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.sound()),
+ io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.source())
+ ));
+ }
+
+ @Override
+ public void openBook(final net.kyori.adventure.inventory.Book book) {
+ final java.util.Locale locale = this.getHandle().adventure$locale;
+ final net.minecraft.world.item.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
+ final ServerPlayer player = this.getHandle();
+ final ServerGamePacketListenerImpl connection = player.connection;
2021-06-11 21:23:46 +02:00
+ final net.minecraft.world.entity.player.Inventory inventory = player.getInventory();
2021-06-11 14:02:28 +02:00
+ final int slot = inventory.items.size() + inventory.selected;
2021-07-07 08:52:40 +02:00
+ final int stateId = getHandle().containerMenu.getStateId();
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, item));
2021-06-11 14:02:28 +02:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundOpenBookPacket(net.minecraft.world.InteractionHand.MAIN_HAND));
2021-07-07 08:52:40 +02:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, inventory.getSelected()));
2021-06-11 14:02:28 +02:00
+ }
2021-09-23 23:07:44 +02:00
+
+ @Override
+ public net.kyori.adventure.pointer.Pointers pointers() {
+ if (this.adventure$pointers == null) {
+ this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
+ .withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::displayName)
+ .withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
+ .withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
+ .withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
+ .withDynamic(net.kyori.adventure.identity.Identity.LOCALE, this::locale)
+ .build();
+ }
+
+ return this.adventure$pointers;
+ }
2021-06-11 14:02:28 +02:00
+ // Paper end
// Spigot start
private final Player.Spigot spigot = new Player.Spigot()
{
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2022-02-12 14:20:33 +01:00
index 4b0a056a134dd5868438bdd0d46f3dab8751436d..2a3853201a6ccf14b2aab67982de7789e0cbc552 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2022-02-12 14:20:33 +01:00
@@ -817,9 +817,9 @@ public class CraftEventFactory {
2021-06-11 14:02:28 +02:00
return event;
}
- public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
+ public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, String stringDeathMessage, boolean keepInventory) { // Paper - Adventure
CraftPlayer entity = victim.getBukkitEntity();
- PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage, stringDeathMessage); // Paper - Adventure
event.setKeepInventory(keepInventory);
2021-08-13 19:08:34 +02:00
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
2021-06-11 14:02:28 +02:00
org.bukkit.World world = entity.getWorld();
2022-02-12 14:20:33 +01:00
@@ -844,7 +844,7 @@ public class CraftEventFactory {
2021-06-11 14:02:28 +02:00
* Server methods
*/
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
- ServerListPingEvent event = new ServerListPingEvent(address, motd, numPlayers, maxPlayers);
+ ServerListPingEvent event = new ServerListPingEvent(address, craftServer.motd(), numPlayers, maxPlayers); // Paper - Adventure
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
2021-11-05 15:08:24 +01:00
index af9facfaa8bba614e37bd604ca0656a852d0325b..60fa587ce17e138d2baf8959c26e25ed1db17a4a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
2021-06-11 21:23:46 +02:00
@@ -69,6 +69,13 @@ public class CraftContainer extends AbstractContainerMenu {
2021-06-11 14:02:28 +02:00
return inventory.getType();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).title() : net.kyori.adventure.text.Component.text(inventory.getType().getDefaultTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
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
2021-06-12 00:37:16 +02:00
index 6486a76466691f958349a4706d7c9caff9cb8f64..08fc05836b26f5f93ae74324705d5f593b57315a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
@@ -19,6 +19,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, type));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, type, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, String title) {
super(new MinecraftInventory(owner, type, title));
}
@@ -27,6 +33,12 @@ public class CraftInventoryCustom extends CraftInventory {
super(new MinecraftInventory(owner, size));
}
+ // Paper start
+ public CraftInventoryCustom(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ super(new MinecraftInventory(owner, size, title));
+ }
+ // Paper end
+
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
super(new MinecraftInventory(owner, size, title));
}
@@ -36,9 +48,17 @@ public class CraftInventoryCustom extends CraftInventory {
private int maxStack = MAX_STACK;
private final List<HumanEntity> viewers;
private final String title;
+ private final net.kyori.adventure.text.Component adventure$title; // Paper
private InventoryType type;
private final InventoryHolder owner;
+ // Paper start
+ public MinecraftInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ this(owner, type.getDefaultSize(), title);
+ this.type = type;
+ }
+ // Paper end
+
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
this(owner, type.getDefaultSize(), type.getDefaultTitle());
this.type = type;
@@ -57,11 +77,24 @@ public class CraftInventoryCustom extends CraftInventory {
Validate.notNull(title, "Title cannot be null");
2021-06-11 21:23:46 +02:00
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
2021-06-11 14:02:28 +02:00
this.title = title;
+ this.adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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");
2021-06-12 00:37:16 +02:00
+ this.items = NonNullList.withSize(size, ItemStack.EMPTY);
2021-06-11 14:02:28 +02:00
+ this.title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title);
+ this.adventure$title = title;
+ this.viewers = new ArrayList<HumanEntity>();
+ this.owner = owner;
+ this.type = InventoryType.CHEST;
+ }
+ // Paper end
+
@Override
public int getContainerSize() {
2021-06-11 21:23:46 +02:00
return this.items.size();
2021-06-11 14:02:28 +02:00
@@ -183,6 +216,12 @@ public class CraftInventoryCustom extends CraftInventory {
return null;
}
+ // Paper start
+ public net.kyori.adventure.text.Component title() {
+ return this.adventure$title;
+ }
+ // Paper end
+
public String getTitle() {
2021-06-11 21:23:46 +02:00
return this.title;
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
2021-06-11 21:23:46 +02:00
index 6a64fbb8b4937f39d5fdc2e2cbec26c83c74c486..7d6b5fdb00a5c1614849735634262a36a4efbd66 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
@@ -64,6 +64,13 @@ public class CraftInventoryView extends InventoryView {
2021-06-11 21:23:46 +02:00
return CraftItemStack.asCraftMirror(this.container.getSlot(slot).getItem());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
+ }
+ // Paper end
+
@Override
public String getTitle() {
2021-06-11 21:23:46 +02:00
return CraftChatMessage.fromComponent(this.container.getTitle());
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2021-10-31 08:34:10 +01:00
index ddcd4f2f1442d9e1b4d04c88f0f96841c4d5650d..69af359e0160480b77886ca35d8f8f3135f06455 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
2021-10-31 08:34:10 +01:00
@@ -344,4 +344,17 @@ public final class CraftItemFactory implements ItemFactory {
2021-06-11 14:02:28 +02:00
public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException {
return ((CraftMetaItem) meta).updateMaterial(material);
}
+
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
+ final net.minecraft.nbt.CompoundTag tag = CraftItemStack.asNMSCopy(item).getTag();
+ return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(net.kyori.adventure.text.event.HoverEvent.ShowItem.of(item.getType().getKey(), item.getAmount(), io.papermc.paper.adventure.PaperAdventure.asBinaryTagHolder(tag))));
+ }
+
+ @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component displayName(@org.jetbrains.annotations.NotNull ItemStack itemStack) {
2021-06-16 19:48:25 +02:00
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
2021-11-23 12:27:39 +01:00
index 059c84a4e50b043f2ac2a033d5d3cbf3cba3b3f9..552851cff3678d605428866999951fefd4375d7a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
@@ -14,10 +14,17 @@ import org.apache.commons.lang.Validate;
public class CraftMerchantCustom extends CraftMerchant {
+ @Deprecated // Paper - Adventure
public CraftMerchantCustom(String title) {
super(new MinecraftMerchant(title));
2021-06-11 21:23:46 +02:00
this.getMerchant().craftMerchant = this;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
+ super(new MinecraftMerchant(title));
+ getMerchant().craftMerchant = this;
+ }
+ // Paper end
@Override
public String toString() {
@@ -37,10 +44,17 @@ public class CraftMerchantCustom extends CraftMerchant {
private Level tradingWorld;
protected CraftMerchant craftMerchant;
+ @Deprecated // Paper - Adventure
public MinecraftMerchant(String title) {
Validate.notNull(title, "Title cannot be null");
this.title = new TextComponent(title);
}
+ // 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
2021-08-09 00:57:20 +02:00
index ca359cb1ac5f48d4f75d33946fcddedb270407c2..0f753f4868141ecc383877ea3a666a383f2e3339 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
@@ -1,8 +1,9 @@
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;
2021-06-12 00:37:16 +02:00
@@ -17,9 +18,11 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
2021-06-11 14:02:28 +02:00
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;
2021-08-09 00:57:20 +02:00
@@ -269,6 +272,145 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
2021-06-11 14:02:28 +02:00
this.generation = (generation == null) ? null : generation.ordinal();
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component title() {
+ return this.title == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(this.title);
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
+ this.setTitle(title == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title));
+ return this;
+ }
+
+ @Override
+ public net.kyori.adventure.text.Component author() {
+ return this.author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(this.author);
+ }
+
+ @Override
+ public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
+ this.setAuthor(author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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)) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::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) : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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 : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title);
+ this.author = author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(author);
+ this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC::serialize).collect(java.util.stream.Collectors.toList());
+ }
+
2021-08-09 00:57:20 +02:00
+ static class CraftMetaBookBuilder implements BookMetaBuilder {
2021-06-11 14:02:28 +02:00
+ private net.kyori.adventure.text.Component title = null;
+ private net.kyori.adventure.text.Component author = null;
+ private final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
+
+ @Override
+ public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
+ this.title = title;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
+ this.author = author;
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
+ this.pages.add(page);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
+ java.util.Collections.addAll(this.pages, pages);
+ return this;
+ }
+
+ @Override
+ public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
+ this.pages.addAll(pages);
+ return this;
+ }
+
+ @Override
+ public BookMeta build() {
2021-08-09 00:57:20 +02:00
+ return this.build(title, author, pages);
+ }
+
+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
2021-06-11 14:02:28 +02:00
+ return new CraftMetaBook(title, author, pages);
+ }
+ }
+
+ @Override
+ public BookMetaBuilder toBuilder() {
+ return new CraftMetaBookBuilder();
+ }
+
+ // Paper end
@Override
public String getPage(final int page) {
2021-06-11 21:23:46 +02:00
Validate.isTrue(this.isValidPage(page), "Invalid page number");
2021-08-09 00:57:20 +02:00
@@ -413,7 +555,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
2021-06-11 14:02:28 +02:00
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
2021-06-11 21:23:46 +02:00
if (this.hasTitle()) {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
2021-08-09 00:57:20 +02:00
index 00445fc7373c70f4cecc4114f9bcfb4b6f27c0e8..b132c151e4fb6c64b633a0712100c3ae5adb81a9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
@@ -1,6 +1,6 @@
package org.bukkit.craftbukkit.inventory;
-import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.ImmutableMap; // Paper
import java.util.Map;
import net.minecraft.nbt.CompoundTag;
import org.bukkit.Material;
2021-08-09 00:57:20 +02:00
@@ -84,8 +84,29 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
2021-06-11 14:02:28 +02:00
}
@Override
- Builder<String, Object> serialize(Builder<String, Object> builder) {
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);
return builder;
}
2021-08-09 00:57:20 +02:00
+
+ // 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 : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(title);
+ this.author = author == null ? null : io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.serialize(author);
+ this.pages = io.papermc.paper.adventure.PaperAdventure.asJson(pages.subList(0, Math.min(MAX_PAGES, pages.size())));
+ }
+
+ static final class CraftMetaBookSignedBuilder extends CraftMetaBookBuilder {
+ @Override
+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
+ return new CraftMetaBookSigned(title, author, pages);
+ }
+ }
+
+ @Override
+ public BookMetaBuilder toBuilder() {
+ return new CraftMetaBookSignedBuilder();
+ }
+ // Paper end
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
2022-01-01 04:05:42 +01:00
index f9626f2ec5e26685660c1c96d2fc507c06a20a1b..39d2cd4acbce96cd7b9bd76bddf85b9b8729855a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
2021-07-07 08:52:40 +02:00
@@ -746,6 +746,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
2021-06-11 21:23:46 +02:00
return !(this.hasDisplayName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isUnbreakable() || this.hasDamage() || this.hasAttributeModifiers());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() {
+ return displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(displayName);
+ }
+
+ @Override
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
+ this.displayName = displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(displayName);
+ }
+ // Paper end
+
@Override
public String getDisplayName() {
return CraftChatMessage.fromJSONComponent(displayName);
2021-07-07 08:52:40 +02:00
@@ -781,6 +793,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
2021-06-11 14:02:28 +02:00
return this.lore != null && !this.lore.isEmpty();
}
+ // Paper start
+ @Override
+ public List<net.kyori.adventure.text.Component> lore() {
+ return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventureFromJson(this.lore) : null;
+ }
+
+ @Override
+ public void lore(final List<net.kyori.adventure.text.Component> lore) {
+ this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asJson(lore) : null;
+ }
+ // Paper end
+
@Override
public boolean hasRepairCost() {
2021-06-11 21:23:46 +02:00
return this.repairCost > 0;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
index ed4415f6dd588c08c922efd5beebb3b124beb9d6..78a7ac47f20e84ccd67ff44d0bc7a2f2faa0d476 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
@@ -12,6 +12,13 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(holder, type);
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, type, title);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
return new CraftInventoryCustom(owner, type, title);
@@ -21,6 +28,12 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
return new CraftInventoryCustom(owner, size);
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
+ return new CraftInventoryCustom(owner, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder owner, int size, String title) {
return new CraftInventoryCustom(owner, size, title);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
2022-02-23 00:00:45 +01:00
index 4e705b7367b78c2da98d0b174807ecbce75f3a59..4972ce5d876d74e04a4fbfeb860f1d44e25b3470 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
2022-02-23 00:00:45 +01:00
@@ -43,6 +43,12 @@ public final class CraftInventoryCreator {
2021-06-11 21:23:46 +02:00
return this.converterMap.get(type).createInventory(holder, type);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
+ return converterMap.get(type).createInventory(holder, type, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
return this.converterMap.get(type).createInventory(holder, type, title);
2021-06-11 14:02:28 +02:00
}
2022-02-23 00:00:45 +01:00
@@ -51,6 +57,12 @@ public final class CraftInventoryCreator {
2021-06-11 21:23:46 +02:00
return this.DEFAULT_CONVERTER.createInventory(holder, size);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
+ return DEFAULT_CONVERTER.createInventory(holder, size, title);
+ }
+ // Paper end
+
public Inventory createInventory(InventoryHolder holder, int size, String title) {
2021-06-11 21:23:46 +02:00
return this.DEFAULT_CONVERTER.createInventory(holder, size, title);
2021-06-11 14:02:28 +02:00
}
2022-02-23 00:00:45 +01:00
@@ -59,6 +71,10 @@ public final class CraftInventoryCreator {
2021-06-11 14:02:28 +02:00
Inventory createInventory(InventoryHolder holder, InventoryType type);
+ // Paper start
+ Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
+ // Paper end
+
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
2021-06-11 21:23:46 +02:00
index 1980240d3dc0331ddf2ff56e163e2bfbd3b231ab..7a7f3f53aef601f124d474d9890e23d87dd96900 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
@@ -31,6 +31,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
2021-06-11 21:23:46 +02:00
return this.getInventory(this.getTileEntity());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Container te = getTileEntity();
+ if (te instanceof RandomizableContainerBlockEntity) {
+ ((RandomizableContainerBlockEntity) te).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+
+ return getInventory(te);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
Container te = this.getTileEntity();
@@ -53,6 +65,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
2021-06-11 14:02:28 +02:00
return furnace;
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ Container tileEntity = getTileEntity();
+ ((AbstractFurnaceBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
2021-06-11 21:23:46 +02:00
Container tileEntity = this.getTileEntity();
@@ -73,6 +94,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
return new BrewingStandBlockEntity(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
+ // BrewingStand does not extend TileEntityLootable
+ Container tileEntity = getTileEntity();
+ if (tileEntity instanceof BrewingStandBlockEntity) {
+ ((BrewingStandBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
+ }
+ return getInventory(tileEntity);
+ }
+ // Paper end
+
@Override
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
// BrewingStand does not extend TileEntityLootable
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
2021-11-23 12:27:39 +01:00
index e9bb0728ae5c16aad4acc106d332db5095db4033..6752cd9b3bc246fc2a7764df0d2b40d3e638fa62 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
@@ -30,6 +30,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
2021-06-11 21:23:46 +02:00
return this.objective.getName();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) {
+ displayName = net.kyori.adventure.text.Component.empty();
+ }
+ CraftScoreboard scoreboard = checkState();
+ objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ // Paper end
@Override
public String getDisplayName() throws IllegalStateException {
2021-06-11 21:23:46 +02:00
CraftScoreboard scoreboard = this.checkState();
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
2021-11-23 12:27:39 +01:00
index afc059755ae3e7b1c0a4cf3c6b8f32ce13cc458d..59f60fcadd8767cf8698482547e8c771d970732a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
@@ -27,6 +27,27 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
2021-06-11 21:23:46 +02:00
return this.registerNewObjective(name, criteria, name);
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName) {
+ return registerNewObjective(name, criteria, displayName, org.bukkit.scoreboard.RenderType.INTEGER);
+ }
+ @Override
+ public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) {
+ 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() <= 16, "The name '" + name + "' is longer than the limit of 16 characters");
+ Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
+ CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
2021-06-11 21:23:46 +02:00
+ net.minecraft.world.scores.Objective objective = board.addObjective(name, craftCriteria.criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
2021-06-11 14:02:28 +02:00
+ return new CraftObjective(this, objective);
+ }
+ // Paper end
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
@@ -35,7 +56,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName, RenderType renderType) throws IllegalArgumentException {
- Validate.notNull(name, "Objective name cannot be null");
+ /*Validate.notNull(name, "Objective name cannot be null"); // Paper
Validate.notNull(criteria, "Criteria cannot be null");
Validate.notNull(displayName, "Display name cannot be null");
Validate.notNull(renderType, "RenderType cannot be null");
2021-06-11 21:23:46 +02:00
@@ -45,7 +66,11 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
2021-06-11 14:02:28 +02:00
CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
2021-06-11 21:23:46 +02:00
net.minecraft.world.scores.Objective objective = this.board.addObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
2021-06-11 14:02:28 +02:00
- return new CraftObjective(this, objective);
2021-06-11 21:23:46 +02:00
+
+ CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
2021-06-11 14:02:28 +02:00
+ ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
+ return new CraftObjective(this, objective);*/ // Paper
+ return registerNewObjective(name, criteria, io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.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
2021-06-16 19:48:25 +02:00
index 81f16dc1ed6e102af298600db75cab21a09bc00f..f86776aa42bd5520f8aaeaa46bb93ec4d5b4e27d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
@@ -28,6 +28,55 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
2021-06-11 21:23:46 +02:00
return this.team.getName();
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
+ }
+ @Override
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
+ if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
+ }
+ @Override
+ public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerPrefix());
+ }
+ @Override
+ public void prefix(net.kyori.adventure.text.Component prefix) throws IllegalStateException, IllegalArgumentException {
+ if (prefix == null) prefix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setPlayerPrefix(io.papermc.paper.adventure.PaperAdventure.asVanilla(prefix));
+ }
+ @Override
+ public net.kyori.adventure.text.Component suffix() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerSuffix());
+ }
+ @Override
+ public void suffix(net.kyori.adventure.text.Component suffix) throws IllegalStateException, IllegalArgumentException {
+ if (suffix == null) suffix = net.kyori.adventure.text.Component.empty();
+ CraftScoreboard scoreboard = checkState();
+ team.setPlayerSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
+ }
+ @Override
+ public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
+ CraftScoreboard scoreboard = checkState();
2021-06-16 19:48:25 +02:00
+ if (team.getColor().getColor() == null) throw new IllegalStateException("Team colors must have hex values");
+ net.kyori.adventure.text.format.TextColor color = net.kyori.adventure.text.format.TextColor.color(team.getColor().getColor());
2021-06-11 14:02:28 +02:00
+ if (!(color instanceof net.kyori.adventure.text.format.NamedTextColor)) throw new IllegalStateException("Team doesn't have a NamedTextColor");
+ return (net.kyori.adventure.text.format.NamedTextColor) color;
+ }
+ @Override
+ public void color(net.kyori.adventure.text.format.NamedTextColor color) {
+ if (color == null) color = net.kyori.adventure.text.format.NamedTextColor.WHITE;
+ CraftScoreboard scoreboard = checkState();
+ 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
2021-06-11 21:23:46 +02:00
index f9b7b8f7ccc95b73967a51420fd6ce88d80d75fe..0de5a46423ae0403dcbfca630dfd7c5ac1e1761d 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
@@ -290,6 +290,7 @@ 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
2022-03-01 06:43:03 +01:00
index c7a8e3b4ff46727d7f186497ff0288284eaa6d3b..964d15cd3b61a33868e5a9e38d21d97ec144bcad 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2022-01-01 04:05:42 +01:00
@@ -66,6 +66,38 @@ public final class CraftMagicNumbers implements UnsafeValues {
2021-06-11 14:02:28 +02:00
private CraftMagicNumbers() {}
+ // Paper start
+ @Override
+ public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() {
+ return io.papermc.paper.adventure.PaperAdventure.FLATTENER;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.COLOR_DOWNSAMPLING_GSON;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.GSON;
+ }
+
+ @Override
2021-12-22 23:56:37 +01:00
+ public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.PLAIN_COMPONENT;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer plainTextSerializer() {
2021-06-11 14:02:28 +02:00
+ return io.papermc.paper.adventure.PaperAdventure.PLAIN;
+ }
+
+ @Override
+ public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
+ return io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC;
+ }
+ // Paper end
+
public static BlockState getBlock(MaterialData material) {
2021-06-11 21:23:46 +02:00
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
2021-06-11 21:23:46 +02:00
index 62c66e3179b9557cdba46242df0fb15bce7e7710..73a37638abacdffbff8274291a64ea6cd0be7a5e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyHashSet.java
@@ -80,7 +80,7 @@ public abstract class LazyHashSet<E> implements Set<E> {
2021-06-11 21:23:46 +02:00
return this.reference = this.makeReference();
2021-06-11 14:02:28 +02:00
}
- abstract Set<E> makeReference();
+ protected abstract Set<E> makeReference(); // Paper - protected
public boolean isLazy() {
2021-06-11 21:23:46 +02:00
return this.reference == null;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
2021-06-11 21:23:46 +02:00
index 838d5b877c01be3ef353f434d98e27b46c0a3fb4..5c4c0ba05f10d2d83b22d3e86805cfa85c3b50a9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/LazyPlayerSet.java
2021-06-11 21:23:46 +02:00
@@ -15,11 +15,17 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
2021-06-11 14:02:28 +02:00
}
@Override
- HashSet<Player> makeReference() {
+ protected HashSet<Player> makeReference() { // Paper - protected
if (reference != null) {
throw new IllegalStateException("Reference already created!");
}
2021-06-11 21:23:46 +02:00
List<ServerPlayer> players = this.server.getPlayerList().players;
2021-06-11 14:02:28 +02:00
+ // Paper start
+ return makePlayerSet(this.server);
+ }
+ public static HashSet<Player> makePlayerSet(final MinecraftServer server) {
+ // Paper end
2021-06-11 21:23:46 +02:00
+ List<ServerPlayer> players = server.getPlayerList().players;
2021-06-11 14:02:28 +02:00
HashSet<Player> reference = new HashSet<Player>(players.size());
for (ServerPlayer player : players) {
2021-06-11 21:23:46 +02:00
reference.add(player.getBukkitEntity());