From 606cf0eea44b88d5630623ff8a5d63571fa42793 Mon Sep 17 00:00:00 2001 From: Adam Thomas Date: Sat, 29 Nov 2014 02:54:00 +0000 Subject: [PATCH] Implement NameTag visibility API for Teams. --- .../craftbukkit/scoreboard/CraftTeam.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java index 8a640d369e..e8d1c081e5 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java @@ -2,9 +2,11 @@ package org.bukkit.craftbukkit.scoreboard; import java.util.Set; +import net.minecraft.server.EnumNameTagVisibility; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; import com.google.common.collect.ImmutableSet; @@ -92,6 +94,20 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { team.setCanSeeFriendlyInvisibles(enabled); } + public NameTagVisibility getNameTagVisibility() throws IllegalArgumentException { + CraftScoreboard scoreboard = checkState(); + + // PAIL: Rename + return notchToBukkit(team.i()); // i is sent in PacketPlayOutScoreboardTeam, cannot see a use of j + } + + public void setNameTagVisibility(NameTagVisibility visibility) throws IllegalArgumentException { + CraftScoreboard scoreboard = checkState(); + + // PAIL: Rename + team.a(bukkitToNotch(visibility)); // i is sent in PacketPlayOutScoreboardTeam, cannot see a use of j + } + public Set getPlayers() throws IllegalStateException { CraftScoreboard scoreboard = checkState(); @@ -142,4 +158,34 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { scoreboard.teams.remove(team.getName()); setUnregistered(); } + + public static EnumNameTagVisibility bukkitToNotch(NameTagVisibility visibility) { + switch (visibility) { + case ALWAYS: + return EnumNameTagVisibility.ALWAYS; + case NEVER: + return EnumNameTagVisibility.NEVER; + case HIDE_FOR_OTHER_TEAMS: + return EnumNameTagVisibility.HIDE_FOR_OTHER_TEAMS; + case HIDE_FOR_OWN_TEAM: + return EnumNameTagVisibility.HIDE_FOR_OWN_TEAM; + default: + throw new IllegalArgumentException("Unknown visibility level " + visibility); + } + } + + public static NameTagVisibility notchToBukkit(EnumNameTagVisibility visibility) { + switch (visibility) { + case ALWAYS: + return NameTagVisibility.ALWAYS; + case NEVER: + return NameTagVisibility.NEVER; + case HIDE_FOR_OTHER_TEAMS: + return NameTagVisibility.HIDE_FOR_OTHER_TEAMS; + case HIDE_FOR_OWN_TEAM: + return NameTagVisibility.HIDE_FOR_OWN_TEAM; + default: + throw new IllegalArgumentException("Unknown visibility level " + visibility); + } + } }