mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Updated TabList to handle new viewers seeing header and footer
This commit is contained in:
parent
48843c88cf
commit
984df871fb
@ -2,6 +2,7 @@ package net.minestom.server.scoreboard;
|
|||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.network.packet.server.play.PlayerListHeaderAndFooterPacket;
|
||||||
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
|
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -11,6 +12,10 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the {@link Player} tab list as a {@link Scoreboard}.
|
* Represents the {@link Player} tab list as a {@link Scoreboard}.
|
||||||
|
* <p>
|
||||||
|
* This modified version for Hollow Cube mimicks Sidebars so that when players are added as a viewer, the packets aren't
|
||||||
|
* needed to be sent out again to all viewers of the TabList.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public class TabList implements Scoreboard {
|
public class TabList implements Scoreboard {
|
||||||
|
|
||||||
@ -23,6 +28,9 @@ public class TabList implements Scoreboard {
|
|||||||
private final Set<Player> unmodifiableViewers = Collections.unmodifiableSet(viewers);
|
private final Set<Player> unmodifiableViewers = Collections.unmodifiableSet(viewers);
|
||||||
private final String objectiveName;
|
private final String objectiveName;
|
||||||
|
|
||||||
|
private Component header = Component.empty();
|
||||||
|
private Component footer = Component.empty();
|
||||||
|
|
||||||
private ScoreboardObjectivePacket.Type type;
|
private ScoreboardObjectivePacket.Type type;
|
||||||
|
|
||||||
public TabList(String name, ScoreboardObjectivePacket.Type type) {
|
public TabList(String name, ScoreboardObjectivePacket.Type type) {
|
||||||
@ -49,12 +57,23 @@ public class TabList implements Scoreboard {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHeader(@NotNull Component header) {
|
||||||
|
this.header = header;
|
||||||
|
sendPacketToViewers(new PlayerListHeaderAndFooterPacket(header, footer));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFooter(@NotNull Component footer) {
|
||||||
|
this.footer = footer;
|
||||||
|
sendPacketToViewers(new PlayerListHeaderAndFooterPacket(header, footer));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addViewer(@NotNull Player player) {
|
public boolean addViewer(@NotNull Player player) {
|
||||||
final boolean result = this.viewers.add(player);
|
final boolean result = this.viewers.add(player);
|
||||||
if (result) {
|
if (result) {
|
||||||
player.sendPacket(this.getCreationObjectivePacket(Component.empty(), this.type));
|
player.sendPacket(this.getCreationObjectivePacket(Component.empty(), this.type));
|
||||||
player.sendPacket(this.getDisplayScoreboardPacket((byte) 0));
|
player.sendPacket(this.getDisplayScoreboardPacket((byte) 0));
|
||||||
|
player.sendPacket(new PlayerListHeaderAndFooterPacket(header, footer));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user