SteamWar/MissileWars
Archiviert
13
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
MissileWars/src/de/steamwar/misslewars/FightScoreboard.java

86 Zeilen
2.9 KiB
Java

/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.misslewars;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.text.SimpleDateFormat;
import java.util.Objects;
/**
* Modified Version of the Fight-System Scoreboard
*/
class FightScoreboard {
private FightScoreboard(){}
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective;
private static final SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
private static long startTime = 0;
public static long getStartTime() {
return startTime;
}
static{
if(scoreboard.getObjective("AAA") == null)
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
else
objective = scoreboard.getObjective("AAA");
}
static void init(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> {
objective.unregister();
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName("§eMissileWars");
objective.getScore("§eSpielzeit").setScore(5);
if (startTime == 0) {
objective.getScore("§7??:??:??").setScore(4);
} else {
long current_time = System.currentTimeMillis() - startTime;
objective.getScore(String.format("§7%02d:%02d", current_time / 60000, (current_time / 1000) % 60)).setScore(4);
}
objective.getScore("").setScore(3);
objective.getScore("§eSpieler").setScore(2);
MissileWars.getBlueTeam().teamScoreboard(objective);
MissileWars.getRedTeam().teamScoreboard(objective);
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
}, 0, 50);
}
static Scoreboard getScoreboard() {
return scoreboard;
}
static void startTime() {
startTime = System.currentTimeMillis();
}
}