Fix status command formatting and add last render times to status and maps commands
This commit is contained in:
parent
7097547301
commit
2e572ddb11
|
@ -34,10 +34,18 @@ import de.bluecolored.bluemap.core.world.World;
|
||||||
import org.apache.commons.lang3.time.DurationFormatUtils;
|
import org.apache.commons.lang3.time.DurationFormatUtils;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CommandHelper {
|
public class CommandHelper {
|
||||||
|
|
||||||
|
private static final DateTimeFormatter TIME_FORMAT =
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")
|
||||||
|
.withLocale(Locale.ROOT)
|
||||||
|
.withZone(ZoneId.systemDefault());
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
private final Map<String, WeakReference<RenderTask>> taskRefMap;
|
private final Map<String, WeakReference<RenderTask>> taskRefMap;
|
||||||
|
|
||||||
|
@ -67,7 +75,9 @@ public class CommandHelper {
|
||||||
|
|
||||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ", status, TextColor.WHITE, "!"));
|
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ", status, TextColor.WHITE, "!"));
|
||||||
|
|
||||||
if (!tasks.isEmpty()) {
|
if (tasks.isEmpty()) {
|
||||||
|
lines.add(Text.of(TextColor.GRAY, " Last time running: ", TextColor.DARK_GRAY, formatTime(renderer.getLastTimeBusy())));
|
||||||
|
} else {
|
||||||
lines.add(Text.of(TextColor.WHITE, " Queued Tasks (" + tasks.size() + "):"));
|
lines.add(Text.of(TextColor.WHITE, " Queued Tasks (" + tasks.size() + "):"));
|
||||||
for (int i = 0; i < tasks.size(); i++) {
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
if (i >= 10){
|
if (i >= 10){
|
||||||
|
@ -76,20 +86,18 @@ public class CommandHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTask task = tasks.get(i);
|
RenderTask task = tasks.get(i);
|
||||||
lines.add(Text.of(TextColor.GRAY, " [" + getRefForTask(task) + "] ", TextColor.GOLD, task.getDescription()));
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0[" + getRefForTask(task) + "] ", TextColor.GOLD, task.getDescription()));
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
String detail = task.getDetail().orElse(null);
|
task.getDetail().ifPresent(detail ->
|
||||||
if (detail != null) {
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Detail: ", TextColor.WHITE, detail)));
|
||||||
lines.add(Text.of(TextColor.GRAY, " Detail: ", TextColor.WHITE, detail));
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.add(Text.of(TextColor.GRAY, " Progress: ", TextColor.WHITE,
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Progress: ", TextColor.WHITE,
|
||||||
(Math.round(task.estimateProgress() * 10000) / 100.0) + "%"));
|
(Math.round(task.estimateProgress() * 10000) / 100.0) + "%"));
|
||||||
|
|
||||||
long etaMs = renderer.estimateCurrentRenderTaskTimeRemaining();
|
long etaMs = renderer.estimateCurrentRenderTaskTimeRemaining();
|
||||||
if (etaMs > 0) {
|
if (etaMs > 0) {
|
||||||
lines.add(Text.of(TextColor.GRAY, " ETA: ", TextColor.WHITE, DurationFormatUtils.formatDuration(etaMs, "HH:mm:ss")));
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0ETA: ", TextColor.WHITE, DurationFormatUtils.formatDuration(etaMs, "HH:mm:ss")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +106,7 @@ public class CommandHelper {
|
||||||
if (plugin.checkPausedByPlayerCount()) {
|
if (plugin.checkPausedByPlayerCount()) {
|
||||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||||
Text.of(TextColor.GOLD, "paused")));
|
Text.of(TextColor.GOLD, "paused")));
|
||||||
lines.add(Text.of(TextColor.GRAY, TextFormat.ITALIC, " (there are " + plugin.getConfigs().getPluginConfig().getPlayerRenderLimit() + " or more players online)"));
|
lines.add(Text.of(TextColor.GRAY, TextFormat.ITALIC, "\u00A0\u00A0\u00A0(there are " + plugin.getConfigs().getPluginConfig().getPlayerRenderLimit() + " or more players online)"));
|
||||||
} else {
|
} else {
|
||||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||||
Text.of(TextColor.RED, "stopped")
|
Text.of(TextColor.RED, "stopped")
|
||||||
|
@ -176,4 +184,9 @@ public class CommandHelper {
|
||||||
return ref.subSequence(0, 4).toString();
|
return ref.subSequence(0, 4).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String formatTime(long timestamp) {
|
||||||
|
if (timestamp < 0) return "-";
|
||||||
|
return TIME_FORMAT.format(Instant.ofEpochMilli(timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -838,27 +838,28 @@ public class Commands<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int mapsCommand(CommandContext<S> context) {
|
public int mapsCommand(CommandContext<S> context) {
|
||||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
List<Text> lines = new ArrayList<>();
|
||||||
|
lines.add(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
|
||||||
|
|
||||||
source.sendMessage(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
|
|
||||||
for (BmMap map : plugin.getMaps().values()) {
|
for (BmMap map : plugin.getMaps().values()) {
|
||||||
boolean unfrozen = plugin.getPluginState().getMapState(map).isUpdateEnabled();
|
boolean frozen = !plugin.getPluginState().getMapState(map).isUpdateEnabled();
|
||||||
if (unfrozen) {
|
|
||||||
source.sendMessage(Text.of(
|
lines.add(Text.of(TextColor.GRAY, " - ",
|
||||||
TextColor.GRAY, " - ",
|
TextColor.WHITE, map.getId(),
|
||||||
TextColor.WHITE, map.getId(),
|
TextColor.GRAY, " (" + map.getName() + ")"));
|
||||||
TextColor.GRAY, " (" + map.getName() + ")"
|
|
||||||
).setHoverText(Text.of(TextColor.WHITE, "World: ", TextColor.GRAY, map.getWorld().getName())));
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0World: ",
|
||||||
} else {
|
TextColor.DARK_GRAY, map.getWorld().getName()));
|
||||||
source.sendMessage(Text.of(
|
lines.add(Text.of(TextColor.GRAY, "\u00A0\u00A0\u00A0Last Update: ",
|
||||||
TextColor.GRAY, " - ",
|
TextColor.DARK_GRAY, helper.formatTime(map.getRenderState().getLatestRenderTime())));
|
||||||
TextColor.WHITE, map.getId(),
|
|
||||||
TextColor.GRAY, " (" + map.getName() + ") - ",
|
if (frozen)
|
||||||
TextColor.AQUA, TextFormat.ITALIC, "frozen!"
|
lines.add(Text.of(TextColor.AQUA, TextFormat.ITALIC, "This map is frozen!"));
|
||||||
).setHoverText(Text.of(TextColor.WHITE, "World: ", TextColor.GRAY, map.getWorld().getName())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||||
|
source.sendMessages(lines);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class RenderManager {
|
||||||
@DebugDump private final int id;
|
@DebugDump private final int id;
|
||||||
@DebugDump private volatile boolean running;
|
@DebugDump private volatile boolean running;
|
||||||
|
|
||||||
|
@DebugDump private long lastTimeBusy;
|
||||||
|
|
||||||
private final AtomicInteger nextWorkerThreadIndex;
|
private final AtomicInteger nextWorkerThreadIndex;
|
||||||
@DebugDump private final Collection<WorkerThread> workerThreads;
|
@DebugDump private final Collection<WorkerThread> workerThreads;
|
||||||
private final AtomicInteger busyCount;
|
private final AtomicInteger busyCount;
|
||||||
|
@ -55,6 +57,8 @@ public class RenderManager {
|
||||||
this.workerThreads = new ConcurrentLinkedDeque<>();
|
this.workerThreads = new ConcurrentLinkedDeque<>();
|
||||||
this.busyCount = new AtomicInteger(0);
|
this.busyCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
this.lastTimeBusy = -1;
|
||||||
|
|
||||||
this.progressTracker = null;
|
this.progressTracker = null;
|
||||||
this.newTask = true;
|
this.newTask = true;
|
||||||
|
|
||||||
|
@ -249,6 +253,10 @@ public class RenderManager {
|
||||||
return workerThreads.size();
|
return workerThreads.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastTimeBusy() {
|
||||||
|
return lastTimeBusy;
|
||||||
|
}
|
||||||
|
|
||||||
private void removeTasksThatAreContainedIn(RenderTask containingTask) {
|
private void removeTasksThatAreContainedIn(RenderTask containingTask) {
|
||||||
synchronized (this.renderTasks) {
|
synchronized (this.renderTasks) {
|
||||||
if (renderTasks.size() < 2) return;
|
if (renderTasks.size() < 2) return;
|
||||||
|
@ -290,13 +298,15 @@ public class RenderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.busyCount.incrementAndGet();
|
this.busyCount.incrementAndGet();
|
||||||
|
this.lastTimeBusy = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
task.doWork();
|
task.doWork();
|
||||||
} finally {
|
} finally {
|
||||||
synchronized (renderTasks) {
|
synchronized (renderTasks) {
|
||||||
this.busyCount.decrementAndGet();
|
int busyCount = this.busyCount.decrementAndGet();
|
||||||
|
if (busyCount > 0) this.lastTimeBusy = System.currentTimeMillis();
|
||||||
this.renderTasks.notifyAll();
|
this.renderTasks.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,7 @@ public class BmMap {
|
||||||
|
|
||||||
public synchronized void savePlayerState() {
|
public synchronized void savePlayerState() {
|
||||||
try (
|
try (
|
||||||
OutputStream out = storage.writeMeta(id, META_FILE_PLAYERS);
|
OutputStream out = storage.writeMeta(id, META_FILE_PLAYERS)
|
||||||
) {
|
) {
|
||||||
out.write("{}".getBytes(StandardCharsets.UTF_8));
|
out.write("{}".getBytes(StandardCharsets.UTF_8));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import java.util.zip.GZIPOutputStream;
|
||||||
public class MapRenderState {
|
public class MapRenderState {
|
||||||
|
|
||||||
private final Map<Vector2i, Long> regionRenderTimes;
|
private final Map<Vector2i, Long> regionRenderTimes;
|
||||||
|
private transient long latestRenderTime = -1;
|
||||||
|
|
||||||
public MapRenderState() {
|
public MapRenderState() {
|
||||||
regionRenderTimes = new HashMap<>();
|
regionRenderTimes = new HashMap<>();
|
||||||
|
@ -44,6 +45,13 @@ public class MapRenderState {
|
||||||
|
|
||||||
public synchronized void setRenderTime(Vector2i regionPos, long renderTime) {
|
public synchronized void setRenderTime(Vector2i regionPos, long renderTime) {
|
||||||
regionRenderTimes.put(regionPos, renderTime);
|
regionRenderTimes.put(regionPos, renderTime);
|
||||||
|
|
||||||
|
if (latestRenderTime != -1) {
|
||||||
|
if (renderTime > latestRenderTime)
|
||||||
|
latestRenderTime = renderTime;
|
||||||
|
else
|
||||||
|
latestRenderTime = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized long getRenderTime(Vector2i regionPos) {
|
public synchronized long getRenderTime(Vector2i regionPos) {
|
||||||
|
@ -52,6 +60,19 @@ public class MapRenderState {
|
||||||
else return renderTime;
|
else return renderTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLatestRenderTime() {
|
||||||
|
if (latestRenderTime == -1) {
|
||||||
|
synchronized (this) {
|
||||||
|
latestRenderTime = regionRenderTimes.values().stream()
|
||||||
|
.mapToLong(Long::longValue)
|
||||||
|
.max()
|
||||||
|
.orElse(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return latestRenderTime;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void reset() {
|
public synchronized void reset() {
|
||||||
regionRenderTimes.clear();
|
regionRenderTimes.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue