引入时间

This commit is contained in:
2024-12-20 03:49:39 +08:00
parent a281e2924b
commit 8cf3fcb6d5
3 changed files with 66 additions and 2 deletions

View File

@@ -2,12 +2,14 @@ package ling.coordinateRecorder.Listener;
import ling.coordinateRecorder.CoordinateRecorder;
import ling.coordinateRecorder.data.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/// 在线玩家集合
@@ -17,7 +19,13 @@ public class PlayerMap {
protected static final PlayerMap current = new PlayerMap();
private PlayerMap() {
Bukkit.getScheduler().runTaskTimer(CoordinateRecorder.getCurrent(), this::flashTime, 0L, 200L);
}
private void flashTime() {
for (Map.Entry<UUID, PlayerData> enter : playerList.entrySet()) {
enter.getValue().flashTime();
}
}
public static PlayerMap getCurrent() {

View File

@@ -107,6 +107,10 @@ public class PlayerData {
ui.flashLocations();
}
public void flashTime() {
ui.flashTime();
}
/// 玩家位置信息发生改变
public void updateLocal() {
ui.playerMove();

View File

@@ -44,14 +44,66 @@ public class ScoreboardUI {
meLocation.setScore(999);
if (playerData.settings.getShowtime()) {
time = this.objective.getScore("时间");
var world = location.getWorld();
time = this.objective.getScore(world == null ? "Error" : getFormatTime(world.getTime()));
time.setScore(998);
}
Score line = objective.getScore("");
line.setScore(997);
player.setScoreboard(this.scoreboard);
flashLocations();
}
protected void flashTime() {
var world = location.getWorld();
if (world == null)
return;
this.scoreboard.resetScores(time.getEntry());
time = objective.getScore(getFormatTime(world.getTime()));
time.setScore(998);
}
public static String getFormatTime(long newTime) {
long hour = newTime / 1000;
/*long minute = (long) (newTime % 1000 * 0.06);
String tmp = "";
if (minute < 10) {
tmp += "0" + minute;
} else {
tmp += minute;
}*/
String hold;
long t = hour + 6 >= 24 ? hour + 6 - 24 : hour + 6;
if (t <= 2)
hold = "深夜";
else if (t <= 4)
hold = "凌晨";
else if (t <= 6)
hold = "早晨";
else if (t <= 11)
hold = "上午";
else if (t <= 12)
hold = "正午";
else if (t <= 17)
hold = "下午";
else if (t <= 19)
hold = "傍晚";
else if (t <= 22)
hold = "晚上";
else
hold = "深夜";
if (hour + 6 >= 24) {
return hold + " 0" + (hour + 6 - 24) + "";
} else {
return hold + " " + (hour + 6) + "";
}
}
protected boolean isLocal(Location l1, Location l2) {
if ((long) l1.getX() != (long) l2.getX())
return true;