made Scoreboard more beautiful
This commit is contained in:
@@ -28,7 +28,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
@Appliance.Flags(autoload = false)
|
@Appliance.Flags(autoload = false)
|
||||||
public class Deathrun extends Appliance implements Event, Scorable {
|
public class Deathrun extends Appliance implements Event, Scorable {
|
||||||
private final EventScoreboardBuilder scoreboardBuilder = new EventScoreboardBuilder(this, 3, 2, 3);
|
private final EventScoreboardBuilder scoreboardBuilder = new EventScoreboardBuilder(this, 3, 2, 0);
|
||||||
private final double borderDistance = 100;
|
private final double borderDistance = 100;
|
||||||
private final int borderVisibilityDistance = 8;
|
private final int borderVisibilityDistance = 8;
|
||||||
private long durationSeconds;
|
private long durationSeconds;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
|||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
import net.kyori.adventure.util.Ticks;
|
import net.kyori.adventure.util.Ticks;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.DisplaySlot;
|
import org.bukkit.scoreboard.DisplaySlot;
|
||||||
import org.bukkit.scoreboard.Objective;
|
import org.bukkit.scoreboard.Objective;
|
||||||
@@ -92,18 +93,37 @@ public class EventScoreboardBuilder {
|
|||||||
|
|
||||||
int[] display = indices.distinct().sorted().toArray();
|
int[] display = indices.distinct().sorted().toArray();
|
||||||
|
|
||||||
for (int i = 0; i < display.length; i++) {
|
List<String> lines = new ArrayList<>();
|
||||||
int idx = display[i];
|
int prevIdx = -1;
|
||||||
|
int sepNo = 0;
|
||||||
|
|
||||||
|
for (int idx : display) {
|
||||||
|
if (prevIdx != -1 && idx > prevIdx + 1) {
|
||||||
|
lines.add(this.separatorLine(sepNo++));
|
||||||
|
}
|
||||||
|
|
||||||
EventScoreEntry entry = scoreList.get(idx);
|
EventScoreEntry entry = scoreList.get(idx);
|
||||||
|
if(!entry.playerUuid().equals(p.getUniqueId())) {
|
||||||
|
lines.add(this.formattedLine(idx, entry.name(), entry.score()));
|
||||||
|
} else {
|
||||||
|
lines.add(ChatColor.YELLOW + this.formattedLine(idx, entry.name(), entry.score()) + ChatColor.RESET);
|
||||||
|
}
|
||||||
|
|
||||||
String line = this.formattedLine(idx, entry.name(), entry.score());
|
prevIdx = idx;
|
||||||
|
}
|
||||||
|
|
||||||
objective.getScore(line).setScore(display.length - i);
|
int score = lines.size();
|
||||||
|
for (String line : lines) {
|
||||||
|
objective.getScore(line).setScore(score--);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scoreboard;
|
return scoreboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String separatorLine(int n) {
|
||||||
|
return ChatColor.GRAY + "..." + ChatColor.RESET + " ".repeat(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void startAutomaticUpdates() {
|
public void startAutomaticUpdates() {
|
||||||
this.scoreboardUpdateTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(
|
this.scoreboardUpdateTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(
|
||||||
@@ -134,7 +154,7 @@ public class EventScoreboardBuilder {
|
|||||||
|
|
||||||
private String formattedLine(int place, String name, int score) {
|
private String formattedLine(int place, String name, int score) {
|
||||||
name = this.trimName(name);
|
name = this.trimName(name);
|
||||||
return "%s. %s: %s".formatted(place+1, name, score);
|
return "%s. %s : %s".formatted(place+1, name, score);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getScores() {
|
public List<String> getScores() {
|
||||||
|
|||||||
Reference in New Issue
Block a user