SteamWar/FightSystem
Archiviert
13
1
Dieser Commit ist enthalten in:
Chaoscaot 2020-11-17 08:58:50 +01:00
Ursprung 26e71da87a
Commit e460b04a67
3 geänderte Dateien mit 69 neuen und 75 gelöschten Zeilen

Datei anzeigen

@ -102,6 +102,7 @@ public class FightSystem extends JavaPlugin {
new RankedJoinListener();
new GameplayListener();
new PersonalKitCreator();
new ScoreboardListener();
if(Core.getVersion() > 8)
new VersionDependentListener();

Datei anzeigen

@ -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());
}
}

Datei anzeigen

@ -30,24 +30,21 @@ import de.steamwar.fightsystem.winconditions.*;
import de.steamwar.scoreboard.SWScoreboard;
import de.steamwar.scoreboard.ScoreboardCallback;
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.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Set;
public class FightScoreboard implements Listener {
public class FightScoreboard {
private static final Set<FightState> fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE);
private static int index = 0;
private static ScoreBoardObjective objective;
private static String title = "";
private static HashMap<String, Integer> scores;
public static void init(){
Bukkit.getPluginManager().registerEvents(new FightScoreboard(), FightSystem.getPlugin());
Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200);
}
@ -55,116 +52,86 @@ public class FightScoreboard implements Listener {
return Bukkit.getScoreboardManager().getMainScoreboard();
}
@EventHandler()
public void onPlayerJoin(PlayerJoinEvent event) {
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
public static void showScoreboard(Player p) {
SWScoreboard.createScoreboard(p, new ScoreboardCallback() {
@Override
public HashMap<String, Integer> getData() {
return objective.getScores();
return scores;
}
@Override
public String getTitle() {
return objective.getTitle();
return title;
}
});
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
SWScoreboard.removeScoreboard(event.getPlayer());
public static void removeScoreboard(Player p) {
SWScoreboard.removeScoreboard(p);
}
private static ScoreBoardObjective teamScoreboard(FightTeam fightTeam){
final ScoreBoardObjective objective = new ScoreBoardObjective(fightTeam.getColoredName());
private static void teamScoreboard(FightTeam fightTeam){
title = fightTeam.getColoredName();
if(Config.recording())
RecordSystem.scoreboardTitle(title);
fightTeam.getPlayers().forEach(fp -> {
if(fp.isLiving())
objective.addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth()));
});
return objective;
}
private static ScoreBoardObjective generalScoreboard(){
final ScoreBoardObjective objective = new ScoreBoardObjective("§6Kampf");
private static void generalScoreboard(){
title = "§6Kampf";
if(Config.recording())
RecordSystem.scoreboardTitle(objective.getTitle());
RecordSystem.scoreboardTitle(title);
if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) {
int fightTime = FightSystem.getFightTime();
if (fightTime >= 60)
objective.addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4);
else
objective.addScore("§7Zeit: §a" + fightTime + "s", 4);
addScore("§7Zeit: §a" + fightTime + "s", 4);
}
objective.addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3);
if(fullScoreboard.contains(FightSystem.getFightState())){
if (Config.PercentSystem){
objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1);
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0);
}else if(Config.WaterTechKO){
objective.addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
objective.addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0);
}else if(Config.RelativePercent){
objective.addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
objective.addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1);
addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0);
}else if(Config.Points){
objective.addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
objective.addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0);
}else if(Config.PumpkinTechKO){
objective.addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
objective.addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1);
addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0);
}
}
if(Config.recording())
objective.scores.forEach(RecordSystem::scoreboardData);
return objective;
}
private static FightTeam getIndexDisplay() {
if(index == 1)
return Fight.redTeam;
if(index == 2)
return Fight.blueTeam;
return null;
}
private static void nextIndexDisplay() {
index++;
if(index > 2)
index = 0;
final FightTeam team = getIndexDisplay();
FightTeam team = null;
if(index == 1)
team = Fight.redTeam;
if(index == 2)
team = Fight.blueTeam;
if(team != null)
objective = teamScoreboard(team);
teamScoreboard(team);
else
objective = generalScoreboard();
generalScoreboard();
}
private static class ScoreBoardObjective {
private final String title;
private final HashMap<String, Integer> scores = new HashMap<>();
public ScoreBoardObjective(String title) {
if(Config.recording())
RecordSystem.scoreboardTitle(title);
this.title = title;
}
public String getTitle() {
return title;
}
public void addScore(String string, int i) {
if(Config.recording())
RecordSystem.scoreboardData(string, i);
scores.put(string, i);
}
public HashMap<String, Integer> getScores() {
return scores;
}
private static void addScore(String string, int i) {
if(Config.recording())
RecordSystem.scoreboardData(string, i);
scores.put(string, i);
}
}