mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 23:07:40 +01:00
Player Tab List and Title APIs
This commit is contained in:
parent
f4a0ce454b
commit
eaf365a7b7
@ -393,6 +393,98 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(fadeInTicks, stayTicks, fadeOutTicks));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubtitle(BaseComponent[] subtitle) {
|
||||
final ClientboundSetSubtitleTextPacket packet = new ClientboundSetSubtitleTextPacket(org.bukkit.craftbukkit.util.CraftChatMessage.fromJSON(net.md_5.bungee.chat.ComponentSerializer.toString(subtitle)));
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSubtitle(BaseComponent subtitle) {
|
||||
setSubtitle(new BaseComponent[]{subtitle});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTitle(BaseComponent[] title) {
|
||||
final ClientboundSetTitleTextPacket packet = new ClientboundSetTitleTextPacket(org.bukkit.craftbukkit.util.CraftChatMessage.fromJSON(net.md_5.bungee.chat.ComponentSerializer.toString(title)));
|
||||
getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@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(com.destroystokyo.paper.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(com.destroystokyo.paper.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().connection.send(new ClientboundClearTitlesPacket(false));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
|
||||
|
Loading…
Reference in New Issue
Block a user