Scoreboard Improvement
Dieser Commit ist enthalten in:
Ursprung
1acd3878f5
Commit
e575d7a493
@ -28,48 +28,50 @@ 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();
|
|
||||||
ScoreBoardObjective objective;
|
|
||||||
if(fightTeam != null)
|
|
||||||
objective = teamScoreboard(fightTeam);
|
|
||||||
else
|
|
||||||
objective = generalScoreboard();
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.createScoreboard(player, new ScoreboardCallback() {
|
|
||||||
@Override
|
|
||||||
public HashMap<String, Integer> getData() {
|
|
||||||
return objective.getScores();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTitle() {
|
|
||||||
return objective.getTitle();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}, 0, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Scoreboard getScoreboard() {
|
public static Scoreboard getScoreboard() {
|
||||||
return Bukkit.getScoreboardManager().getMainScoreboard();
|
return Bukkit.getScoreboardManager().getMainScoreboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler()
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Integer> getData() {
|
||||||
|
return objective.getScores();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return objective.getTitle();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
SWScoreboard.removeScoreboard(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){
|
private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){
|
||||||
ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName());
|
ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName());
|
||||||
fightTeam.getPlayers().forEach(fp -> {
|
fightTeam.getPlayers().forEach(fp -> {
|
||||||
@ -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 {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren