SteamWar/MissileWars
Archiviert
13
0

Update FightScoreboard
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Dieser Commit ist enthalten in:
yoyosource 2024-08-01 10:49:39 +02:00
Ursprung f3f341d38e
Commit d1968e0c43
2 geänderte Dateien mit 39 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -19,24 +19,30 @@
package de.steamwar.misslewars;
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.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Objects;
/**
* Modified Version of the Fight-System Scoreboard
*/
class FightScoreboard {
class FightScoreboard implements Listener {
private FightScoreboard(){}
public FightScoreboard() {
Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin());
}
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;
@ -44,34 +50,32 @@ class FightScoreboard {
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);
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() {
@Override
public String getTitle() {
return "§eMissileWars";
}
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, 20);
@Override
public HashMap<String, Integer> getData() {
HashMap<String, Integer> data = new HashMap<>();
data.put("§eSpielzeit", 5);
if (startTime == 0) {
data.put("§7??:??:??", 4);
} else {
long current_time = System.currentTimeMillis() - startTime;
data.put(String.format("§7%02d:%02d", current_time / 60000, (current_time / 1000) % 60), 4);
}
data.put("", 3);
data.put("§eSpieler", 2);
MissileWars.getBlueTeam().teamScoreboard(data);
MissileWars.getRedTeam().teamScoreboard(data);
return data;
}
});
}
static Scoreboard getScoreboard() {
@ -81,5 +85,4 @@ class FightScoreboard {
static void startTime() {
startTime = System.currentTimeMillis();
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
@ -158,8 +159,10 @@ public class MWTeam {
}
}
public void teamScoreboard(Objective objective) {
players.forEach(p -> objective.getScore(getColorCode() + p.getName()).setScore(1));
public void teamScoreboard(HashMap<String, Integer> data) {
players.forEach(player -> {
data.put(getColorCode() + player.getName(), 1);
});
}
public int size() {