SteamWar/FightSystem
Archiviert
13
1

Changed Fight Scoreboard to SWScoreboard

Dieser Commit ist enthalten in:
Chaoscaot 2020-10-06 23:39:47 +02:00
Ursprung 0299e35766
Commit 1acd3878f5

Datei anzeigen

@ -25,13 +25,13 @@ import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.winconditions.*; import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Objects; import java.util.HashMap;
import java.util.Set; import java.util.Set;
public class FightScoreboard { public class FightScoreboard {
@ -39,85 +39,111 @@ public class FightScoreboard {
private FightScoreboard(){} 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 final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective;
private static int index = 0; private static int index = 0;
static{
if(scoreboard.getObjective("AAA") == null)
//noinspection deprecation
objective = scoreboard.registerNewObjective("AAA", "BBB");
else
objective = scoreboard.getObjective("AAA");
}
public static void init(){ public static void init(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> { Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> {
objective.unregister(); Bukkit.getOnlinePlayers().forEach(player -> SWScoreboard.removeScoreboard(player));
//noinspection deprecation
scoreboard.registerNewObjective("AAA", "BBB");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
FightTeam fightTeam = getIndexDisplay(); FightTeam fightTeam = getIndexDisplay();
ScoreBoardObjective objective;
if(fightTeam != null) if(fightTeam != null)
teamScoreboard(fightTeam); objective = teamScoreboard(fightTeam);
else else
generalScoreboard(); objective = generalScoreboard();
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard)); 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); }, 0, 200);
} }
public static Scoreboard getScoreboard() { public static Scoreboard getScoreboard() {
return scoreboard; return Bukkit.getScoreboardManager().getMainScoreboard();
} }
private static void teamScoreboard(FightTeam fightTeam){ private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){
objective.setDisplayName(fightTeam.getColoredName()); ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName());
fightTeam.getPlayers().forEach(fp -> { fightTeam.getPlayers().forEach(fp -> {
if(fp.isLiving()) if(fp.isLiving())
objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) Math.ceil(fp.getPlayer().getHealth())); objective.addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
}); });
return objective;
} }
private static void generalScoreboard(){ private static ScoreBoardObjective generalScoreboard(){
objective.setDisplayName("§6Kampf"); ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf");
if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) {
int fightTime = FightSystem.getFightTime(); int fightTime = FightSystem.getFightTime();
if (fightTime >= 60) if (fightTime >= 60)
objective.getScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s").setScore(3); objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 3);
else else
objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); objective.addScore("§7Zeit: §a" + fightTime + "s", 3);
} }
if(fullScoreboard.contains(FightSystem.getFightState())){ if(fullScoreboard.contains(FightSystem.getFightState())){
if (Config.PercentSystem){ if (Config.PercentSystem){
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%").setScore(1); objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%").setScore(0); objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
}else if(Config.WaterTechKO){ }else if(Config.WaterTechKO){
objective.getScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater()).setScore(1); objective.addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater()).setScore(0); objective.addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
}else if(Config.RelativePercent){ }else if(Config.RelativePercent){
objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1); objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0); objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
}else if(Config.Points){ }else if(Config.Points){
objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1); objective.addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0); objective.addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
}else if(Config.PumpkinTechKO){ }else if(Config.PumpkinTechKO){
objective.getScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins()).setScore(1); objective.addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
objective.getScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins()).setScore(0); objective.addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
} }
} }
return objective;
} }
private static FightTeam getIndexDisplay() { private static FightTeam getIndexDisplay() {
index++;
if(index == 1) if(index == 1)
return Fight.redTeam; return Fight.redTeam;
if(index == 2) if(index == 2)
return Fight.blueTeam; return Fight.blueTeam;
index = 0;
return null; return null;
} }
private static void nextIndexDisplay() {
index++;
if(index > 2)
return;
index = 0;
}
private static class ScoreBoardObjective {
private final String title;
private HashMap<String, Integer> scores = new HashMap<>();
public ScoreBoardObjective(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void addScore(String string, int i) {
scores.put(string, i);
}
public HashMap<String, Integer> getScores() {
return scores;
}
}
} }