mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 17:31:06 +01:00
2914 lines
144 KiB
Diff
2914 lines
144 KiB
Diff
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/io/papermc/paper/adventure/AdventureComponent.java b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a2acd31dce4461338a8baa96e03df36a4b4281b8
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java
|
|
@@ -0,0 +1,78 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import com.google.gson.JsonElement;
|
|
+import com.google.gson.JsonSerializationContext;
|
|
+import com.google.gson.JsonSerializer;
|
|
+import java.lang.reflect.Type;
|
|
+import java.util.List;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.TextComponent;
|
|
+import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
|
+import net.minecraft.server.ChatModifier;
|
|
+import net.minecraft.server.IChatBaseComponent;
|
|
+import net.minecraft.server.IChatMutableComponent;
|
|
+import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
|
+
|
|
+public final class AdventureComponent implements IChatBaseComponent {
|
|
+ final Component wrapped;
|
|
+ private @MonotonicNonNull IChatBaseComponent converted;
|
|
+
|
|
+ public AdventureComponent(final Component wrapped) {
|
|
+ this.wrapped = wrapped;
|
|
+ }
|
|
+
|
|
+ public IChatBaseComponent deepConverted() {
|
|
+ IChatBaseComponent converted = this.converted;
|
|
+ if (converted == null) {
|
|
+ converted = PaperAdventure.WRAPPER_AWARE_SERIALIZER.serialize(this.wrapped);
|
|
+ this.converted = converted;
|
|
+ }
|
|
+ return converted;
|
|
+ }
|
|
+
|
|
+ public @Nullable IChatBaseComponent deepConvertedIfPresent() {
|
|
+ return this.converted;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ChatModifier getChatModifier() {
|
|
+ return this.deepConverted().getChatModifier();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getText() {
|
|
+ if (this.wrapped instanceof TextComponent) {
|
|
+ return ((TextComponent) this.wrapped).content();
|
|
+ } else {
|
|
+ return this.deepConverted().getText();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getString() {
|
|
+ return PlainComponentSerializer.plain().serialize(this.wrapped);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<IChatBaseComponent> getSiblings() {
|
|
+ return this.deepConverted().getSiblings();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public IChatMutableComponent g() {
|
|
+ return this.deepConverted().g();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public IChatMutableComponent mutableCopy() {
|
|
+ return this.deepConverted().mutableCopy();
|
|
+ }
|
|
+
|
|
+ public static class Serializer implements JsonSerializer<AdventureComponent> {
|
|
+ @Override
|
|
+ public JsonElement serialize(final AdventureComponent src, final Type type, final JsonSerializationContext context) {
|
|
+ return PaperAdventure.GSON.serializer().toJsonTree(src.wrapped, Component.class);
|
|
+ }
|
|
+ }
|
|
+}
|
|
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..64fcc77eb2ce8979ae756696d98f1d3a91326ba6
|
|
--- /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.server.MojangsonParser;
|
|
+import net.minecraft.server.NBTBase;
|
|
+import net.minecraft.server.NBTTagCompound;
|
|
+
|
|
+final class NBTLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
|
|
+ public static final NBTLegacyHoverEventSerializer INSTANCE = new NBTLegacyHoverEventSerializer();
|
|
+ private static final Codec<NBTTagCompound, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.of(MojangsonParser::parse, NBTBase::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 NBTTagCompound contents = SNBT_CODEC.decode(raw);
|
|
+ final NBTTagCompound tag = contents.getCompound(ITEM_TAG);
|
|
+ return HoverEvent.ShowItem.of(
|
|
+ Key.key(contents.getString(ITEM_TYPE)),
|
|
+ contents.hasKey(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 NBTTagCompound 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 NBTTagCompound tag = new NBTTagCompound();
|
|
+ tag.setString(ITEM_TYPE, input.item().asString());
|
|
+ tag.setByte(ITEM_COUNT, (byte) input.count());
|
|
+ if (input.nbt() != null) {
|
|
+ try {
|
|
+ tag.set(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 NBTTagCompound tag = new NBTTagCompound();
|
|
+ tag.setString(ENTITY_ID, input.id().toString());
|
|
+ tag.setString(ENTITY_TYPE, input.type().asString());
|
|
+ if (input.name() != null) {
|
|
+ tag.setString(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
|
|
index 0000000000000000000000000000000000000000..7beb93a96b9eca4558131c339678cc31e9972c96
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -0,0 +1,284 @@
|
|
+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 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.format.TextColor;
|
|
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
+import net.kyori.adventure.translation.GlobalTranslator;
|
|
+import net.kyori.adventure.util.Codec;
|
|
+import net.minecraft.server.BossBattle;
|
|
+import net.minecraft.server.EnumChatFormat;
|
|
+import net.minecraft.server.IChatBaseComponent;
|
|
+import net.minecraft.server.ItemStack;
|
|
+import net.minecraft.server.MinecraftKey;
|
|
+import net.minecraft.server.MojangsonParser;
|
|
+import net.minecraft.server.NBTTagCompound;
|
|
+import net.minecraft.server.NBTTagList;
|
|
+import net.minecraft.server.NBTTagString;
|
|
+import net.minecraft.server.SoundCategory;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
|
+
|
|
+public final class PaperAdventure {
|
|
+ public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale");
|
|
+ static final GsonComponentSerializer GSON = GsonComponentSerializer.builder()
|
|
+ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
|
|
+ .build();
|
|
+ private static final Codec<NBTTagCompound, String, IOException, IOException> NBT_CODEC = new Codec<NBTTagCompound, String, IOException, IOException>() {
|
|
+ @Override
|
|
+ public @NonNull NBTTagCompound decode(final @NonNull String encoded) throws IOException {
|
|
+ try {
|
|
+ return MojangsonParser.parse(encoded);
|
|
+ } catch (final CommandSyntaxException e) {
|
|
+ throw new IOException(e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @NonNull String encode(final @NonNull NBTTagCompound decoded) {
|
|
+ return decoded.toString();
|
|
+ }
|
|
+ };
|
|
+ static final WrapperAwareSerializer WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer();
|
|
+
|
|
+ private PaperAdventure() {
|
|
+ }
|
|
+
|
|
+ // Key
|
|
+
|
|
+ public static MinecraftKey asVanilla(final Key key) {
|
|
+ return new MinecraftKey(key.namespace(), key.value());
|
|
+ }
|
|
+
|
|
+ public static MinecraftKey asVanillaNullable(final Key key) {
|
|
+ if (key == null) {
|
|
+ return null;
|
|
+ }
|
|
+ return new MinecraftKey(key.namespace(), key.value());
|
|
+ }
|
|
+
|
|
+ // Component
|
|
+
|
|
+ public static Component asAdventure(final IChatBaseComponent component) {
|
|
+ return GSON.serializer().fromJson(IChatBaseComponent.ChatSerializer.toJsonTree(component), Component.class);
|
|
+ }
|
|
+
|
|
+ public static ArrayList<Component> asAdventure(final List<IChatBaseComponent> vanillas) {
|
|
+ final ArrayList<Component> adventures = new ArrayList<>(vanillas.size());
|
|
+ for (final IChatBaseComponent 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 IChatBaseComponent asVanilla(final Component component) {
|
|
+ if (true) return new AdventureComponent(component);
|
|
+ return IChatBaseComponent.ChatSerializer.fromJsonTree(GSON.serializer().toJsonTree(component));
|
|
+ }
|
|
+
|
|
+ public static List<IChatBaseComponent> asVanilla(final List<Component> adventures) {
|
|
+ final List<IChatBaseComponent> 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 IChatBaseComponent component, final Locale locale) {
|
|
+ if (component instanceof AdventureComponent) {
|
|
+ return asJsonString(((AdventureComponent) component).wrapped, locale);
|
|
+ }
|
|
+ return IChatBaseComponent.ChatSerializer.componentToJson(component);
|
|
+ }
|
|
+
|
|
+ // BossBar
|
|
+
|
|
+ public static BossBattle.BarColor asVanilla(final BossBar.Color color) {
|
|
+ if (color == BossBar.Color.PINK) {
|
|
+ return BossBattle.BarColor.PINK;
|
|
+ } else if (color == BossBar.Color.BLUE) {
|
|
+ return BossBattle.BarColor.BLUE;
|
|
+ } else if (color == BossBar.Color.RED) {
|
|
+ return BossBattle.BarColor.RED;
|
|
+ } else if (color == BossBar.Color.GREEN) {
|
|
+ return BossBattle.BarColor.GREEN;
|
|
+ } else if (color == BossBar.Color.YELLOW) {
|
|
+ return BossBattle.BarColor.YELLOW;
|
|
+ } else if (color == BossBar.Color.PURPLE) {
|
|
+ return BossBattle.BarColor.PURPLE;
|
|
+ } else if (color == BossBar.Color.WHITE) {
|
|
+ return BossBattle.BarColor.WHITE;
|
|
+ }
|
|
+ throw new IllegalArgumentException(color.name());
|
|
+ }
|
|
+
|
|
+ public static BossBar.Color asAdventure(final BossBattle.BarColor color) {
|
|
+ if(color == BossBattle.BarColor.PINK) {
|
|
+ return BossBar.Color.PINK;
|
|
+ } else if(color == BossBattle.BarColor.BLUE) {
|
|
+ return BossBar.Color.BLUE;
|
|
+ } else if(color == BossBattle.BarColor.RED) {
|
|
+ return BossBar.Color.RED;
|
|
+ } else if(color == BossBattle.BarColor.GREEN) {
|
|
+ return BossBar.Color.GREEN;
|
|
+ } else if(color == BossBattle.BarColor.YELLOW) {
|
|
+ return BossBar.Color.YELLOW;
|
|
+ } else if(color == BossBattle.BarColor.PURPLE) {
|
|
+ return BossBar.Color.PURPLE;
|
|
+ } else if(color == BossBattle.BarColor.WHITE) {
|
|
+ return BossBar.Color.WHITE;
|
|
+ }
|
|
+ throw new IllegalArgumentException(color.name());
|
|
+ }
|
|
+
|
|
+ public static BossBattle.BarStyle asVanilla(final BossBar.Overlay overlay) {
|
|
+ if (overlay == BossBar.Overlay.PROGRESS) {
|
|
+ return BossBattle.BarStyle.PROGRESS;
|
|
+ } else if (overlay == BossBar.Overlay.NOTCHED_6) {
|
|
+ return BossBattle.BarStyle.NOTCHED_6;
|
|
+ } else if (overlay == BossBar.Overlay.NOTCHED_10) {
|
|
+ return BossBattle.BarStyle.NOTCHED_10;
|
|
+ } else if (overlay == BossBar.Overlay.NOTCHED_12) {
|
|
+ return BossBattle.BarStyle.NOTCHED_12;
|
|
+ } else if (overlay == BossBar.Overlay.NOTCHED_20) {
|
|
+ return BossBattle.BarStyle.NOTCHED_20;
|
|
+ }
|
|
+ throw new IllegalArgumentException(overlay.name());
|
|
+ }
|
|
+
|
|
+ public static BossBar.Overlay asAdventure(final BossBattle.BarStyle overlay) {
|
|
+ if (overlay == BossBattle.BarStyle.PROGRESS) {
|
|
+ return BossBar.Overlay.PROGRESS;
|
|
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_6) {
|
|
+ return BossBar.Overlay.NOTCHED_6;
|
|
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_10) {
|
|
+ return BossBar.Overlay.NOTCHED_10;
|
|
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_12) {
|
|
+ return BossBar.Overlay.NOTCHED_12;
|
|
+ } else if (overlay == BossBattle.BarStyle.NOTCHED_20) {
|
|
+ return BossBar.Overlay.NOTCHED_20;
|
|
+ }
|
|
+ throw new IllegalArgumentException(overlay.name());
|
|
+ }
|
|
+
|
|
+ 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.server.Items.WRITTEN_BOOK, 1);
|
|
+ final NBTTagCompound tag = item.getOrCreateTag();
|
|
+ tag.setString("title", asJsonString(book.title(), locale));
|
|
+ tag.setString("author", asJsonString(book.author(), locale));
|
|
+ final NBTTagList pages = new NBTTagList();
|
|
+ for (final Component page : book.pages()) {
|
|
+ pages.add(NBTTagString.create(asJsonString(page, locale)));
|
|
+ }
|
|
+ tag.set("pages", pages);
|
|
+ return item;
|
|
+ }
|
|
+
|
|
+ // Sounds
|
|
+
|
|
+ public static SoundCategory asVanilla(final Sound.Source source) {
|
|
+ if (source == Sound.Source.MASTER) {
|
|
+ return SoundCategory.MASTER;
|
|
+ } else if (source == Sound.Source.MUSIC) {
|
|
+ return SoundCategory.MUSIC;
|
|
+ } else if (source == Sound.Source.RECORD) {
|
|
+ return SoundCategory.RECORDS;
|
|
+ } else if (source == Sound.Source.WEATHER) {
|
|
+ return SoundCategory.WEATHER;
|
|
+ } else if (source == Sound.Source.BLOCK) {
|
|
+ return SoundCategory.BLOCKS;
|
|
+ } else if (source == Sound.Source.HOSTILE) {
|
|
+ return SoundCategory.HOSTILE;
|
|
+ } else if (source == Sound.Source.NEUTRAL) {
|
|
+ return SoundCategory.NEUTRAL;
|
|
+ } else if (source == Sound.Source.PLAYER) {
|
|
+ return SoundCategory.PLAYERS;
|
|
+ } else if (source == Sound.Source.AMBIENT) {
|
|
+ return SoundCategory.AMBIENT;
|
|
+ } else if (source == Sound.Source.VOICE) {
|
|
+ return SoundCategory.VOICE;
|
|
+ }
|
|
+ throw new IllegalArgumentException(source.name());
|
|
+ }
|
|
+
|
|
+ public static @Nullable SoundCategory asVanillaNullable(final Sound.@Nullable Source source) {
|
|
+ if (source == null) {
|
|
+ return null;
|
|
+ }
|
|
+ return asVanilla(source);
|
|
+ }
|
|
+
|
|
+ // NBT
|
|
+
|
|
+ public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable NBTTagCompound tag) {
|
|
+ if (tag == null) {
|
|
+ return null;
|
|
+ }
|
|
+ try {
|
|
+ return BinaryTagHolder.encode(tag, NBT_CODEC);
|
|
+ } catch (final IOException e) {
|
|
+ return null;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Colors
|
|
+
|
|
+ public static @NonNull TextColor asAdventure(EnumChatFormat minecraftColor) {
|
|
+ if (minecraftColor.e() == null) {
|
|
+ throw new IllegalArgumentException("Not a valid color");
|
|
+ }
|
|
+ return TextColor.color(minecraftColor.e());
|
|
+ }
|
|
+
|
|
+ public static @Nullable EnumChatFormat asVanilla(TextColor color) {
|
|
+ return EnumChatFormat.getByHexValue(color.value());
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..59dd2a453dbfc538431a3414ab35d183cff0faec
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/VanillaBossBarListener.java
|
|
@@ -0,0 +1,41 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import java.util.Set;
|
|
+import java.util.function.Consumer;
|
|
+import net.kyori.adventure.bossbar.BossBar;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.minecraft.server.PacketPlayOutBoss;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+
|
|
+public final class VanillaBossBarListener implements BossBar.Listener {
|
|
+ private final Consumer<PacketPlayOutBoss.Action> action;
|
|
+
|
|
+ public VanillaBossBarListener(final Consumer<PacketPlayOutBoss.Action> action) {
|
|
+ this.action = action;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
|
|
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_NAME);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
|
|
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_PCT);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
|
|
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_STYLE);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
|
|
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_STYLE);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
|
|
+ this.action.accept(PacketPlayOutBoss.Action.UPDATE_PROPERTIES);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..39c1e750ae1270ca780a5d8624f8daa45bd27637
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java
|
|
@@ -0,0 +1,44 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import java.util.function.BiFunction;
|
|
+import java.util.regex.MatchResult;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.ComponentLike;
|
|
+import net.kyori.adventure.text.TextComponent;
|
|
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
+
|
|
+public class VanillaChatMessageLogic {
|
|
+ public static Component displayNameForChat(final CraftPlayer player) {
|
|
+ return player.displayName();
|
|
+ }
|
|
+
|
|
+ public static Component formatChat(final Component displayName, final String format, final String message) {
|
|
+ final class Replacement implements BiFunction<MatchResult, TextComponent.Builder, ComponentLike> {
|
|
+ private int index = 0;
|
|
+
|
|
+ @Override
|
|
+ public ComponentLike apply(final MatchResult result, final TextComponent.Builder builder) {
|
|
+ if (this.index == 0) {
|
|
+ this.index++;
|
|
+ return displayName;
|
|
+ } else if (this.index == 1) {
|
|
+ this.index++;
|
|
+ return LegacyComponentSerializer.legacySection().deserialize(message).mergeStyle(builder.asComponent());
|
|
+ } else {
|
|
+ return builder;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ final Replacement replacement = new Replacement();
|
|
+ if (format.contains("%2$s") && !format.contains("%1$s")) {
|
|
+ replacement.index = 1;
|
|
+ }
|
|
+ return LegacyComponentSerializer.legacySection().deserialize(format)
|
|
+ .replaceText(config -> {
|
|
+ config.times(2);
|
|
+ config.match("%(\\d+\\$)?s");
|
|
+ config.replacement(replacement);
|
|
+ });
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..1de7376cd4d3601f39d1f73b143c4244fe8480a3
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
|
|
@@ -0,0 +1,20 @@
|
|
+package io.papermc.paper.adventure;
|
|
+
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.serializer.ComponentSerializer;
|
|
+import net.minecraft.server.IChatBaseComponent;
|
|
+
|
|
+final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, IChatBaseComponent> {
|
|
+ @Override
|
|
+ public Component deserialize(final IChatBaseComponent input) {
|
|
+ if (input instanceof AdventureComponent) {
|
|
+ return ((AdventureComponent) input).wrapped;
|
|
+ }
|
|
+ return PaperAdventure.GSON.serializer().fromJson(IChatBaseComponent.ChatSerializer.toJsonTree(input), Component.class);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public IChatBaseComponent serialize(final Component component) {
|
|
+ return IChatBaseComponent.ChatSerializer.fromJsonTree(PaperAdventure.GSON.serializer().toJsonTree(component));
|
|
+ }
|
|
+}
|
|
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..7aacbd4cdd538f9676d8370a6baba81772efb6f5
|
|
--- /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.BossBattleServer;
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
+
|
|
+public abstract class HackyBossBarPlatformBridge {
|
|
+ public BossBattleServer 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 BossBattleServer(
|
|
+ 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::sendUpdate);
|
|
+ $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/server/BossBattle.java b/src/main/java/net/minecraft/server/BossBattle.java
|
|
index 715c6d9f4820f700cb931f549756d2af2005667b..04477938aeae32b221c15c3491fb9a80248eebb5 100644
|
|
--- a/src/main/java/net/minecraft/server/BossBattle.java
|
|
+++ b/src/main/java/net/minecraft/server/BossBattle.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.server;
|
|
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
import java.util.UUID;
|
|
|
|
public abstract class BossBattle {
|
|
@@ -12,6 +13,7 @@ public abstract class BossBattle {
|
|
protected boolean e;
|
|
protected boolean f;
|
|
protected boolean g;
|
|
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
|
|
|
|
public BossBattle(UUID uuid, IChatBaseComponent ichatbasecomponent, BossBattle.BarColor bossbattle_barcolor, BossBattle.BarStyle bossbattle_barstyle) {
|
|
this.h = uuid;
|
|
@@ -26,61 +28,75 @@ public abstract class BossBattle {
|
|
}
|
|
|
|
public IChatBaseComponent j() {
|
|
+ if(this.adventure != null) return PaperAdventure.asVanilla(this.adventure.name()); // Paper
|
|
return this.title;
|
|
}
|
|
|
|
public void a(IChatBaseComponent ichatbasecomponent) {
|
|
+ if (this.adventure != null) this.adventure.name(PaperAdventure.asAdventure(ichatbasecomponent)); // Paper
|
|
this.title = ichatbasecomponent;
|
|
}
|
|
|
|
public float getProgress() {
|
|
+ if (this.adventure != null) return this.adventure.progress(); // Paper
|
|
return this.b;
|
|
}
|
|
|
|
public void a(float f) {
|
|
+ if (this.adventure != null) this.adventure.progress(f); // Paper
|
|
this.b = f;
|
|
}
|
|
|
|
public BossBattle.BarColor l() {
|
|
+ if (this.adventure != null) return PaperAdventure.asVanilla(this.adventure.color()); // Paper
|
|
return this.color;
|
|
}
|
|
|
|
public void a(BossBattle.BarColor bossbattle_barcolor) {
|
|
+ if(this.adventure != null) this.adventure.color(PaperAdventure.asAdventure(bossbattle_barcolor)); // Paper
|
|
this.color = bossbattle_barcolor;
|
|
}
|
|
|
|
public BossBattle.BarStyle m() {
|
|
+ if(this.adventure != null) return PaperAdventure.asVanilla(this.adventure.overlay()); // Paper
|
|
return this.style;
|
|
}
|
|
|
|
public void a(BossBattle.BarStyle bossbattle_barstyle) {
|
|
+ if(this.adventure != null) this.adventure.overlay(PaperAdventure.asAdventure(bossbattle_barstyle)); // Paper
|
|
this.style = bossbattle_barstyle;
|
|
}
|
|
|
|
public boolean isDarkenSky() {
|
|
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN); // Paper
|
|
return this.e;
|
|
}
|
|
|
|
public BossBattle a(boolean flag) {
|
|
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN, flag); // Paper
|
|
this.e = flag;
|
|
return this;
|
|
}
|
|
|
|
public boolean isPlayMusic() {
|
|
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC); // Paper
|
|
return this.f;
|
|
}
|
|
|
|
public BossBattle b(boolean flag) {
|
|
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, flag); // Paper
|
|
this.f = flag;
|
|
return this;
|
|
}
|
|
|
|
public BossBattle c(boolean flag) {
|
|
+ if(this.adventure != null) PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, flag); // Paper
|
|
this.g = flag;
|
|
return this;
|
|
}
|
|
|
|
public boolean isCreateFog() {
|
|
+ if(this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG); // Paper
|
|
return this.g;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Enchantment.java b/src/main/java/net/minecraft/server/Enchantment.java
|
|
index 7e2162fc78168adb96ed20651e1a3e061c29f96d..8e94a62916574bc2e5e93c5cf2e5ea7950d61e2e 100644
|
|
--- a/src/main/java/net/minecraft/server/Enchantment.java
|
|
+++ b/src/main/java/net/minecraft/server/Enchantment.java
|
|
@@ -83,6 +83,7 @@ public abstract class Enchantment {
|
|
return this.f();
|
|
}
|
|
|
|
+ public final IChatBaseComponent getTranslationComponentForLevel(int level) { return this.d(level); } // Paper - OBFHELPER
|
|
public IChatBaseComponent d(int i) {
|
|
ChatMessage chatmessage = new ChatMessage(this.g());
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
index 37a84b44a46e1490f7b79839b04aef012ddc9fa3..0445bffdd1a6c9548c5c98c1ea4fd2c0c517acf4 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -16,6 +16,7 @@ import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.Location;
|
|
@@ -84,6 +85,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
// CraftBukkit start
|
|
public String displayName;
|
|
+ public net.kyori.adventure.text.Component adventure$displayName; // Paper
|
|
public IChatBaseComponent listName;
|
|
public org.bukkit.Location compassTarget;
|
|
public int newExp = 0;
|
|
@@ -114,6 +116,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
// CraftBukkit start
|
|
this.displayName = this.getName();
|
|
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getName()); // Paper
|
|
this.canPickUpLoot = true;
|
|
this.maxHealthCache = this.getMaxHealth();
|
|
}
|
|
@@ -567,23 +570,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
IChatBaseComponent defaultMessage = this.getCombatTracker().getDeathMessage();
|
|
|
|
- String deathmessage = defaultMessage.getString();
|
|
- 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), keepInventory); // Paper - Adventure
|
|
|
|
// SPIGOT-943 - only call if they have an inventory open
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
this.closeInventory();
|
|
}
|
|
|
|
- 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?
|
|
- IChatBaseComponent 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?
|
|
+ IChatBaseComponent ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure
|
|
|
|
this.playerConnection.a((Packet) (new PacketPlayOutCombatEvent(this.getCombatTracker(), PacketPlayOutCombatEvent.EnumCombatEventType.ENTITY_DIED, ichatbasecomponent)), (future) -> {
|
|
if (!future.isSuccess()) {
|
|
@@ -1555,6 +1552,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
}
|
|
|
|
public String locale = "en_us"; // CraftBukkit - add, lowercase
|
|
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
|
|
public void a(PacketPlayInSettings packetplayinsettings) {
|
|
// CraftBukkit start
|
|
if (getMainHand() != packetplayinsettings.getMainHand()) {
|
|
@@ -1566,6 +1564,10 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
this.server.server.getPluginManager().callEvent(event);
|
|
}
|
|
this.locale = packetplayinsettings.locale;
|
|
+ // Paper start
|
|
+ this.adventure$locale = net.kyori.adventure.translation.Translator.parseLocale(this.locale);
|
|
+ this.playerConnection.networkManager.channel.attr(PaperAdventure.LOCALE_ATTRIBUTE).set(this.adventure$locale);
|
|
+ // Paper end
|
|
this.clientViewDistance = packetplayinsettings.viewDistance;
|
|
// CraftBukkit end
|
|
this.bY = packetplayinsettings.d();
|
|
diff --git a/src/main/java/net/minecraft/server/EnumChatFormat.java b/src/main/java/net/minecraft/server/EnumChatFormat.java
|
|
index 68a5a0cbe88795f59ce96035da45371a5a366f5a..c186af518ef43e9efaf086233e1da8a1cf293c66 100644
|
|
--- a/src/main/java/net/minecraft/server/EnumChatFormat.java
|
|
+++ b/src/main/java/net/minecraft/server/EnumChatFormat.java
|
|
@@ -61,6 +61,7 @@ public enum EnumChatFormat {
|
|
return !this.A && this != EnumChatFormat.RESET;
|
|
}
|
|
|
|
+ @Nullable public Integer getHexValue() { return this.e(); } // Paper - OBFHELPER
|
|
@Nullable
|
|
public Integer e() {
|
|
return this.D;
|
|
@@ -84,6 +85,18 @@ public enum EnumChatFormat {
|
|
return s == null ? null : (EnumChatFormat) EnumChatFormat.w.get(c(s));
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Nullable public static EnumChatFormat getByHexValue(int i) {
|
|
+ for (EnumChatFormat value : values()) {
|
|
+ if (value.getHexValue() != null && value.getHexValue() == i) {
|
|
+ return value;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Nullable
|
|
public static EnumChatFormat a(int i) {
|
|
if (i < 0) {
|
|
diff --git a/src/main/java/net/minecraft/server/IChatBaseComponent.java b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
index 7441beeaa4ee83467dac4d68176132efc6247337..de6bfc27cd38fd6293853d55cf62699aade94212 100644
|
|
--- a/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
+++ b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.server;
|
|
|
|
+import io.papermc.paper.adventure.AdventureComponent; // Paper
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import com.google.gson.JsonArray;
|
|
@@ -104,6 +105,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
|
|
GsonBuilder gsonbuilder = new GsonBuilder();
|
|
|
|
gsonbuilder.disableHtmlEscaping();
|
|
+ gsonbuilder.registerTypeAdapter(AdventureComponent.class, new AdventureComponent.Serializer()); // Paper
|
|
gsonbuilder.registerTypeHierarchyAdapter(IChatBaseComponent.class, new IChatBaseComponent.ChatSerializer());
|
|
gsonbuilder.registerTypeHierarchyAdapter(ChatModifier.class, new ChatModifier.ChatModifierSerializer());
|
|
gsonbuilder.registerTypeAdapterFactory(new ChatTypeAdapterFactory());
|
|
@@ -344,10 +346,12 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
|
|
return jsonobject;
|
|
}
|
|
|
|
+ public static String componentToJson(final IChatBaseComponent component) { return a(component); } // Paper - OBFHELPER
|
|
public static String a(IChatBaseComponent ichatbasecomponent) {
|
|
return IChatBaseComponent.ChatSerializer.a.toJson(ichatbasecomponent);
|
|
}
|
|
|
|
+ public static JsonElement toJsonTree(final IChatBaseComponent component) { return b(component); } // Paper - OBFHELPER
|
|
public static JsonElement b(IChatBaseComponent ichatbasecomponent) {
|
|
return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent);
|
|
}
|
|
@@ -357,6 +361,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
|
|
return (IChatMutableComponent) ChatDeserializer.a(IChatBaseComponent.ChatSerializer.a, s, IChatMutableComponent.class, false);
|
|
}
|
|
|
|
+ public static @Nullable IChatBaseComponent fromJsonTree(final JsonElement json) { return a(json); } // Paper - OBFHELPER
|
|
@Nullable
|
|
public static IChatMutableComponent a(JsonElement jsonelement) {
|
|
return (IChatMutableComponent) IChatBaseComponent.ChatSerializer.a.fromJson(jsonelement, IChatMutableComponent.class);
|
|
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
|
|
index 291baeb12c796cfaa64d60d44007ee537ddedce2..b6544feaffacd511191054386614d3e921b26d6c 100644
|
|
--- a/src/main/java/net/minecraft/server/LoginListener.java
|
|
+++ b/src/main/java/net/minecraft/server/LoginListener.java
|
|
@@ -19,6 +19,7 @@ import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
import org.bukkit.event.player.PlayerPreLoginEvent;
|
|
@@ -282,7 +283,7 @@ public class LoginListener implements PacketLoginInListener {
|
|
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
|
|
@@ -293,12 +294,12 @@ public class LoginListener implements PacketLoginInListener {
|
|
|
|
LoginListener.this.server.processQueue.add(waitable);
|
|
if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
|
|
- disconnect(event.getKickMessage());
|
|
+ disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
|
return;
|
|
}
|
|
} else {
|
|
if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
|
- disconnect(asyncEvent.getKickMessage());
|
|
+ disconnect(PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
|
|
return;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/NBTTagString.java b/src/main/java/net/minecraft/server/NBTTagString.java
|
|
index 7ef2378311edd0645472d895cf3756426f25605d..f36e1bd69270bdfd9fa3de4626dc0f48cad8007b 100644
|
|
--- a/src/main/java/net/minecraft/server/NBTTagString.java
|
|
+++ b/src/main/java/net/minecraft/server/NBTTagString.java
|
|
@@ -40,6 +40,7 @@ public class NBTTagString implements NBTBase {
|
|
this.data = s;
|
|
}
|
|
|
|
+ public static NBTTagString create(final String value) { return a(value); } // Paper - OBFHELPER
|
|
public static NBTTagString a(String s) {
|
|
return s.isEmpty() ? NBTTagString.b : new NBTTagString(s);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
index 2976e8cc2da6e54e08e50ca1f5de5669823ef3f7..6c9aed49d5e63d6df608719ed17e813f86e93fcc 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
|
|
@@ -10,6 +10,7 @@ import io.netty.buffer.ByteBufOutputStream;
|
|
import io.netty.handler.codec.DecoderException;
|
|
import io.netty.handler.codec.EncoderException;
|
|
import io.netty.util.ByteProcessor;
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import java.io.DataInput;
|
|
import java.io.DataOutput;
|
|
import java.io.IOException;
|
|
@@ -31,6 +32,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
|
|
public class PacketDataSerializer extends ByteBuf {
|
|
|
|
private final ByteBuf a;
|
|
+ public java.util.Locale adventure$locale; // Paper
|
|
|
|
public PacketDataSerializer(ByteBuf bytebuf) {
|
|
this.a = bytebuf;
|
|
@@ -152,8 +154,15 @@ public class PacketDataSerializer extends ByteBuf {
|
|
return IChatBaseComponent.ChatSerializer.a(this.e(262144));
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public PacketDataSerializer writeComponent(final net.kyori.adventure.text.Component component) {
|
|
+ return this.writeUtf(PaperAdventure.asJsonString(component, this.adventure$locale), 262144);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public PacketDataSerializer a(IChatBaseComponent ichatbasecomponent) {
|
|
- return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144);
|
|
+ //return this.a(IChatBaseComponent.ChatSerializer.a(ichatbasecomponent), 262144); // Paper - comment
|
|
+ return this.writeUtf(PaperAdventure.asJsonString(ichatbasecomponent, this.adventure$locale), 262144); // Paper
|
|
}
|
|
|
|
public <T extends Enum<T>> T a(Class<T> oclass) {
|
|
@@ -336,6 +345,7 @@ public class PacketDataSerializer extends ByteBuf {
|
|
return this.a(s, 32767);
|
|
}
|
|
|
|
+ public PacketDataSerializer writeUtf(final String string, final int maxLength) { return this.a(string, maxLength); } // Paper - OBFHELPER
|
|
public PacketDataSerializer a(String s, int i) {
|
|
byte[] abyte = s.getBytes(StandardCharsets.UTF_8);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketEncoder.java b/src/main/java/net/minecraft/server/PacketEncoder.java
|
|
index 63c4dbd327beb7b6ab42eb44650d68accd3b0de6..d3c6bdbefb89b3e668477e0d771015e9b25c24a8 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketEncoder.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
|
|
@@ -3,6 +3,7 @@ package net.minecraft.server;
|
|
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 org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
@@ -35,6 +36,7 @@ public class PacketEncoder extends MessageToByteEncoder<Packet<?>> {
|
|
throw new IOException("Can't serialize unregistered packet");
|
|
} else {
|
|
PacketDataSerializer packetdataserializer = new PacketDataSerializer(bytebuf);
|
|
+ packetdataserializer.adventure$locale = channelhandlercontext.channel().attr(PaperAdventure.LOCALE_ATTRIBUTE).get(); // Paper
|
|
|
|
packetdataserializer.d(integer);
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutChat.java b/src/main/java/net/minecraft/server/PacketPlayOutChat.java
|
|
index 9ae419f9ad971ee5c743ee931426ab482b6184f1..47328ca5e3f1e71ed25ba89df5b666f041e49b76 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutChat.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutChat.java
|
|
@@ -6,6 +6,7 @@ import java.util.UUID;
|
|
public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
|
|
|
|
private IChatBaseComponent a;
|
|
+ public net.kyori.adventure.text.Component adventure$message; // Paper
|
|
public net.md_5.bungee.api.chat.BaseComponent[] components; // Spigot
|
|
private ChatMessageType b;
|
|
private UUID c;
|
|
@@ -27,6 +28,11 @@ public class PacketPlayOutChat implements Packet<PacketListenerPlayOut> {
|
|
|
|
@Override
|
|
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
|
+ // Paper start
|
|
+ if (this.adventure$message != null) {
|
|
+ packetdataserializer.writeComponent(this.adventure$message);
|
|
+ } else
|
|
+ // Paper end
|
|
// Spigot start
|
|
if (components != null) {
|
|
packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(components));
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutPlayerListHeaderFooter.java b/src/main/java/net/minecraft/server/PacketPlayOutPlayerListHeaderFooter.java
|
|
index bb15a104c5ec5b12a28078369dc12257105f89bd..e3a8e1353bf8cd00fab439ca8ee25d1bc428503c 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutPlayerListHeaderFooter.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutPlayerListHeaderFooter.java
|
|
@@ -6,6 +6,10 @@ public class PacketPlayOutPlayerListHeaderFooter implements Packet<PacketListene
|
|
|
|
public IChatBaseComponent header;
|
|
public IChatBaseComponent footer;
|
|
+ // Paper start
|
|
+ public net.kyori.adventure.text.Component adventure$header;
|
|
+ public net.kyori.adventure.text.Component adventure$footer;
|
|
+ // Paper end
|
|
|
|
public PacketPlayOutPlayerListHeaderFooter() {}
|
|
|
|
@@ -17,6 +21,13 @@ public class PacketPlayOutPlayerListHeaderFooter implements Packet<PacketListene
|
|
|
|
@Override
|
|
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
|
+ // Paper start
|
|
+ if (this.adventure$header != null && this.adventure$footer != null) {
|
|
+ packetdataserializer.writeComponent(this.adventure$header);
|
|
+ packetdataserializer.writeComponent(this.adventure$footer);
|
|
+ return;
|
|
+ }
|
|
+ // Paper end
|
|
packetdataserializer.a(this.header);
|
|
packetdataserializer.a(this.footer);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutTitle.java b/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
|
index 3a6e780007bc1b1fa799166daa01d3a9e15c7ab0..772ca6256964692a2b9c12e2edc532d2a8f51f7b 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
|
@@ -7,6 +7,7 @@ public class PacketPlayOutTitle implements Packet<PacketListenerPlayOut> {
|
|
|
|
private PacketPlayOutTitle.EnumTitleAction a;
|
|
private IChatBaseComponent b;
|
|
+ public net.kyori.adventure.text.Component adventure$text; // Paper
|
|
private int c;
|
|
private int d;
|
|
private int e;
|
|
@@ -48,6 +49,11 @@ public class PacketPlayOutTitle implements Packet<PacketListenerPlayOut> {
|
|
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
|
packetdataserializer.a((Enum) this.a);
|
|
if (this.a == PacketPlayOutTitle.EnumTitleAction.TITLE || this.a == PacketPlayOutTitle.EnumTitleAction.SUBTITLE || this.a == PacketPlayOutTitle.EnumTitleAction.ACTIONBAR) {
|
|
+ // Paper start
|
|
+ if (this.adventure$text != null) {
|
|
+ packetdataserializer.writeComponent(this.adventure$text);
|
|
+ } else
|
|
+ // Paper end
|
|
packetdataserializer.a(this.b);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketStatusListener.java b/src/main/java/net/minecraft/server/PacketStatusListener.java
|
|
index 055555cb5ce63d41cb9a7f4114341b0685879b9e..7875d4c08969b3adc6f95504686cc9fe99e3f29a 100644
|
|
--- a/src/main/java/net/minecraft/server/PacketStatusListener.java
|
|
+++ b/src/main/java/net/minecraft/server/PacketStatusListener.java
|
|
@@ -43,7 +43,7 @@ public class PacketStatusListener implements PacketStatusInListener {
|
|
CraftIconCache icon = minecraftServer.server.getServerIcon();
|
|
|
|
ServerListPingEvent() {
|
|
- super(((InetSocketAddress) networkManager.getSocketAddress()).getAddress(), minecraftServer.getMotd(), minecraftServer.getPlayerList().getMaxPlayers());
|
|
+ super(((InetSocketAddress) networkManager.getSocketAddress()).getAddress(), minecraftServer.server.motd(), minecraftServer.getPlayerList().getMaxPlayers()); // Paper - Adventure
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index d34e91887cd73009bf852fb849e495a8affed7a9..6c759b295d1bdac25cd40713d7020fffa9d0fdb3 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -25,6 +25,8 @@ import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
+import io.papermc.paper.adventure.VanillaChatMessageLogic; // Paper
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
|
import org.bukkit.Location;
|
|
@@ -243,21 +245,20 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
return this.minecraftServer.a(this.player.getProfile());
|
|
}
|
|
|
|
- // CraftBukkit start
|
|
- @Deprecated
|
|
- public void disconnect(IChatBaseComponent ichatbasecomponent) {
|
|
- disconnect(CraftChatMessage.fromComponent(ichatbasecomponent));
|
|
+ public void disconnect(String s) {
|
|
+ // Paper start - Adventure
|
|
+ this.disconnect(CraftChatMessage.fromStringOrNull(s));
|
|
}
|
|
- // CraftBukkit end
|
|
|
|
- public void disconnect(String s) {
|
|
+ public void disconnect(IChatBaseComponent reason) {
|
|
+ // Paper end
|
|
// CraftBukkit start - fire PlayerKickEvent
|
|
if (this.processedDisconnect) {
|
|
return;
|
|
}
|
|
- String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " 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
|
|
|
|
- PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);
|
|
+ PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), PaperAdventure.asAdventure(reason), leaveMessage); // Paper - Adventure
|
|
|
|
if (this.server.getServer().isRunning()) {
|
|
this.server.getPluginManager().callEvent(event);
|
|
@@ -268,8 +269,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
return;
|
|
}
|
|
// Send the possibly modified leave message
|
|
- s = event.getReason();
|
|
- final IChatBaseComponent ichatbasecomponent = CraftChatMessage.fromString(s, true)[0];
|
|
+ final IChatBaseComponent ichatbasecomponent = PaperAdventure.asVanilla(event.reason()); // Paper - Adventure
|
|
// CraftBukkit end
|
|
|
|
this.networkManager.sendPacket(new PacketPlayOutKickDisconnect(ichatbasecomponent), (future) -> {
|
|
@@ -1485,9 +1485,11 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
*/
|
|
|
|
this.player.p();
|
|
- String quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player);
|
|
- if ((quitMessage != null) && (quitMessage.length() > 0)) {
|
|
- this.minecraftServer.getPlayerList().sendMessage(CraftChatMessage.fromString(quitMessage));
|
|
+ // Paper start - Adventure
|
|
+ net.kyori.adventure.text.Component quitMessage = this.minecraftServer.getPlayerList().disconnect(this.player);
|
|
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
|
|
+ this.minecraftServer.getPlayerList().sendMessage(PaperAdventure.asVanilla(quitMessage));
|
|
+ // Paper end
|
|
}
|
|
// CraftBukkit end
|
|
ITextFilter itextfilter = this.player.Q();
|
|
@@ -1721,15 +1723,20 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
return null;
|
|
}
|
|
|
|
- String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage());
|
|
- PlayerConnection.this.minecraftServer.console.sendMessage(message);
|
|
+ final net.kyori.adventure.text.Component adventure$msg = VanillaChatMessageLogic.formatChat(VanillaChatMessageLogic.displayNameForChat((CraftPlayer) player), queueEvent.getFormat(), queueEvent.getMessage()); // Paper
|
|
+ //String message = String.format(queueEvent.getFormat(), queueEvent.getPlayer().getDisplayName(), queueEvent.getMessage()); // Paper - comment
|
|
+ //PlayerConnection.this.minecraftServer.console.sendMessage(message); // Paper - comment
|
|
+ PlayerConnection.this.minecraftServer.console.sendMessage(adventure$msg); // Paper
|
|
if (((LazyPlayerSet) queueEvent.getRecipients()).isLazy()) {
|
|
+ final IChatBaseComponent vanilla$msg = PaperAdventure.asVanilla(adventure$msg); // Paper
|
|
for (Object player : PlayerConnection.this.minecraftServer.getPlayerList().players) {
|
|
- ((EntityPlayer) player).sendMessage(PlayerConnection.this.player.getUniqueID(), CraftChatMessage.fromString(message));
|
|
+ //((EntityPlayer) player).sendMessage(PlayerConnection.this.player.getUniqueID(), CraftChatMessage.fromString(message)); // Paper - comment
|
|
+ ((EntityPlayer) player).sendMessage(vanilla$msg, PlayerConnection.this.player.getUniqueID());
|
|
}
|
|
} else {
|
|
for (Player player : queueEvent.getRecipients()) {
|
|
- player.sendMessage(PlayerConnection.this.player.getUniqueID(), message);
|
|
+ //player.sendMessage(PlayerConnection.this.player.getUniqueID(), message); // Paper - comment
|
|
+ player.sendMessage(PlayerConnection.this.player.getBukkitEntity(), adventure$msg); // Paper
|
|
}
|
|
}
|
|
return null;
|
|
@@ -1751,15 +1758,20 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
return;
|
|
}
|
|
|
|
- s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
|
|
- minecraftServer.console.sendMessage(s);
|
|
+ final net.kyori.adventure.text.Component adventure$msg = VanillaChatMessageLogic.formatChat(VanillaChatMessageLogic.displayNameForChat((CraftPlayer) player), event.getFormat(), event.getMessage()); // Paper
|
|
+ //s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); // Paper - comment
|
|
+ //minecraftServer.console.sendMessage(s); // Paper - comment
|
|
+ minecraftServer.console.sendMessage(adventure$msg); // Paper
|
|
if (((LazyPlayerSet) event.getRecipients()).isLazy()) {
|
|
+ final IChatBaseComponent vanilla$msg = PaperAdventure.asVanilla(adventure$msg); // Paper
|
|
for (Object recipient : minecraftServer.getPlayerList().players) {
|
|
- ((EntityPlayer) recipient).sendMessage(PlayerConnection.this.player.getUniqueID(), CraftChatMessage.fromString(s));
|
|
+ //((EntityPlayer) recipient).sendMessage(PlayerConnection.this.player.getUniqueID(), CraftChatMessage.fromString(s)); // Paper - comment
|
|
+ ((EntityPlayer) recipient).sendMessage(vanilla$msg, PlayerConnection.this.player.getUniqueID()); // Paper
|
|
}
|
|
} else {
|
|
for (Player recipient : event.getRecipients()) {
|
|
- recipient.sendMessage(PlayerConnection.this.player.getUniqueID(), s);
|
|
+ //recipient.sendMessage(PlayerConnection.this.player.getUniqueID(), s); // Paper - comment
|
|
+ recipient.sendMessage(PlayerConnection.this.player.getBukkitEntity(), adventure$msg); // Paper
|
|
}
|
|
}
|
|
}
|
|
@@ -2511,21 +2523,20 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
return;
|
|
}
|
|
|
|
- // CraftBukkit start
|
|
- Player player = this.server.getPlayer(this.player);
|
|
- int x = packetplayinupdatesign.b().getX();
|
|
- int y = packetplayinupdatesign.b().getY();
|
|
- int z = packetplayinupdatesign.b().getZ();
|
|
- String[] lines = new String[4];
|
|
+ // CraftBukkit start // Paper start - Adventure
|
|
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>();
|
|
|
|
for (int i = 0; i < list.size(); ++i) {
|
|
- lines[i] = EnumChatFormat.a(new ChatComponentText(EnumChatFormat.a((String) list.get(i))).getString());
|
|
+ lines.add(net.kyori.adventure.text.Component.text(list.get(i)));
|
|
}
|
|
- SignChangeEvent event = new SignChangeEvent((org.bukkit.craftbukkit.block.CraftBlock) player.getWorld().getBlockAt(x, y, z), this.server.getPlayer(this.player), lines);
|
|
+ SignChangeEvent event = new SignChangeEvent(org.bukkit.craftbukkit.block.CraftBlock.at(worldserver, blockposition), this.getPlayer(), lines);
|
|
this.server.getPluginManager().callEvent(event);
|
|
|
|
if (!event.isCancelled()) {
|
|
- System.arraycopy(org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines()), 0, tileentitysign.lines, 0, 4);
|
|
+ for (int i = 0; i < 4; i++) {
|
|
+ tileentitysign.a(i, PaperAdventure.asVanilla(event.line(i)));
|
|
+ }
|
|
+ // Paper end
|
|
tileentitysign.isEditable = false;
|
|
}
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
|
index 5b49047b820dbe1f326320b71445ac216bf688b5..dc1055d6e59b455c026d1cf6a0ef8287f2e1ff0c 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -8,6 +8,7 @@ import com.mojang.authlib.GameProfile;
|
|
import com.mojang.serialization.DataResult;
|
|
import com.mojang.serialization.Dynamic;
|
|
import io.netty.buffer.Unpooled;
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
import java.io.File;
|
|
import java.net.SocketAddress;
|
|
import java.text.SimpleDateFormat;
|
|
@@ -23,6 +24,7 @@ import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import com.google.common.base.Predicate;
|
|
import com.google.common.collect.Iterables;
|
|
|
|
@@ -188,7 +190,7 @@ public abstract class PlayerList {
|
|
}
|
|
// CraftBukkit start
|
|
chatmessage.a(EnumChatFormat.YELLOW);
|
|
- String joinMessage = CraftChatMessage.fromComponent(chatmessage);
|
|
+ IChatBaseComponent joinMessage = chatmessage; // Paper - Adventure
|
|
|
|
playerconnection.a(entityplayer.locX(), entityplayer.locY(), entityplayer.locZ(), entityplayer.yaw, entityplayer.pitch);
|
|
this.players.add(entityplayer);
|
|
@@ -197,19 +199,18 @@ public abstract class PlayerList {
|
|
// this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{entityplayer})); // CraftBukkit - replaced with loop below
|
|
|
|
// CraftBukkit start
|
|
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(cserver.getPlayer(entityplayer), joinMessage);
|
|
+ PlayerJoinEvent playerJoinEvent = new org.bukkit.event.player.PlayerJoinEvent(cserver.getPlayer(entityplayer), PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
|
|
cserver.getPluginManager().callEvent(playerJoinEvent);
|
|
|
|
if (!entityplayer.playerConnection.networkManager.isConnected()) {
|
|
return;
|
|
}
|
|
|
|
- joinMessage = playerJoinEvent.getJoinMessage();
|
|
+ final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
|
|
|
- if (joinMessage != null && joinMessage.length() > 0) {
|
|
- for (IChatBaseComponent line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
|
|
- server.getPlayerList().sendAll(new PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.b));
|
|
- }
|
|
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
|
|
+ joinMessage = PaperAdventure.asVanilla(playerJoinEvent.joinMessage()); // Paper - Adventure
|
|
+ server.getPlayerList().sendAll(new PacketPlayOutChat(joinMessage, ChatMessageType.SYSTEM, SystemUtils.b)); // Paper - Adventure
|
|
}
|
|
// CraftBukkit end
|
|
|
|
@@ -406,7 +407,7 @@ public abstract class PlayerList {
|
|
|
|
}
|
|
|
|
- public String disconnect(EntityPlayer entityplayer) { // CraftBukkit - return string
|
|
+ public net.kyori.adventure.text.Component disconnect(EntityPlayer entityplayer) { // Paper - return Component
|
|
WorldServer worldserver = entityplayer.getWorldServer();
|
|
|
|
entityplayer.a(StatisticList.LEAVE_GAME);
|
|
@@ -417,7 +418,7 @@ public abstract class PlayerList {
|
|
entityplayer.closeInventory();
|
|
}
|
|
|
|
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game");
|
|
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, entityplayer.getBukkitEntity().displayName()));
|
|
cserver.getPluginManager().callEvent(playerQuitEvent);
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|
|
@@ -478,7 +479,7 @@ public abstract class PlayerList {
|
|
cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
|
|
// CraftBukkit end
|
|
|
|
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
|
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
|
|
}
|
|
|
|
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
|
|
@@ -524,10 +525,10 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
// return chatmessage;
|
|
- if (!gameprofilebanentry.hasExpired()) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); // Spigot
|
|
+ if (!gameprofilebanentry.hasExpired()) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Spigot // Paper - Adventure
|
|
} else if (!this.isWhitelisted(gameprofile)) {
|
|
chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted");
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure
|
|
} else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) {
|
|
IpBanEntry ipbanentry = this.l.get(socketaddress);
|
|
|
|
@@ -537,17 +538,17 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
// return chatmessage;
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
|
|
} else {
|
|
// return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full") : null;
|
|
if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) {
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_FULL, org.spigotmc.SpigotConfig.serverFullMessage); // Spigot
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
|
|
}
|
|
}
|
|
|
|
cserver.getPluginManager().callEvent(event);
|
|
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
|
- loginlistener.disconnect(event.getKickMessage());
|
|
+ loginlistener.disconnect(PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
|
return null;
|
|
}
|
|
return entity;
|
|
@@ -1068,7 +1069,7 @@ public abstract class PlayerList {
|
|
public void shutdown() {
|
|
// CraftBukkit start - disconnect safely
|
|
for (EntityPlayer player : this.players) {
|
|
- player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
|
|
+ player.playerConnection.disconnect(PaperAdventure.asVanilla(this.server.server.shutdownMessage())); // CraftBukkit - add custom shutdown message // Paper - Adventure
|
|
}
|
|
// CraftBukkit end
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/WorldMap.java b/src/main/java/net/minecraft/server/WorldMap.java
|
|
index e6d97e7ffae3eadac586bad078123cd4aaa69916..d11725d61b888ceb08c4ea30f23d563170ce944d 100644
|
|
--- a/src/main/java/net/minecraft/server/WorldMap.java
|
|
+++ b/src/main/java/net/minecraft/server/WorldMap.java
|
|
@@ -12,6 +12,7 @@ import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
// CraftBukkit start
|
|
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
|
import java.util.UUID;
|
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
@@ -453,7 +454,7 @@ public class WorldMap extends PersistentBase {
|
|
for ( org.bukkit.map.MapCursor cursor : render.cursors) {
|
|
|
|
if (cursor.isVisible()) {
|
|
- icons.add(new MapIcon(MapIcon.Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption())));
|
|
+ icons.add(new MapIcon(MapIcon.Type.a(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), PaperAdventure.asVanilla(cursor.caption()))); // Paper - Adventure
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index 351440f534653c9d315ccaf1e923e03ca6ba01f6..99a242956a56121ab4f108fc58563e1df1537577 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -563,8 +563,11 @@ public final class CraftServer implements Server {
|
|
}
|
|
|
|
@Override
|
|
+ @Deprecated // Paper start
|
|
public int broadcastMessage(String message) {
|
|
- return broadcast(message, BROADCAST_CHANNEL_USERS);
|
|
+ this.sendMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message));
|
|
+ return this.getOnlinePlayers().size() + 1;
|
|
+ // Paper end
|
|
}
|
|
|
|
public Player getPlayer(final EntityPlayer entity) {
|
|
@@ -1302,7 +1305,15 @@ public final class CraftServer implements Server {
|
|
return configuration.getInt("settings.spawn-radius", -1);
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
+ public net.kyori.adventure.text.Component shutdownMessage() {
|
|
+ String msg = getShutdownMessage();
|
|
+ return msg != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(msg) : null;
|
|
+ }
|
|
+ // Paper end
|
|
+ @Override
|
|
+ @Deprecated // Paper
|
|
public String getShutdownMessage() {
|
|
return configuration.getString("settings.shutdown-message");
|
|
}
|
|
@@ -1418,7 +1429,15 @@ public final class CraftServer implements Server {
|
|
}
|
|
|
|
@Override
|
|
+ @Deprecated // Paper
|
|
public int broadcast(String message, String permission) {
|
|
+ // Paper start - Adventure
|
|
+ return this.broadcast(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message), permission);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int broadcast(net.kyori.adventure.text.Component message, String permission) {
|
|
+ // Paper end
|
|
Set<CommandSender> recipients = new HashSet<>();
|
|
for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
|
|
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
|
|
@@ -1426,14 +1445,14 @@ public final class CraftServer implements Server {
|
|
}
|
|
}
|
|
|
|
- BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
|
|
+ BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
|
|
getPluginManager().callEvent(broadcastMessageEvent);
|
|
|
|
if (broadcastMessageEvent.isCancelled()) {
|
|
return 0;
|
|
}
|
|
|
|
- message = broadcastMessageEvent.getMessage();
|
|
+ message = broadcastMessageEvent.message(); // Paper - Adventure
|
|
|
|
for (CommandSender recipient : recipients) {
|
|
recipient.sendMessage(message);
|
|
@@ -1659,6 +1678,14 @@ public final class CraftServer implements Server {
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
|
|
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
|
Validate.isTrue(type.isCreatable(), "Cannot open an inventory of type ", type);
|
|
@@ -1671,13 +1698,28 @@ public final class CraftServer implements Server {
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
|
|
+ Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
|
|
+ return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
|
|
Validate.isTrue(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
|
|
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
+ public Merchant createMerchant(net.kyori.adventure.text.Component title) {
|
|
+ return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
|
|
+ }
|
|
+ // Paper end
|
|
+ @Override
|
|
+ @Deprecated // Paper
|
|
public Merchant createMerchant(String title) {
|
|
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
|
|
}
|
|
@@ -1721,6 +1763,12 @@ public final class CraftServer implements Server {
|
|
return Thread.currentThread().equals(console.serverThread) || console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component motd() {
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(new net.minecraft.server.ChatComponentText(console.getMotd()));
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getMotd() {
|
|
return console.getMotd();
|
|
@@ -2149,5 +2197,15 @@ public final class CraftServer implements Server {
|
|
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
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
|
|
index 21ebceafbf27125761aa08cfe0785f6f05c77592..252b03e287cbe9212c7ec80be049647c4c77d37a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java
|
|
@@ -70,6 +70,19 @@ public class CraftBeacon extends CraftBlockEntityState<TileEntityBeacon> impleme
|
|
this.getSnapshot().secondaryEffect = (effect != null) ? MobEffectList.fromId(effect.getId()) : null;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component customName() {
|
|
+ final TileEntityBeacon be = this.getSnapshot();
|
|
+ return be.customName != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.customName) : 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() {
|
|
TileEntityBeacon beacon = this.getSnapshot();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
index 36ba813e56c6e75528507c415d11e5a57a5f4ae3..a76fa169b0efbf02a4aebbfbd8e38c8f429eba83 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java
|
|
@@ -1,6 +1,7 @@
|
|
package org.bukkit.craftbukkit.block;
|
|
|
|
import net.minecraft.server.ChestLock;
|
|
+import net.minecraft.server.TileEntityBeacon;
|
|
import net.minecraft.server.TileEntityContainer;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.block.Block;
|
|
@@ -32,6 +33,19 @@ public abstract class CraftContainer<T extends TileEntityContainer> extends Craf
|
|
this.getSnapshot().chestLock = (key == null) ? ChestLock.a : new ChestLock(key);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component customName() {
|
|
+ final T be = this.getSnapshot();
|
|
+ return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void customName(final net.kyori.adventure.text.Component customName) {
|
|
+ this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public String getCustomName() {
|
|
T container = this.getSnapshot();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
|
|
index 3a782294c15e2c2592976858e28ec33f049cb65e..772c6b2fa50deac27e5ed112e6d9f9ddd32f668e 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftEnchantingTable.java
|
|
@@ -16,6 +16,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<TileEntityEnchan
|
|
super(material, te);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component customName() {
|
|
+ final TileEntityEnchantTable 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() {
|
|
TileEntityEnchantTable enchant = this.getSnapshot();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
index 81f6bf5533288ed90e2f1f4d421d54195d9650c7..352c8e58418db5e293b179ab801b513fc0ab9be2 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
@@ -13,8 +13,10 @@ import org.bukkit.craftbukkit.util.CraftChatMessage;
|
|
public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements Sign {
|
|
|
|
// Lazily initialized only if requested:
|
|
- private String[] originalLines = null;
|
|
- private String[] lines = null;
|
|
+ // Paper start
|
|
+ private java.util.ArrayList<net.kyori.adventure.text.Component> originalLines = null; // ArrayList for RandomAccess
|
|
+ private java.util.ArrayList<net.kyori.adventure.text.Component> lines = null; // ArrayList for RandomAccess
|
|
+ // Paper end
|
|
|
|
public CraftSign(final Block block) {
|
|
super(block, TileEntitySign.class);
|
|
@@ -24,27 +26,52 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
|
|
super(material, te);
|
|
}
|
|
|
|
+ // Paper start
|
|
@Override
|
|
- public String[] getLines() {
|
|
- if (lines == null) {
|
|
- // Lazy initialization:
|
|
- TileEntitySign sign = this.getSnapshot();
|
|
- lines = new String[sign.lines.length];
|
|
- System.arraycopy(revertComponents(sign.lines), 0, lines, 0, lines.length);
|
|
- originalLines = new String[lines.length];
|
|
- System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
|
|
+ public java.util.List<net.kyori.adventure.text.Component> lines() {
|
|
+ this.loadLines();
|
|
+ return this.lines;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component line(int index) {
|
|
+ this.loadLines();
|
|
+ return this.lines.get(index);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void line(int index, net.kyori.adventure.text.Component line) {
|
|
+ this.loadLines();
|
|
+ this.lines.set(index, line);
|
|
+ }
|
|
+
|
|
+ private void loadLines() {
|
|
+ if (lines != null) {
|
|
+ return;
|
|
}
|
|
- return lines;
|
|
+
|
|
+ // Lazy initialization:
|
|
+ TileEntitySign sign = this.getSnapshot();
|
|
+ lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(sign.lines));
|
|
+ originalLines = new java.util.ArrayList<>(lines);
|
|
+ }
|
|
+ // Paper end
|
|
+ @Override
|
|
+ public String[] getLines() {
|
|
+ this.loadLines();
|
|
+ return this.lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
|
|
}
|
|
|
|
@Override
|
|
public String getLine(int index) throws IndexOutOfBoundsException {
|
|
- return getLines()[index];
|
|
+ this.loadLines();
|
|
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.lines.get(index)); // Paper
|
|
}
|
|
|
|
@Override
|
|
public void setLine(int index, String line) throws IndexOutOfBoundsException {
|
|
- getLines()[index] = line;
|
|
+ this.loadLines();
|
|
+ this.lines.set(index, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(line)); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -72,16 +99,32 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
|
|
super.applyTo(sign);
|
|
|
|
if (lines != null) {
|
|
- for (int i = 0; i < lines.length; i++) {
|
|
- String line = (lines[i] == null) ? "" : lines[i];
|
|
- if (line.equals(originalLines[i])) {
|
|
+ // Paper start
|
|
+ for (int i = 0; i < this.lines.size(); ++i) {
|
|
+ net.kyori.adventure.text.Component component = this.lines.get(i);
|
|
+ net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
|
|
+ if (component.equals(origComp)) {
|
|
continue; // The line contents are still the same, skip.
|
|
}
|
|
- sign.lines[i] = CraftChatMessage.fromString(line)[0];
|
|
+ sign.lines[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(component);
|
|
}
|
|
+ // Paper end
|
|
}
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public static IChatBaseComponent[] sanitizeLines(java.util.List<net.kyori.adventure.text.Component> lines) {
|
|
+ IChatBaseComponent[] components = new IChatBaseComponent[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 ChatComponentText("");
|
|
+ }
|
|
+ }
|
|
+ return components;
|
|
+ }
|
|
+ // Paper end
|
|
public static IChatBaseComponent[] sanitizeLines(String[] lines) {
|
|
IChatBaseComponent[] components = new IChatBaseComponent[4];
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
index 089fe4a3458ed3106fa214f89a7004a5d3c6bb95..5bb8c38c511ec000476afde8038587ddbc7549cc 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java
|
|
@@ -80,4 +80,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
|
public boolean isConversing() {
|
|
return conversationTracker.isConversing();
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
|
|
+ this.sendRawMessage(net.kyori.adventure.text.serializer.plain.PlainComponentSerializer.plain().serialize(message));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java b/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java
|
|
index 34ceee4a81ef4ed05eb9007ca17c223f75f4ff50..11acf5f725a7f2e350a05268a00906ba843c623b 100644
|
|
--- 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;
|
|
return !target.isCompatible(ench.target);
|
|
}
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component displayName(int level) {
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getTranslationComponentForLevel(level));
|
|
+ }
|
|
+ // Paper end
|
|
|
|
public net.minecraft.server.Enchantment getHandle() {
|
|
return target;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
index db7c4011c8b90b6daca2b48a6d9ec447d31f7197..969bf1095bb2a90ad0f1cb1f1e023e056e3855c0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
|
|
@@ -145,6 +145,7 @@ import net.minecraft.server.EntityZombieVillager;
|
|
import net.minecraft.server.IChatBaseComponent;
|
|
import net.minecraft.server.NBTBase;
|
|
import net.minecraft.server.NBTTagCompound;
|
|
+import net.minecraft.server.TileEntityEnchantTable;
|
|
import org.bukkit.Chunk; // Paper
|
|
import org.bukkit.EntityEffect;
|
|
import org.bukkit.Location;
|
|
@@ -768,6 +769,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
|
return getHandle().getVehicle().getBukkitEntity();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component customName() {
|
|
+ final IChatBaseComponent 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);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void setCustomName(String name) {
|
|
// sane limit for name length
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index 96b55867d8bfbc85cb290da9b320ec74b9dbb179..ccfa8243639f487e0f83f012349fcfef94f377cb 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -316,9 +316,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 = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
|
|
|
|
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0]));
|
|
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
|
|
+ player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
|
getHandle().activeContainer = container;
|
|
getHandle().activeContainer.addSlotListener(player);
|
|
}
|
|
@@ -387,8 +390,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
|
|
// Now open the window
|
|
Containers<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
|
|
- String title = inventory.getTitle();
|
|
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0]));
|
|
+
|
|
+ //String title = inventory.getTitle(); // Paper - comment
|
|
+ net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
|
|
+ if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
|
|
+ //player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
|
|
+ player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
|
player.activeContainer = container;
|
|
player.activeContainer.addSlotListener(player);
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 8428ef53e0408c4a7f74cc03e7e238be9c2f1888..28368aa85e25ad5ee1e35255f093fd3f5a7a15bf 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -239,14 +239,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
@Override
|
|
public String getDisplayName() {
|
|
+ if(true) return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.getHandle().adventure$displayName); // Paper
|
|
return getHandle().displayName;
|
|
}
|
|
|
|
@Override
|
|
public void setDisplayName(final String name) {
|
|
+ this.getHandle().adventure$displayName = name != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(name) : null; if (true) return; // Paper
|
|
getHandle().displayName = name == null ? getName() : name;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public void playerListName(net.kyori.adventure.text.Component name) {
|
|
+ getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
|
|
+ for (EntityPlayer player : server.getHandle().players) {
|
|
+ if (player.getBukkitEntity().canSee(this)) {
|
|
+ player.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME, getHandle()));
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component playerListName() {
|
|
+ return getHandle().listName == null ? net.kyori.adventure.text.Component.text(getName()) : io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().listName);
|
|
+ }
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component playerListHeader() {
|
|
+ return playerListHeader;
|
|
+ }
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component playerListFooter() {
|
|
+ return playerListFooter;
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getPlayerListName() {
|
|
return getHandle().listName == null ? getName() : CraftChatMessage.fromComponent(getHandle().listName);
|
|
@@ -265,35 +290,35 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
}
|
|
|
|
- private IChatBaseComponent playerListHeader;
|
|
- private IChatBaseComponent playerListFooter;
|
|
+ private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
|
|
+ private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
|
|
|
|
@Override
|
|
public String getPlayerListHeader() {
|
|
- return (playerListHeader == null) ? null : CraftChatMessage.fromComponent(playerListHeader);
|
|
+ return (playerListHeader == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(playerListHeader); // Paper - Adventure
|
|
}
|
|
|
|
@Override
|
|
public String getPlayerListFooter() {
|
|
- return (playerListFooter == null) ? null : CraftChatMessage.fromComponent(playerListFooter);
|
|
+ return (playerListFooter == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(playerListFooter); // Paper - Adventure
|
|
}
|
|
|
|
@Override
|
|
public void setPlayerListHeader(String header) {
|
|
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
|
|
+ this.playerListHeader = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
|
|
updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
@Override
|
|
public void setPlayerListFooter(String footer) {
|
|
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
|
|
+ this.playerListFooter = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
|
|
updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
@Override
|
|
public void setPlayerListHeaderFooter(String header, String footer) {
|
|
- this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
|
|
- this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
|
|
+ this.playerListHeader = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
|
|
+ this.playerListFooter = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
|
|
updatePlayerListHeaderFooter();
|
|
}
|
|
|
|
@@ -301,8 +326,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
if (getHandle().playerConnection == null) return;
|
|
|
|
PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
|
|
- packet.header = (this.playerListHeader == null) ? new ChatComponentText("") : this.playerListHeader;
|
|
- packet.footer = (this.playerListFooter == null) ? new ChatComponentText("") : this.playerListFooter;
|
|
+ packet.header = (this.playerListHeader == null) ? new ChatComponentText("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListHeader); // Paper - Adventure
|
|
+ packet.footer = (this.playerListFooter == null) ? new ChatComponentText("") : io.papermc.paper.adventure.PaperAdventure.asVanilla(this.playerListFooter); // Paper - Adventure
|
|
getHandle().playerConnection.sendPacket(packet);
|
|
}
|
|
|
|
@@ -334,6 +359,19 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
getHandle().playerConnection.disconnect(message == null ? "" : message);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public void kick(final net.kyori.adventure.text.Component message) {
|
|
+ org.spigotmc.AsyncCatcher.catchOp("player kick");
|
|
+ final PlayerConnection connection = this.getHandle().playerConnection;
|
|
+ if (connection != null) {
|
|
+ connection.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(
|
|
+ message == null ? net.kyori.adventure.text.Component.empty() : message
|
|
+ ));
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void setCompassTarget(Location loc) {
|
|
if (getHandle().playerConnection == null) return;
|
|
@@ -548,6 +586,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
getHandle().playerConnection.sendPacket(packet);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public void sendSignChange(Location loc, List<net.kyori.adventure.text.Component> lines) {
|
|
+ this.sendSignChange(loc, lines, org.bukkit.DyeColor.BLACK);
|
|
+ }
|
|
+ @Override
|
|
+ public void sendSignChange(Location loc, List<net.kyori.adventure.text.Component> lines, DyeColor dyeColor) {
|
|
+ if (getHandle().playerConnection == 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");
|
|
+ }
|
|
+ IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
|
|
+ this.sendSignChange0(components, loc, dyeColor);
|
|
+ }
|
|
+
|
|
+ private void sendSignChange0(IChatBaseComponent[] components, Location loc, DyeColor dyeColor) {
|
|
+ TileEntitySign sign = new TileEntitySign();
|
|
+ sign.setPosition(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
|
+ sign.setColor(EnumColor.fromColorIndex(dyeColor.getWoolData()));
|
|
+ System.arraycopy(components, 0, sign.lines, 0, sign.lines.length);
|
|
+
|
|
+ getHandle().playerConnection.sendPacket(sign.getUpdatePacket());
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public void sendSignChange(Location loc, String[] lines) {
|
|
sendSignChange(loc, lines, DyeColor.BLACK);
|
|
@@ -570,12 +639,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
IChatBaseComponent[] components = CraftSign.sanitizeLines(lines);
|
|
- TileEntitySign sign = new TileEntitySign();
|
|
+ /*TileEntitySign sign = new TileEntitySign(); // Paper
|
|
sign.setPosition(new BlockPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
|
sign.setColor(EnumColor.fromColorIndex(dyeColor.getWoolData()));
|
|
System.arraycopy(components, 0, sign.lines, 0, sign.lines.length);
|
|
|
|
- getHandle().playerConnection.sendPacket(sign.getUpdatePacket());
|
|
+ getHandle().playerConnection.sendPacket(sign.getUpdatePacket());*/ // Paper
|
|
+ this.sendSignChange0(components, loc, dyeColor); // Paper
|
|
}
|
|
|
|
@Override
|
|
@@ -1705,6 +1775,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
return (getHandle().clientViewDistance == null) ? Bukkit.getViewDistance() : getHandle().clientViewDistance;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public java.util.Locale locale() {
|
|
+ return getHandle().adventure$locale;
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getLocale() {
|
|
return getHandle().locale;
|
|
@@ -1728,6 +1804,137 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
getInventory().setItemInMainHand(hand);
|
|
}
|
|
|
|
+ // 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;
|
|
+ }
|
|
+
|
|
+ @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) {
|
|
+ final PacketPlayOutChat packet = new PacketPlayOutChat(null, type == net.kyori.adventure.audience.MessageType.CHAT ? net.minecraft.server.ChatMessageType.CHAT : net.minecraft.server.ChatMessageType.SYSTEM, identity.uuid());
|
|
+ packet.adventure$message = message;
|
|
+ this.getHandle().playerConnection.sendPacket(packet);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void sendActionBar(final net.kyori.adventure.text.Component message) {
|
|
+ final PacketPlayOutTitle packet = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.ACTIONBAR, null);
|
|
+ packet.adventure$text = message;
|
|
+ this.getHandle().playerConnection.sendPacket(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 PlayerConnection connection = this.getHandle().playerConnection;
|
|
+ if (connection == null) return;
|
|
+ final PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
|
|
+ packet.adventure$header = (this.playerListHeader == null) ? net.kyori.adventure.text.Component.empty() : this.playerListHeader;
|
|
+ packet.adventure$footer = (this.playerListFooter == null) ? net.kyori.adventure.text.Component.empty() : this.playerListFooter;
|
|
+ connection.sendPacket(packet);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void showTitle(final net.kyori.adventure.title.Title title) {
|
|
+ final PlayerConnection connection = this.getHandle().playerConnection;
|
|
+ final net.kyori.adventure.title.Title.Times times = title.times();
|
|
+ if (times != null) {
|
|
+ connection.sendPacket(new PacketPlayOutTitle(ticks(times.fadeIn()), ticks(times.fadeOut()), ticks(times.stay())));
|
|
+ }
|
|
+ final PacketPlayOutTitle sp = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, null);
|
|
+ sp.adventure$text = title.subtitle();
|
|
+ connection.sendPacket(sp);
|
|
+ final PacketPlayOutTitle tp = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, null);
|
|
+ tp.adventure$text = title.title();
|
|
+ connection.sendPacket(tp);
|
|
+ }
|
|
+
|
|
+ private static int ticks(final java.time.Duration duration) {
|
|
+ if (duration == null) {
|
|
+ return -1;
|
|
+ }
|
|
+ return (int) (duration.toMillis() / 50L);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void clearTitle() {
|
|
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.CLEAR, null));
|
|
+ }
|
|
+
|
|
+ // 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 Vec3D pos = this.getHandle().getPositionVector();
|
|
+ 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 MinecraftKey name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
|
|
+ final java.util.Optional<net.minecraft.server.SoundEffect> event = net.minecraft.server.IRegistry.SOUND_EVENT.getOptional(name);
|
|
+ if (event.isPresent()) {
|
|
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(event.get(), io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), x, y, z, sound.volume(), sound.pitch()));
|
|
+ } else {
|
|
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), new Vec3D(x, y, z), sound.volume(), sound.pitch()));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
|
|
+ this.getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(
|
|
+ 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.server.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
|
|
+ final EntityPlayer player = this.getHandle();
|
|
+ final PlayerConnection connection = player.playerConnection;
|
|
+ final net.minecraft.server.PlayerInventory inventory = player.inventory;
|
|
+ final int slot = inventory.items.size() + inventory.itemInHandIndex;
|
|
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutSetSlot(0, slot, item));
|
|
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutOpenBook(net.minecraft.server.EnumHand.MAIN_HAND));
|
|
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutSetSlot(0, slot, inventory.getItemInHand()));
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
// Spigot start
|
|
private final Player.Spigot spigot = new Player.Spigot()
|
|
{
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index f6688c7151734f4bdb63a71e810996e04b09e22c..6c153971dd72ff9df9725f889032cfb59bbe31e3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -766,7 +766,7 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
|
|
- public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
|
|
+ public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, boolean keepInventory) { // Paper - Adventure
|
|
CraftPlayer entity = victim.getBukkitEntity();
|
|
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
|
|
event.setKeepInventory(keepInventory);
|
|
@@ -792,7 +792,7 @@ public class CraftEventFactory {
|
|
* 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
|
|
index 8c714c7430c0a6b8fd7f4a158d9a271e1642bd7a..97c9b528f9ee8eb156a311d68d5d897fb1d837b7 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
|
|
@@ -39,6 +39,7 @@ public class CraftContainer extends Container {
|
|
|
|
private final InventoryView view;
|
|
private InventoryType cachedType;
|
|
+ private net.kyori.adventure.text.Component adventure$title; // Paper
|
|
private String cachedTitle;
|
|
private Container delegate;
|
|
private final int cachedSize;
|
|
@@ -50,7 +51,9 @@ public class CraftContainer extends Container {
|
|
IInventory top = ((CraftInventory) view.getTopInventory()).getInventory();
|
|
PlayerInventory bottom = (PlayerInventory) ((CraftInventory) view.getBottomInventory()).getInventory();
|
|
cachedType = view.getType();
|
|
- cachedTitle = view.getTitle();
|
|
+ this.adventure$title = view.title(); // Paper
|
|
+ if (this.adventure$title == null) this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(view.getTitle()); // Paper
|
|
+ //cachedTitle = view.getTitle(); // Paper - comment
|
|
cachedSize = getSize();
|
|
setupSlots(top, bottom, player);
|
|
}
|
|
@@ -77,6 +80,13 @@ public class CraftContainer extends Container {
|
|
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();
|
|
@@ -95,7 +105,8 @@ public class CraftContainer extends Container {
|
|
|
|
@Override
|
|
public boolean c(EntityHuman entityhuman) {
|
|
- if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) {
|
|
+ if (cachedType == view.getType() && cachedSize == getSize() && this.adventure$title.equals(view.title())) { // Paper
|
|
+ //if (cachedType == view.getType() && cachedSize == getSize() && cachedTitle.equals(view.getTitle())) { // Paper - comment
|
|
return true;
|
|
}
|
|
// If the window type has changed for some reason, update the player
|
|
@@ -103,7 +114,9 @@ public class CraftContainer extends Container {
|
|
// as good a place as any to put something like this.
|
|
boolean typeChanged = (cachedType != view.getType());
|
|
cachedType = view.getType();
|
|
- cachedTitle = view.getTitle();
|
|
+ this.adventure$title = view.title(); // Paper
|
|
+ if (this.adventure$title == null) this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(view.getTitle()); // Paper
|
|
+ //cachedTitle = view.getTitle(); // Paper - comment
|
|
if (view.getPlayer() instanceof CraftPlayer) {
|
|
CraftPlayer player = (CraftPlayer) view.getPlayer();
|
|
Containers<?> type = getNotchInventoryType(view.getTopInventory());
|
|
@@ -115,7 +128,8 @@ public class CraftContainer extends Container {
|
|
setupSlots(top, bottom, player.getHandle());
|
|
}
|
|
int size = getSize();
|
|
- player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle)));
|
|
+ player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure$title))); // Paper
|
|
+ //player.getHandle().playerConnection.sendPacket(new PacketPlayOutOpenWindow(this.windowId, type, new ChatComponentText(cachedTitle))); // Paper - comment
|
|
player.updateInventory();
|
|
}
|
|
return true;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryCustom.java
|
|
index e1dfdb23f7d755b19cf14c0bf15358095406e9a0..ad94839f4f8265dd1bfe26b71fbaeb3cdb1a1456 100644
|
|
--- 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");
|
|
this.items = NonNullList.a(size, ItemStack.b);
|
|
this.title = title;
|
|
+ this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title);
|
|
this.viewers = new ArrayList<HumanEntity>();
|
|
this.owner = owner;
|
|
this.type = InventoryType.CHEST;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public MinecraftInventory(final InventoryHolder owner, final int size, final net.kyori.adventure.text.Component title) {
|
|
+ Validate.notNull(title, "Title cannot be null");
|
|
+ this.items = NonNullList.a(size, ItemStack.b);
|
|
+ this.title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
|
|
+ this.adventure$title = title;
|
|
+ this.viewers = new ArrayList<HumanEntity>();
|
|
+ this.owner = owner;
|
|
+ this.type = InventoryType.CHEST;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public int getSize() {
|
|
return items.size();
|
|
@@ -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() {
|
|
return title;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryView.java
|
|
index 4c6492a92821916fa98d6409a8ebf17f255535ad..80759d640d5af1620712aadbfb5f1ab7bc379f4b 100644
|
|
--- 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 {
|
|
return CraftItemStack.asCraftMirror(container.getSlot(slot).getItem());
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component title() {
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public String getTitle() {
|
|
return CraftChatMessage.fromComponent(container.getTitle());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
index 89a3617068421bb86baf4e8bfd9df2d0626adff7..a50eb746b8774a089c39652d534920acf708b137 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java
|
|
@@ -334,4 +334,12 @@ public final class CraftItemFactory implements ItemFactory {
|
|
public Material updateMaterial(ItemMeta meta, Material material) throws IllegalArgumentException {
|
|
return ((CraftMetaItem) meta).updateMaterial(material);
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
|
|
+ final net.minecraft.server.NBTTagCompound 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))));
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantCustom.java
|
|
index 9f6e797d34e5ad21a496c89f5a45ddb0638d3adc..115ee3785b4e0ba6a235bbb31b643aa596705401 100644
|
|
--- 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));
|
|
getMerchant().craftMerchant = this;
|
|
}
|
|
+ // Paper start
|
|
+ public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
|
|
+ super(new MinecraftMerchant(title));
|
|
+ getMerchant().craftMerchant = this;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public String toString() {
|
|
@@ -37,10 +44,17 @@ public class CraftMerchantCustom extends CraftMerchant {
|
|
private World tradingWorld;
|
|
protected CraftMerchant craftMerchant;
|
|
|
|
+ @Deprecated // Paper - Adventure
|
|
public MinecraftMerchant(String title) {
|
|
Validate.notNull(title, "Title cannot be null");
|
|
this.title = new ChatComponentText(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
|
|
index a0cc04cb6d1f02df3018320b4147bd0b156dd81c..fb4d39a4cf101749f74da9c48bb3a27b0188fbeb 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java
|
|
@@ -1,13 +1,16 @@
|
|
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;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
+import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
import net.minecraft.server.IChatBaseComponent;
|
|
import net.minecraft.server.NBTTagCompound;
|
|
import net.minecraft.server.NBTTagList;
|
|
@@ -267,6 +270,135 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
this.generation = (generation == null) ? null : generation.ordinal();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component title() {
|
|
+ return this.title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.title);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
|
|
+ this.setTitle(title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title));
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component author() {
|
|
+ return this.author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.author);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
|
|
+ this.setAuthor(author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(author));
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component page(final int page) {
|
|
+ Validate.isTrue(isValidPage(page), "Invalid page number");
|
|
+ return this instanceof CraftMetaBookSigned ? GsonComponentSerializer.gson().deserialize(pages.get(page - 1)) : LegacyComponentSerializer.legacySection().deserialize(pages.get(page - 1));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void page(final int page, net.kyori.adventure.text.Component data) {
|
|
+ if (!isValidPage(page)) {
|
|
+ throw new IllegalArgumentException("Invalid page number " + page + "/" + pages.size());
|
|
+ }
|
|
+ if (data == null) {
|
|
+ data = net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+ pages.set(page - 1, this instanceof CraftMetaBookSigned ? GsonComponentSerializer.gson().serialize(data) : LegacyComponentSerializer.legacySection().serialize(data));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<net.kyori.adventure.text.Component> pages() {
|
|
+ if (this.pages == null) return ImmutableList.of();
|
|
+ if (this instanceof CraftMetaBookSigned)
|
|
+ return pages.stream().map(GsonComponentSerializer.gson()::deserialize).collect(ImmutableList.toImmutableList());
|
|
+ else
|
|
+ return pages.stream().map(LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
|
|
+ if (this.pages != null) this.pages.clear();
|
|
+ for (net.kyori.adventure.text.Component page : pages) {
|
|
+ addPages(page);
|
|
+ }
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMeta pages(net.kyori.adventure.text.Component... pages) {
|
|
+ if (this.pages != null) this.pages.clear();
|
|
+ addPages(pages);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void addPages(net.kyori.adventure.text.Component... pages) {
|
|
+ if (this.pages == null) this.pages = new ArrayList<>();
|
|
+ for (net.kyori.adventure.text.Component page : pages) {
|
|
+ if (this.pages.size() >= MAX_PAGES) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (page == null) {
|
|
+ page = net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+
|
|
+ this.pages.add(this instanceof CraftMetaBookSigned ? GsonComponentSerializer.gson().serialize(page) : LegacyComponentSerializer.legacySection().serialize(page));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private CraftMetaBook(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages) {
|
|
+ super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK));
|
|
+ this.title = title == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
|
|
+ this.author = author == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(author);
|
|
+ this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(LegacyComponentSerializer.legacySection()::serialize).collect(java.util.stream.Collectors.toList());
|
|
+ }
|
|
+
|
|
+ static final class CraftMetaBookBuilder implements BookMetaBuilder {
|
|
+ private net.kyori.adventure.text.Component title = null;
|
|
+ private net.kyori.adventure.text.Component author = null;
|
|
+ private final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
|
|
+ this.title = title;
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
|
|
+ this.author = author;
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
|
|
+ this.pages.add(page);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
|
|
+ java.util.Collections.addAll(this.pages, pages);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
|
|
+ this.pages.addAll(pages);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public BookMeta build() {
|
|
+ return new CraftMetaBook(title, author, pages);
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getPage(final int page) {
|
|
Validate.isTrue(isValidPage(page), "Invalid page number");
|
|
@@ -411,7 +543,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta {
|
|
}
|
|
|
|
@Override
|
|
- Builder<String, Object> serialize(Builder<String, Object> builder) {
|
|
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
|
super.serialize(builder);
|
|
|
|
if (hasTitle()) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java
|
|
index 0bd396ebee14bd4014744983b273dad832211178..06eec130166f7fef7674ea402123f2edf9f4e455 100644
|
|
--- 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.server.NBTTagCompound;
|
|
import org.bukkit.Material;
|
|
@@ -84,7 +84,7 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta {
|
|
}
|
|
|
|
@Override
|
|
- Builder<String, Object> serialize(Builder<String, Object> builder) {
|
|
+ ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
|
super.serialize(builder);
|
|
return builder;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 60e04343b4b10b1de0bbd033b148a9da41b66aad..ac6be3da812c927a5486809c096b5a2e1aba617b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -745,6 +745,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers());
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component displayName() {
|
|
+ return displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(displayName);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
|
|
+ this.displayName = displayName == null ? null : net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(displayName);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public String getDisplayName() {
|
|
return CraftChatMessage.fromJSONComponent(displayName);
|
|
@@ -780,6 +792,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
return this.lore != null && !this.lore.isEmpty();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public List<net.kyori.adventure.text.Component> lore() {
|
|
+ return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventureFromJson(this.lore) : null;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void lore(final List<net.kyori.adventure.text.Component> lore) {
|
|
+ this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asJson(lore) : null;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public boolean hasRepairCost() {
|
|
return repairCost > 0;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftCustomInventoryConverter.java
|
|
index 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
|
|
index b51321c8dd70a90ab149f456c7ffb4587c4fbd34..94d807c5d09f165c6eedd0a1c4026c2b833806a0 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftInventoryCreator.java
|
|
@@ -43,6 +43,17 @@ public final class CraftInventoryCreator {
|
|
return converterMap.get(type).createInventory(holder, type);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ // Paper start
|
|
+ if (holder != null) {
|
|
+ return DEFAULT_CONVERTER.createInventory(holder, type, title);
|
|
+ }
|
|
+ //noinspection ConstantConditions // Paper end
|
|
+ return converterMap.get(type).createInventory(holder, type, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
|
return converterMap.get(type).createInventory(holder, type, title);
|
|
}
|
|
@@ -51,6 +62,12 @@ public final class CraftInventoryCreator {
|
|
return DEFAULT_CONVERTER.createInventory(holder, size);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
|
|
+ return DEFAULT_CONVERTER.createInventory(holder, size, title);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public Inventory createInventory(InventoryHolder holder, int size, String title) {
|
|
return DEFAULT_CONVERTER.createInventory(holder, size, title);
|
|
}
|
|
@@ -59,6 +76,10 @@ public final class CraftInventoryCreator {
|
|
|
|
Inventory createInventory(InventoryHolder holder, InventoryType type);
|
|
|
|
+ // Paper start
|
|
+ Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
|
|
+ // Paper end
|
|
+
|
|
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java
|
|
index ad91eabb47511268d0cf307d941070800ce9bd3f..b99ce1217461595f5ccc8c7565ec3b65d1df83d9 100644
|
|
--- 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
|
|
return getInventory(getTileEntity());
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ IInventory te = getTileEntity();
|
|
+ if (te instanceof TileEntityLootable) {
|
|
+ ((TileEntityLootable) te).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
|
|
+ }
|
|
+
|
|
+ return getInventory(te);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
|
IInventory te = getTileEntity();
|
|
@@ -54,6 +66,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
|
return furnace;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ IInventory tileEntity = getTileEntity();
|
|
+ ((TileEntityFurnace) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
|
|
+ return getInventory(tileEntity);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
|
IInventory tileEntity = getTileEntity();
|
|
@@ -74,6 +95,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
|
return new TileEntityBrewingStand();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
|
+ // BrewingStand does not extend TileEntityLootable
|
|
+ IInventory tileEntity = getTileEntity();
|
|
+ if (tileEntity instanceof TileEntityBrewingStand) {
|
|
+ ((TileEntityBrewingStand) 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
|
|
index 5eaea24d253d92078709af2a7d7fd0beda3e5520..37faafaf7136e02aa1c76d841b8f47c0f6b9a36c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java
|
|
@@ -31,6 +31,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
|
|
return objective.getName();
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
|
|
+ }
|
|
+ @Override
|
|
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
|
|
+ if (displayName == null) {
|
|
+ displayName = net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
|
|
+ }
|
|
+ // Paper end
|
|
@Override
|
|
public String getDisplayName() throws IllegalStateException {
|
|
CraftScoreboard scoreboard = checkState();
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
index e3036fe23fa2be100044332c432d1ad5b4872823..d05959c7884d7ba19ff1a507c7d07c52bec038f6 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java
|
|
@@ -28,6 +28,27 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|
public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException {
|
|
return registerNewObjective(name, criteria, name);
|
|
}
|
|
+ // 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);
|
|
+ ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
|
|
+ return new CraftObjective(this, objective);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException {
|
|
@@ -36,7 +57,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");
|
|
@@ -46,7 +67,8 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
|
|
|
CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria);
|
|
ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType));
|
|
- return new CraftObjective(this, objective);
|
|
+ return new CraftObjective(this, objective);*/ // Paper
|
|
+ return registerNewObjective(name, criteria, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(displayName)); // Paper
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
index 0fba3d2a8d3bd7ec615d137e4625a7f357729d8d..b900aaf66f25e41956e7a4370b887fd4ed530570 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java
|
|
@@ -27,6 +27,55 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
|
|
|
return team.getName();
|
|
}
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
|
|
+ }
|
|
+ @Override
|
|
+ public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
|
|
+ if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
|
|
+ }
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPrefix());
|
|
+ }
|
|
+ @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.setPrefix(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.getSuffix());
|
|
+ }
|
|
+ @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.setSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
|
|
+ }
|
|
+ @Override
|
|
+ public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
|
|
+ CraftScoreboard scoreboard = checkState();
|
|
+ if (team.getColor().getHexValue() == 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().getHexValue());
|
|
+ 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
|
|
index 1582a799e456402453c43c2e0c6b8a194951a9dd..0dfb9ddad426e962db1216d1f490c1c5e2210adf 100644
|
|
--- 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(IChatBaseComponent 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;
|