Delete src/main/java/de/lasertag/scoreboard/ScoreboardManager.java via Git Manager GUI
This commit is contained in:
@@ -1,113 +0,0 @@
|
||||
package de.lasertag.scoreboard;
|
||||
|
||||
import de.lasertag.LasertagPlugin;
|
||||
import de.lasertag.game.Game;
|
||||
import de.lasertag.game.Team;
|
||||
import de.lasertag.player.LaserPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ScoreboardManager {
|
||||
|
||||
private final LasertagPlugin plugin;
|
||||
private final Map<UUID, Scoreboard> boards = new HashMap<>();
|
||||
|
||||
public ScoreboardManager(LasertagPlugin plugin) { this.plugin = plugin; }
|
||||
|
||||
public void update(Player player, Game game) {
|
||||
Scoreboard board = boards.computeIfAbsent(player.getUniqueId(),
|
||||
k -> Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
|
||||
// Altes Objective entfernen
|
||||
Objective old = board.getObjective("lt");
|
||||
if (old != null) old.unregister();
|
||||
|
||||
Objective obj = board.registerNewObjective("lt", "dummy",
|
||||
ChatColor.AQUA + "" + ChatColor.BOLD + "⚡ LASERTAG");
|
||||
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
|
||||
LaserPlayer lp = game.getLP(player.getUniqueId());
|
||||
|
||||
int line = 15;
|
||||
|
||||
// Trennlinie oben
|
||||
setLine(obj, board, "§b§l─────────────────", line--);
|
||||
|
||||
// Zeit
|
||||
int secs = game.getTimeLeft();
|
||||
String timeStr = String.format("%d:%02d", secs / 60, secs % 60);
|
||||
setLine(obj, board, "§7⏰ Zeit: §e" + timeStr, line--);
|
||||
setLine(obj, board, "§7§l─────────────────", line--);
|
||||
|
||||
// Team-Punkte (sortiert nach Punkte)
|
||||
setLine(obj, board, "§7Team-Punkte:", line--);
|
||||
Map<Team, Integer> scores = game.getTeamScore();
|
||||
Team[] sorted = Team.values().clone();
|
||||
// Bubble sort (nur 4 Teams)
|
||||
for (int i = 0; i < sorted.length - 1; i++)
|
||||
for (int j = 0; j < sorted.length - 1 - i; j++)
|
||||
if (scores.getOrDefault(sorted[j],0) < scores.getOrDefault(sorted[j+1],0)) {
|
||||
Team tmp = sorted[j]; sorted[j] = sorted[j+1]; sorted[j+1] = tmp;
|
||||
}
|
||||
|
||||
for (Team t : sorted) {
|
||||
int hp = game.getArena().getBaseHealth(t);
|
||||
int maxHp = plugin.getConfig().getInt("game.base-health", 5);
|
||||
String baseHpBar = buildHpBar(hp, maxHp, 5);
|
||||
String pts = scores.getOrDefault(t, 0) + "§7pts";
|
||||
setLine(obj, board,
|
||||
t.getChatColor() + "● " + t.getDisplayName() + " §8| §f" + pts
|
||||
+ " §8| " + baseHpBar, line--);
|
||||
}
|
||||
|
||||
setLine(obj, board, "§7§l─────────────────", line--);
|
||||
|
||||
// Spieler-Stats
|
||||
if (lp != null) {
|
||||
String hitStatus = lp.isHit()
|
||||
? (lp.isHealing() ? "§e⚕ Heilend..." : "§c☠ Getroffen!")
|
||||
: "§a✔ Aktiv";
|
||||
setLine(obj, board, "§7Status: " + hitStatus, line--);
|
||||
setLine(obj, board, "§7Kills: §a" + lp.getKills() + " §8| §7Tode: §c" + lp.getDeaths(), line--);
|
||||
setLine(obj, board, "§7Punkte: §6" + lp.getScore(), line--);
|
||||
if (lp.getKillStreak() >= 3)
|
||||
setLine(obj, board, "§6🔥 Serie: §e×" + lp.getKillStreak(), line--);
|
||||
}
|
||||
|
||||
setLine(obj, board, "§b§l─────────────────", line--);
|
||||
setLine(obj, board, "§bwww.lasertag.de", line--);
|
||||
|
||||
player.setScoreboard(board);
|
||||
}
|
||||
|
||||
public void remove(Player player) {
|
||||
boards.remove(player.getUniqueId());
|
||||
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
|
||||
}
|
||||
|
||||
// ─── Hilfsmethoden ───────────────────────────────────────────────────────
|
||||
|
||||
private int uniqueSuffix = 0;
|
||||
|
||||
private void setLine(Objective obj, Scoreboard board, String text, int score) {
|
||||
// Scoreboard-Entries müssen einzigartig sein
|
||||
String entry = text;
|
||||
while (board.getEntries().contains(entry))
|
||||
entry = entry + ChatColor.values()[uniqueSuffix++ % ChatColor.values().length];
|
||||
obj.getScore(entry).setScore(score);
|
||||
}
|
||||
|
||||
private String buildHpBar(int hp, int max, int len) {
|
||||
if (max <= 0) return "§8-----";
|
||||
int filled = (int) Math.round((double) hp / max * len);
|
||||
filled = Math.max(0, Math.min(len, filled));
|
||||
String color = filled > len / 2 ? "§a" : filled > 1 ? "§e" : "§c";
|
||||
return color + "█".repeat(filled) + "§8" + "░".repeat(len - filled);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user