2019-06-26 03:18:50 +08:00
|
|
|
From e3b7c7b79f0a486813a8d148e919771c456bb9f9 Mon Sep 17 00:00:00 2001
|
2016-03-01 07:09:49 +08:00
|
|
|
From: Techcable <Techcable@outlook.com>
|
|
|
|
Date: Thu, 3 Mar 2016 02:32:10 -0600
|
|
|
|
Subject: [PATCH] Player Tab List and Title APIs
|
|
|
|
|
|
|
|
|
2018-09-01 18:09:13 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/IChatBaseComponent.java b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
2019-06-14 10:27:40 +08:00
|
|
|
index 2dc6342d46..1d0de5d9a7 100644
|
2018-09-01 18:09:13 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
2019-04-26 09:24:00 +08:00
|
|
|
@@ -433,6 +433,7 @@ public interface IChatBaseComponent extends Message, Iterable<IChatBaseComponent
|
2019-01-01 11:15:55 +08:00
|
|
|
return IChatBaseComponent.ChatSerializer.a.toJsonTree(ichatbasecomponent);
|
2018-09-01 18:09:13 +08:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:33:50 +08:00
|
|
|
+ @Nullable public static IChatBaseComponent jsonToComponent(String json) { return a(json);} // Paper - OBFHELPER
|
2018-09-01 18:09:13 +08:00
|
|
|
@Nullable
|
|
|
|
public static IChatBaseComponent a(String s) {
|
2019-01-01 11:15:55 +08:00
|
|
|
return (IChatBaseComponent) ChatDeserializer.a(IChatBaseComponent.ChatSerializer.a, s, IChatBaseComponent.class, false);
|
2016-03-23 14:05:09 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutTitle.java b/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
2019-06-14 10:27:40 +08:00
|
|
|
index 3a6e780007..535056c64e 100644
|
2016-03-23 14:05:09 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PacketPlayOutTitle.java
|
2019-04-26 09:24:00 +08:00
|
|
|
@@ -43,12 +43,29 @@ public class PacketPlayOutTitle implements Packet<PacketListenerPlayOut> {
|
2019-01-01 11:15:55 +08:00
|
|
|
}
|
2016-03-23 14:05:09 +08:00
|
|
|
|
2018-09-01 06:56:57 +08:00
|
|
|
}
|
2016-03-23 14:05:09 +08:00
|
|
|
+ // Paper start
|
|
|
|
+ public net.md_5.bungee.api.chat.BaseComponent[] components;
|
|
|
|
+
|
|
|
|
+ public PacketPlayOutTitle(EnumTitleAction action, net.md_5.bungee.api.chat.BaseComponent[] components, int fadeIn, int stay, int fadeOut) {
|
|
|
|
+ this.a = action;
|
|
|
|
+ this.components = components;
|
|
|
|
+ this.c = fadeIn;
|
|
|
|
+ this.d = stay;
|
|
|
|
+ this.e = fadeOut;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2019-04-26 09:24:00 +08:00
|
|
|
@Override
|
2016-03-23 14:05:09 +08:00
|
|
|
public void b(PacketDataSerializer packetdataserializer) throws IOException {
|
2019-01-01 11:15:55 +08:00
|
|
|
packetdataserializer.a((Enum) this.a);
|
2016-11-17 10:23:38 +08:00
|
|
|
if (this.a == PacketPlayOutTitle.EnumTitleAction.TITLE || this.a == PacketPlayOutTitle.EnumTitleAction.SUBTITLE || this.a == PacketPlayOutTitle.EnumTitleAction.ACTIONBAR) {
|
2016-03-23 14:05:09 +08:00
|
|
|
- packetdataserializer.a(this.b);
|
|
|
|
+ // Paper start
|
|
|
|
+ if (this.components != null) {
|
|
|
|
+ packetdataserializer.a(net.md_5.bungee.chat.ComponentSerializer.toString(components));
|
|
|
|
+ } else {
|
|
|
|
+ packetdataserializer.a(this.b);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.a == PacketPlayOutTitle.EnumTitleAction.TIMES) {
|
2016-03-01 07:09:49 +08:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2019-06-25 09:47:58 +08:00
|
|
|
index 3d14319b75..982b06b840 100644
|
2016-03-01 07:09:49 +08: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;
|
2017-02-18 10:03:38 +08:00
|
|
|
import com.google.common.io.BaseEncoding;
|
2019-06-25 09:47:58 +08:00
|
|
|
@@ -211,6 +212,96 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2016-12-21 06:34:27 +08:00
|
|
|
}
|
2016-03-01 07:09:49 +08:00
|
|
|
}
|
2016-12-21 06:34:27 +08:00
|
|
|
|
|
|
|
+ // Paper start
|
2016-03-01 07:09:49 +08:00
|
|
|
+ @Override
|
|
|
|
+ public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
|
2018-09-01 18:09:13 +08:00
|
|
|
+ if (header != null) {
|
2018-10-15 13:05:02 +08:00
|
|
|
+ String headerJson = net.md_5.bungee.chat.ComponentSerializer.toString(header);
|
2018-09-01 18:09:13 +08:00
|
|
|
+ playerListHeader = net.minecraft.server.ChatBaseComponent.ChatSerializer.jsonToComponent(headerJson);
|
|
|
|
+ } else {
|
|
|
|
+ playerListHeader = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (footer != null) {
|
2018-10-15 13:05:02 +08:00
|
|
|
+ String footerJson = net.md_5.bungee.chat.ComponentSerializer.toString(footer);
|
|
|
|
+ playerListFooter = net.minecraft.server.ChatBaseComponent.ChatSerializer.jsonToComponent(footerJson);
|
2018-09-01 18:09:13 +08:00
|
|
|
+ } else {
|
|
|
|
+ playerListFooter = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updatePlayerListHeaderFooter();
|
2016-03-01 07:09:49 +08:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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) {
|
|
|
|
+ getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TIMES, (BaseComponent[]) null, fadeInTicks, stayTicks, fadeOutTicks));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setSubtitle(BaseComponent[] subtitle) {
|
|
|
|
+ getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, subtitle, 0, 0, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void setSubtitle(BaseComponent subtitle) {
|
|
|
|
+ setSubtitle(new BaseComponent[]{subtitle});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void showTitle(BaseComponent[] title) {
|
|
|
|
+ getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, title, 0, 0, 0));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @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() {
|
|
|
|
+ getHandle().playerConnection.sendPacket(new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.CLEAR, (BaseComponent[]) null, 0, 0, 0));
|
|
|
|
+ }
|
2016-12-21 06:34:27 +08:00
|
|
|
+ // Paper end
|
|
|
|
+
|
2016-03-01 07:09:49 +08:00
|
|
|
@Override
|
2016-12-21 06:34:27 +08:00
|
|
|
public String getDisplayName() {
|
|
|
|
return getHandle().displayName;
|
2016-03-01 07:09:49 +08:00
|
|
|
--
|
2019-06-25 09:47:58 +08:00
|
|
|
2.22.0
|
2016-03-01 07:09:49 +08:00
|
|
|
|