2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Techcable <Techcable@outlook.com>
|
|
|
|
Date: Thu, 3 Mar 2016 02:32:10 -0600
|
|
|
|
Subject: [PATCH] Player Tab List and Title APIs
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/FriendlyByteBuf.java b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
2023-03-14 19:36:39 +01:00
|
|
|
index 9020bc6d9ff6bc0c9b3f00470813f3258554cf45..c2f56f4628e42c130e4c55030432cb43aa0d8458 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/FriendlyByteBuf.java
|
2023-03-14 19:36:39 +01:00
|
|
|
@@ -548,6 +548,11 @@ public class FriendlyByteBuf extends ByteBuf {
|
2021-06-11 14:02:28 +02:00
|
|
|
public FriendlyByteBuf writeComponent(final net.kyori.adventure.text.Component component) {
|
|
|
|
return this.writeUtf(PaperAdventure.asJsonString(component, this.adventure$locale), 262144);
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Deprecated
|
|
|
|
+ public FriendlyByteBuf writeComponent(final net.md_5.bungee.api.chat.BaseComponent[] component) {
|
|
|
|
+ return this.writeUtf(net.md_5.bungee.chat.ComponentSerializer.toString(component), 262144);
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
public FriendlyByteBuf writeComponent(Component text) {
|
2021-06-16 01:41:38 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
|
|
|
|
index c44a276d201fdfa5144d45d319d7761583c60639..f68a1a6dc6add9496e25cb52c318e086e356e2bb 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetSubtitleTextPacket.java
|
|
|
|
@@ -7,6 +7,7 @@ import net.minecraft.network.protocol.Packet;
|
|
|
|
public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacketListener> {
|
|
|
|
private final Component text;
|
|
|
|
public net.kyori.adventure.text.Component adventure$text; // Paper
|
|
|
|
+ public net.md_5.bungee.api.chat.BaseComponent[] components; // Paper
|
|
|
|
|
|
|
|
public ClientboundSetSubtitleTextPacket(Component subtitle) {
|
|
|
|
this.text = subtitle;
|
|
|
|
@@ -21,6 +22,8 @@ public class ClientboundSetSubtitleTextPacket implements Packet<ClientGamePacket
|
|
|
|
// Paper start
|
|
|
|
if (this.adventure$text != null) {
|
|
|
|
buf.writeComponent(this.adventure$text);
|
|
|
|
+ } else if (this.components != null) {
|
|
|
|
+ buf.writeComponent(this.components);
|
|
|
|
} else
|
|
|
|
// Paper end
|
|
|
|
buf.writeComponent(this.text);
|
|
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
|
|
|
|
index bd808eb312ade7122973a47f4b96505829511da5..bf0f9cab7c66c089f35b851e799ba4a43420b437 100644
|
|
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
|
|
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetTitleTextPacket.java
|
|
|
|
@@ -7,6 +7,7 @@ import net.minecraft.network.protocol.Packet;
|
|
|
|
public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketListener> {
|
|
|
|
private final Component text;
|
|
|
|
public net.kyori.adventure.text.Component adventure$text; // Paper
|
|
|
|
+ public net.md_5.bungee.api.chat.BaseComponent[] components; // Paper
|
|
|
|
|
|
|
|
public ClientboundSetTitleTextPacket(Component title) {
|
|
|
|
this.text = title;
|
|
|
|
@@ -21,6 +22,8 @@ public class ClientboundSetTitleTextPacket implements Packet<ClientGamePacketLis
|
|
|
|
// Paper start
|
|
|
|
if (this.adventure$text != null) {
|
|
|
|
buf.writeComponent(this.adventure$text);
|
|
|
|
+ } else if (this.components != null) {
|
|
|
|
+ buf.writeComponent(this.components);
|
|
|
|
} else
|
|
|
|
// Paper end
|
|
|
|
buf.writeComponent(this.text);
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2023-06-07 20:31:32 +02:00
|
|
|
index b1f69f7183b2765695446fd587527def4dd8c4c9..20daf74908ecb0c569bd92260c82d61bb5555cfd 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
package org.bukkit.craftbukkit.entity;
|
|
|
|
|
|
|
|
+import com.destroystokyo.paper.Title;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import com.google.common.io.BaseEncoding;
|
2023-06-07 20:31:32 +02:00
|
|
|
@@ -283,6 +284,100 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
|
|
|
|
+ if (header != null) {
|
|
|
|
+ String headerJson = net.md_5.bungee.chat.ComponentSerializer.toString(header);
|
|
|
|
+ playerListHeader = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(headerJson);
|
|
|
|
+ } else {
|
|
|
|
+ playerListHeader = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (footer != null) {
|
|
|
|
+ String footerJson = net.md_5.bungee.chat.ComponentSerializer.toString(footer);
|
|
|
|
+ playerListFooter = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(footerJson);
|
|
|
|
+ } else {
|
|
|
|
+ playerListFooter = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updatePlayerListHeaderFooter();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setPlayerListHeaderFooter(BaseComponent header, BaseComponent footer) {
|
|
|
|
+ this.setPlayerListHeaderFooter(header == null ? null : new BaseComponent[]{header},
|
|
|
|
+ footer == null ? null : new BaseComponent[]{footer});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setTitleTimes(int fadeInTicks, int stayTicks, int fadeOutTicks) {
|
2021-06-12 04:23:18 +02:00
|
|
|
+ getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(fadeInTicks, stayTicks, fadeOutTicks));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setSubtitle(BaseComponent[] subtitle) {
|
2021-06-16 01:41:38 +02:00
|
|
|
+ final ClientboundSetSubtitleTextPacket packet = new ClientboundSetSubtitleTextPacket((net.minecraft.network.chat.Component) null);
|
|
|
|
+ packet.components = subtitle;
|
|
|
|
+ getHandle().connection.send(packet);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setSubtitle(BaseComponent subtitle) {
|
|
|
|
+ setSubtitle(new BaseComponent[]{subtitle});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void showTitle(BaseComponent[] title) {
|
2021-06-16 01:41:38 +02:00
|
|
|
+ final ClientboundSetTitleTextPacket packet = new ClientboundSetTitleTextPacket((net.minecraft.network.chat.Component) null);
|
|
|
|
+ packet.components = title;
|
|
|
|
+ getHandle().connection.send(packet);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void showTitle(BaseComponent title) {
|
|
|
|
+ showTitle(new BaseComponent[]{title});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void showTitle(BaseComponent[] title, BaseComponent[] subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
|
|
|
|
+ setTitleTimes(fadeInTicks, stayTicks, fadeOutTicks);
|
|
|
|
+ setSubtitle(subtitle);
|
|
|
|
+ showTitle(title);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void showTitle(BaseComponent title, BaseComponent subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
|
|
|
|
+ setTitleTimes(fadeInTicks, stayTicks, fadeOutTicks);
|
|
|
|
+ setSubtitle(subtitle);
|
|
|
|
+ showTitle(title);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void sendTitle(Title title) {
|
|
|
|
+ Preconditions.checkNotNull(title, "Title is null");
|
|
|
|
+ setTitleTimes(title.getFadeIn(), title.getStay(), title.getFadeOut());
|
|
|
|
+ setSubtitle(title.getSubtitle() == null ? new BaseComponent[0] : title.getSubtitle());
|
|
|
|
+ showTitle(title.getTitle());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateTitle(Title title) {
|
|
|
|
+ Preconditions.checkNotNull(title, "Title is null");
|
|
|
|
+ setTitleTimes(title.getFadeIn(), title.getStay(), title.getFadeOut());
|
|
|
|
+ if (title.getSubtitle() != null) {
|
|
|
|
+ setSubtitle(title.getSubtitle());
|
|
|
|
+ }
|
|
|
|
+ showTitle(title.getTitle());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void hideTitle() {
|
2021-06-12 04:23:18 +02:00
|
|
|
+ getHandle().connection.send(new ClientboundClearTitlesPacket(false));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public String getDisplayName() {
|
|
|
|
if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
|