From 10f8e597f886fda2df23217134389caaa127eb3e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 07:32:03 +0100 Subject: [PATCH] Add spectate team to hide nametags Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 9 ++++----- .../steamwar/fightsystem/listener/FightScoreboard.java | 10 ++++++++-- .../de/steamwar/fightsystem/listener/Permanent.java | 7 +++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 47ba81f..dac4135 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.listener.Permanent; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; @@ -121,11 +122,7 @@ public class FightTeam { new KitLoader(); new SpectateHandler(); - if(FightScoreboard.getBukkit().getTeam(name) == null) - team = FightScoreboard.getBukkit().registerNewTeam(name); - else - team = FightScoreboard.getBukkit().getTeam(name); - assert team != null; + team = FightScoreboard.getBukkitTeam(name); WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); @@ -252,6 +249,7 @@ public class FightTeam { FightPlayer fightPlayer = new FightPlayer(player, this); players.put(player, fightPlayer); invited.remove(player); + Permanent.getSpectatorTeam().removeEntry(player.getName()); team.addEntry(player.getName()); Fight.setPlayerGamemode(player, GameMode.SURVIVAL); @@ -277,6 +275,7 @@ public class FightTeam { List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true); players.remove(player); team.removeEntry(player.getName()); + Permanent.getSpectatorTeam().addEntry(player.getName()); FightUI.addSubtitle("UI_PLAYER_LEAVES", prefix, player.getName()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 957f085..63ca402 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -30,14 +30,20 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; import java.util.HashMap; import java.util.Objects; public class FightScoreboard implements Listener, ScoreboardCallback { - public static Scoreboard getBukkit() { - return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); + public static Team getBukkitTeam(String name) { + Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); + Team team = scoreboard.getTeam(name); + if(team != null) + return team; + + return scoreboard.registerNewTeam(name); } private static FightScoreboard scoreboard; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index d10c7c8..64aa91a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -46,9 +46,15 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.scoreboard.Team; public class Permanent implements Listener { + private static final Team spectatorTeam = FightScoreboard.getBukkitTeam("Spectator"); + public static Team getSpectatorTeam() { + return spectatorTeam; + } + public Permanent() { new StateDependentListener(ArenaMode.All, FightState.All, this); } @@ -81,6 +87,7 @@ public class Permanent implements Listener { if (!Config.ArenaLeaveable && !Fight.fighting(player)) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + spectatorTeam.addEntry(player.getName()); player.teleport(Config.SpecSpawn); } }