Skip to content

Commit

Permalink
Fixed tab team not working at all
Browse files Browse the repository at this point in the history
Signed-off-by: DevDrizzy <[email protected]>
  • Loading branch information
DevDrizzy committed May 11, 2024
1 parent 1e3214c commit c43216f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<groupId>xyz.refinedev.api</groupId>
<artifactId>TablistAPI</artifactId>
<version>2.1</version>
<version>2.2</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void unload() {
}

// Destroy main tablist team
Team team = player.getScoreboard().getTeam("tab");
Team team = player.getScoreboard().getTeam("ztab");
if (team != null) {
team.unregister();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TabListener implements Listener {
private final TablistHandler instance;


@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();

Expand All @@ -37,7 +37,7 @@ public void onJoin(PlayerJoinEvent event) {
public void onQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();

Team team = player.getScoreboard().getTeam("tab");
Team team = player.getScoreboard().getTeam("ztab");
if (team != null) {
team.removeEntry(player.getName());
team.unregister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public void onPacketSend(PacketSendEvent event) {
WrapperPlayServerTeams teams = new WrapperPlayServerTeams(event);
if (teams.getTeamMode() != WrapperPlayServerTeams.TeamMode.REMOVE_ENTITIES) return;
if (!teams.getTeamName().equals("tab")) {
if (!teams.getTeamName().equals("ztab")) {
teams.setTeamMode(WrapperPlayServerTeams.TeamMode.ADD_ENTITIES);
teams.setTeamName("tab");
Optional<WrapperPlayServerTeams.ScoreBoardTeamInfo> teamInfo = teams.getTeamInfo();
if (teamInfo.isPresent()) {
WrapperPlayServerTeams.ScoreBoardTeamInfo info = teamInfo.get();
info.setDisplayName(Component.text("tab"));
info.setDisplayName(Component.text("ztab"));
}
}
} else */if (isClientNew && event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_UPDATE) {
Expand Down Expand Up @@ -118,10 +118,10 @@ private void preventGlitch(Player player, UserProfile userProfile) {
}

Scoreboard scoreboard = player.getScoreboard();
Team team = scoreboard.getTeam("tab");
Team team = scoreboard.getTeam("ztab");

if (team == null) {
team = scoreboard.registerNewTeam("tab");
team = scoreboard.registerNewTeam("ztab");
}

if (!team.hasEntry(online.getName())) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/xyz/refinedev/api/tablist/setup/TabLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ public void create() {
this.sendPacket(packetInfo);
}

// Add everyone to the "Tab" team
// These aren't really used for 1.17+ except for hiding our own name
Team bukkitTeam = scoreboard.getTeam("ztab");
if (bukkitTeam == null) {
bukkitTeam = scoreboard.registerNewTeam("ztab");
}

for (Player target : Bukkit.getOnlinePlayers()) {
if (target == null) continue;
if (bukkitTeam.hasEntry(target.getName())) continue;

bukkitTeam.addEntry(target.getName());
}

// Add them to their own team so that our own name doesn't show up
for ( int index = 0; index < 80; index++ ) {
int x = index % mod;
Expand All @@ -160,6 +174,15 @@ public void create() {
scoreboardTeam.addEntry(displayName);
}
}


for ( Player target : Bukkit.getOnlinePlayers() ) {
Team team = target.getScoreboard().getTeam("ztab");
if (team == null) continue;
if (team.hasEntry(player.getName())) continue;

team.addEntry(player.getName());
}
}

public void refresh() {
Expand Down

0 comments on commit c43216f

Please sign in to comment.