SteamWar/FightSystem
Archiviert
13
1

Scoreboard Improvement

Dieser Commit ist enthalten in:
Chaoscaot 2020-10-11 10:22:07 +02:00
Ursprung 1acd3878f5
Commit e575d7a493

Datei anzeigen

@ -28,31 +28,33 @@ import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback; import de.steamwar.scoreboard.ScoreboardCallback;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
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.Scoreboard;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set; import java.util.Set;
public class FightScoreboard { public class FightScoreboard implements Listener {
private FightScoreboard(){}
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
private static int index = 0; private static int index = 0;
private static ScoreBoardObjective objective;
public static void init(){ public static void init(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> { Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> nextIndexDisplay(), 0, 200);
Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.removeScoreboard(player)); }
FightTeam fightTeam = getIndexDisplay(); public static Scoreboard getScoreboard() {
ScoreBoardObjective objective; return Bukkit.getScoreboardManager().getMainScoreboard();
if(fightTeam != null) }
objective = teamScoreboard(fightTeam);
else
objective = generalScoreboard();
Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, new ScoreboardCallback() { @EventHandler()
public void onPlayerJoin(PlayerJoinEvent event) {
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
@Override @Override
public HashMap<String, Integer> getData() { public HashMap<String, Integer> getData() {
return objective.getScores(); return objective.getScores();
@ -62,12 +64,12 @@ public class FightScoreboard {
public String getTitle() { public String getTitle() {
return objective.getTitle(); return objective.getTitle();
} }
})); });
}, 0, 200);
} }
public static Scoreboard getScoreboard() { @EventHandler
return Bukkit.getScoreboardManager().getMainScoreboard(); public void onPlayerQuit(PlayerQuitEvent event) {
SWScoreboard.removeScoreboard(event.getPlayer());
} }
private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){ private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){
@ -123,6 +125,11 @@ public class FightScoreboard {
if(index > 2) if(index > 2)
return; return;
index = 0; index = 0;
FightTeam team = getIndexDisplay();
if(team != null)
objective = teamScoreboard(team);
else
objective = generalScoreboard();
} }
private static class ScoreBoardObjective { private static class ScoreBoardObjective {