From abd1ea36165cef3ffc7d964cbd33b2a0599daf73 Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Thu, 21 Feb 2019 20:04:06 +0100 Subject: [PATCH] Added Scoreboard Signed-off-by: Yaruma3341 --- src/me/yaruma/fightsystem/FightSystem.java | 22 +++++ .../listener/PlayerJoinListener.java | 2 + .../utils/countdown/Countdown.java | 2 + .../utils/scoreboard/Scoreboard.java | 91 +++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index ab10388..3ee7aff 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -9,6 +9,7 @@ import me.yaruma.fightsystem.manager.FileManager; import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.countdown.FinishSetupOver; import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver; +import me.yaruma.fightsystem.utils.scoreboard.Scoreboard; import me.yaruma.fightsystem.winconditions.WinconditionAllDead; import me.yaruma.fightsystem.winconditions.WinconditionCaptainDead; import me.yaruma.fightsystem.winconditions.WinconditionPercentSystem; @@ -28,6 +29,7 @@ public class FightSystem extends JavaPlugin { private static FightSystem plugin; private FileManager fileManager; private FightManager fightManager; + private Scoreboard scoreboard; private FightState fightState; @@ -56,6 +58,11 @@ public class FightSystem extends JavaPlugin { public int team2cornerZ; + public int fightTime = 0; + public double damageRed = 0D; + public double getDamageBlue = 0D; + + public void onEnable() { plugin = this; @@ -197,6 +204,10 @@ public class FightSystem extends JavaPlugin { return fightState; } + public Scoreboard getScoreboard() { + return scoreboard; + } + public void setSetupState() { if(this.fightState == null) { this.fightState = FightState.SETUP; @@ -332,4 +343,15 @@ public class FightSystem extends JavaPlugin { return team2cornerZ; } + public int getFightTime() { + return fightTime; + } + + public double getDamageRed() { + return damageRed; + } + + public double getGetDamageBlue() { + return getDamageBlue; + } } diff --git a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java index 7ac9b7c..55c70a6 100644 --- a/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java +++ b/src/me/yaruma/fightsystem/listener/PlayerJoinListener.java @@ -60,6 +60,8 @@ public class PlayerJoinListener implements Listener { player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc()); } } + + FightSystem.getPlugin().getScoreboard().setAutoScoreboard(20*10, player); } diff --git a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java index 93957ab..6059649 100644 --- a/src/me/yaruma/fightsystem/utils/countdown/Countdown.java +++ b/src/me/yaruma/fightsystem/utils/countdown/Countdown.java @@ -19,6 +19,8 @@ public class Countdown { public Countdown(int time, CountdownCallback countdownCallback) { this.time = time; this.countdownCallback = countdownCallback; + + if(countdownCallback == new FinishTimeOver()) FightSystem.getPlugin().fightTime = time; } diff --git a/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java b/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java new file mode 100644 index 0000000..2485825 --- /dev/null +++ b/src/me/yaruma/fightsystem/utils/scoreboard/Scoreboard.java @@ -0,0 +1,91 @@ +package me.yaruma.fightsystem.utils.scoreboard; + +import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.Fight; +import me.yaruma.fightsystem.fight.FightTeam; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.ScoreboardManager; + +public class Scoreboard { + + private ScoreboardManager scoreboardManager; + private org.bukkit.scoreboard.Scoreboard scoreboard; + private Objective objective; + private int taskID; + + public Scoreboard(FightSystem instance) { + this.scoreboardManager = Bukkit.getScoreboardManager(); + this.scoreboard = this.scoreboardManager.getNewScoreboard(); + this.objective = scoreboard.registerNewObjective("AAA", "BBB"); + } + + public void setAutoScoreboard(int delay, Player player) { + taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), new Runnable() { + + private int index; + + private String PREFIX; + private String NAME; + + @Override + public void run() { + if(getIndexDisplay(index) != null) { + + if(getIndexDisplay(index) == Fight.redTeam) { + this.PREFIX = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.TeamRedColor"); + this.NAME = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.TeamRedName"); + } + if(getIndexDisplay(index) == Fight.redTeam) { + this.PREFIX = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.TeamRedColor"); + this.NAME = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.TeamRedName"); + } + + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + objective.setDisplayName("§6Info " + PREFIX + NAME); + + for(int i = 0; i < getIndexDisplay(index).getPlayers().size(); i++) { + objective.getScore(PREFIX + getIndexDisplay(index).getPlayers().get(i).getPlayer().getDisplayName() + " §8: " + "§6" + getIndexDisplay(index).getPlayers().get(i).getPlayer().getHealth()).setScore(i); + } + + } else { + index = 0; + + String gameName = FightSystem.getPlugin().getFileManager().getStringFromConfig("Output.GameName"); + + objective.setDisplayName("§6Fight Info"); + if(gameName == "AirWargear" || gameName == "WarShip") { + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + objective.getScore("§7Zeit: §a" + FightSystem.getPlugin().getFightTime()).setScore(0); + objective.getScore("§7Entern: " + (FightSystem.getPlugin().getFileManager().getBooleanFromConfig("Fight.Entern") ? "§aja" : "§cnein")).setScore(1); + objective.getScore("§7Spieltyp: §e" + gameName).setScore(2); + objective.getScore("§eSchaden ROT: " + FightSystem.getPlugin().getDamageRed()).setScore(3); + objective.getScore("§eSchaden BLAU: " + FightSystem.getPlugin().getGetDamageBlue()).setScore(4); + } else { + objective.setDisplaySlot(DisplaySlot.SIDEBAR); + objective.getScore("§7Zeit: §a" + FightSystem.getPlugin().getFightTime()).setScore(0); + objective.getScore("§7Spieltyp: §e" + gameName).setScore(2); + } + } + player.setScoreboard(scoreboard); + index++; + } + }, 0, delay); + } + + private FightTeam getIndexDisplay(int index) { + if(index == 0) { + return Fight.redTeam; + } + if(index == 1) { + return Fight.blueTeam; + } + if(index == 2) { + return null; + } + return null; + } + +}