Changed Fight Scoreboard to SWScoreboard #194
@ -102,6 +102,7 @@ public class FightSystem extends JavaPlugin {
|
|||||||
new RankedJoinListener();
|
new RankedJoinListener();
|
||||||
new GameplayListener();
|
new GameplayListener();
|
||||||
new PersonalKitCreator();
|
new PersonalKitCreator();
|
||||||
|
new ScoreboardListener();
|
||||||
if(Core.getVersion() > 8)
|
if(Core.getVersion() > 8)
|
||||||
new VersionDependentListener();
|
new VersionDependentListener();
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package de.steamwar.fightsystem.listener;
|
||||||
|
|
||||||
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
|
import de.steamwar.fightsystem.utils.FightScoreboard;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class ScoreboardListener extends BasicListener {
|
||||||
|
|
||||||
|
public ScoreboardListener() {
|
||||||
|
super(EnumSet.allOf(FightState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
FightScoreboard.showScoreboard(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
FightScoreboard.removeScoreboard(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
@ -27,111 +27,111 @@ import de.steamwar.fightsystem.fight.FightTeam;
|
|||||||
import de.steamwar.fightsystem.record.RecordSystem;
|
import de.steamwar.fightsystem.record.RecordSystem;
|
||||||
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.entity.Player;
|
||||||
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 {
|
||||||
|
|
||||||
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;
|
||||||
|
private static String title = "";
|
||||||
static{
|
private static HashMap<String, Integer> scores;
|
||||||
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(){
|
||||||
Lixfel
hat
Fände es besser, direkt titel und scores zu speichern (siehe unten) Fände es besser, direkt titel und scores zu speichern (siehe unten)
|
|||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), () -> {
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200);
|
||||||
objective.unregister();
|
|
||||||
//noinspection deprecation
|
|
||||||
scoreboard.registerNewObjective("AAA", "BBB");
|
|
||||||
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
|
||||||
|
|
||||||
FightTeam fightTeam = getIndexDisplay();
|
|
||||||
if(fightTeam != null)
|
|
||||||
teamScoreboard(fightTeam);
|
|
||||||
else
|
|
||||||
generalScoreboard();
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
|
|
||||||
}, 0, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Lixfel
hat
Listener sollen im Ordner Listener sein, in diesem Fall solltest du wsl. einfach im ConnectionListener im JonListener einen Aufruf hierher machen. Listener sollen im Ordner Listener sein, in diesem Fall solltest du wsl. einfach im ConnectionListener im JonListener einen Aufruf hierher machen.
|
|||||||
public static Scoreboard getScoreboard() {
|
public static Scoreboard getScoreboard() {
|
||||||
return scoreboard;
|
return Bukkit.getScoreboardManager().getMainScoreboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showScoreboard(Player p) {
|
||||||
Lixfel
hat
Hast du darauf geachtet, dass die Teammitglieder immer noch keinen Nametag über sich haben & in der passenden Farbe rechts angezeigt werden? Aufgrund der derzeitigen SWScoreboard-Implementierung (welche ich überarbeiten möchte) habe ich da nämlich so meine Befürchtungen. Hast du darauf geachtet, dass die Teammitglieder immer noch keinen Nametag über sich haben & in der passenden Farbe rechts angezeigt werden? Aufgrund der derzeitigen SWScoreboard-Implementierung (welche ich überarbeiten möchte) habe ich da nämlich so meine Befürchtungen.
Chaoscaot
hat
Die Nametags werden gehided und der Name hat auch die richtige Farbe in der Sidebar. Die Nametags werden gehided und der Name hat auch die richtige Farbe in der Sidebar.
|
|||||||
|
SWScoreboard.createScoreboard(p, new ScoreboardCallback() {
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Integer> getData() {
|
||||||
|
return scores;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeScoreboard(Player p) {
|
||||||
|
SWScoreboard.removeScoreboard(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void teamScoreboard(FightTeam fightTeam){
|
private static void teamScoreboard(FightTeam fightTeam){
|
||||||
objective.setDisplayName(fightTeam.getColoredName());
|
title = fightTeam.getColoredName();
|
||||||
if(Config.recording())
|
if(Config.recording())
|
||||||
RecordSystem.scoreboardTitle(fightTeam.getColoredName());
|
RecordSystem.scoreboardTitle(title);
|
||||||
fightTeam.getPlayers().forEach(fp -> {
|
fightTeam.getPlayers().forEach(fp -> {
|
||||||
if(fp.isLiving())
|
if(fp.isLiving())
|
||||||
setScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
|
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void generalScoreboard(){
|
private static void generalScoreboard(){
|
||||||
objective.setDisplayName("§eKampf");
|
title = "§6Kampf";
|
||||||
if(Config.recording())
|
if(Config.recording())
|
||||||
RecordSystem.scoreboardTitle("§eKampf");
|
RecordSystem.scoreboardTitle(title);
|
||||||
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)
|
||||||
setScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
|
||||||
else
|
else
|
||||||
setScore("§7Zeit: §a" + fightTime + "s", 4);
|
addScore("§7Zeit: §a" + fightTime + "s", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
setScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
|
||||||
|
|
||||||
if(fullScoreboard.contains(FightSystem.getFightState())){
|
if(fullScoreboard.contains(FightSystem.getFightState())){
|
||||||
if (Config.PercentSystem){
|
if (Config.PercentSystem){
|
||||||
setScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
|
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
|
||||||
setScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
|
||||||
}else if(Config.WaterTechKO){
|
}else if(Config.WaterTechKO){
|
||||||
setScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(),1);
|
addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
|
||||||
setScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
|
||||||
}else if(Config.RelativePercent){
|
}else if(Config.RelativePercent){
|
||||||
setScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
|
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
|
||||||
setScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
|
||||||
}else if(Config.Points){
|
}else if(Config.Points){
|
||||||
setScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
|
addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
|
||||||
setScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
|
||||||
}else if(Config.PumpkinTechKO){
|
}else if(Config.PumpkinTechKO){
|
||||||
setScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
|
addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
|
||||||
setScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
|
addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setScore(String key, int value){
|
private static void nextIndexDisplay() {
|
||||||
objective.getScore(key).setScore(value);
|
|
||||||
if(Config.recording())
|
|
||||||
RecordSystem.scoreboardData(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static FightTeam getIndexDisplay() {
|
|
||||||
index++;
|
index++;
|
||||||
if(index == 1)
|
if(index > 2)
|
||||||
return Fight.redTeam;
|
|
||||||
if(index == 2)
|
|
||||||
return Fight.blueTeam;
|
|
||||||
index = 0;
|
index = 0;
|
||||||
return null;
|
FightTeam team = null;
|
||||||
|
if(index == 1)
|
||||||
Lixfel
hat
Du sendest jeden Score doppelt raus. Du sendest jeden Score doppelt raus.
|
|||||||
|
team = Fight.redTeam;
|
||||||
|
if(index == 2)
|
||||||
|
team = Fight.blueTeam;
|
||||||
|
if(team != null)
|
||||||
|
teamScoreboard(team);
|
||||||
|
else
|
||||||
Lixfel
hat
Das schaut mir katastrophal verbuggt aus, da dürfte nie das korrekte Scoreboard angezeigt werden! Das schaut mir katastrophal verbuggt aus, da dürfte nie das korrekte Scoreboard angezeigt werden!
YoyoNow
hat
Es wird wohl immer einmal kein Scoreboard angezeigt werden weil Es wird wohl immer einmal kein Scoreboard angezeigt werden weil `Index = 0` bedeutet die `getIndexDisplay()` Methode gibt `null` zurück. Dies sollte behoben werden.
YoyoNow
hat
Der Fehler ist nun behoben, bzw um 13:00 am gleichen Tag wurde dieser Fehler noch behoben, deswegen habe ich den Pull-Request jetzt nach einer guten Zeit drauf gucken genehmigt Der Fehler ist nun behoben, bzw um 13:00 am gleichen Tag wurde dieser Fehler noch behoben, deswegen habe ich den Pull-Request jetzt nach einer guten Zeit drauf gucken genehmigt
|
|||||||
|
generalScoreboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addScore(String string, int i) {
|
||||||
|
if(Config.recording())
|
||||||
|
RecordSystem.scoreboardData(string, i);
|
||||||
Lixfel
hat
Die Funktion nextIndexDisplay sollte sich mit der Funktion getIndexDisplay zusammenführen lassen. Die Funktion nextIndexDisplay sollte sich mit der Funktion getIndexDisplay zusammenführen lassen.
|
|||||||
|
scores.put(string, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Man sollte das Scoreboard nicht regelmäßig bei jedem Spieler neu setzen, das macht das SWScoreboard schon von selbst.