forked from mc/VTools
1
0
Fork 0

修理最后一分钟不更新置顶的顺序问题,以及使用shutdown命令双重提示的问题

This commit is contained in:
Sodium-Aluminate 2023-12-25 00:03:28 +08:00
parent d647b99465
commit 85e1bf1ca4
2 changed files with 34 additions and 20 deletions

View File

@ -101,7 +101,7 @@ public class ServerCloser {
while (!lock.isEmpty()) {
lock.poll().cancel();
}
lock.add(new Counter(INSTANCE, 1, "收到关机命令已经过了 %s 分钟,即将关机。").start());
lock.add(new Counter(INSTANCE, 1).reason("收到关机命令已经过了 %s 分钟,即将关机。").noLastWarning().start());
}
}
@ -110,7 +110,7 @@ public class ServerCloser {
while (!lock.isEmpty()) {
lock.poll().cancel();
}
lock.add(new Counter(INSTANCE, 60, "虽然关机被取消,但 %s 分钟内依旧没有玩家上线,即将关机。").start());
lock.add(new Counter(INSTANCE, 60).reason("虽然关机被取消,但 %s 分钟内依旧没有玩家上线,即将关机。").start());
}
}
@ -127,15 +127,25 @@ public class ServerCloser {
private final int totalMin;
private int minLeft;
private boolean canceled = false;
private final String reason;
private String reason;
private static final String DEFAULT_REASON = "距离上一个玩家离开已经过了 %s 分钟,即将关机。";
private boolean lastWarning = true;
protected Counter(ServerCloser instance, int minute) {this(instance, minute, null);}
protected Counter(ServerCloser instance, int minute, String reason) {
protected Counter(ServerCloser instance, int minute) {
this.instance = instance;
totalMin = minute;
minLeft = minute;
this.reason = Objects.requireNonNullElse(reason, "距离上一个玩家离开已经过了 %s 分钟,即将关机。");
this.reason = DEFAULT_REASON;
}
public Counter reason(String reason) {
this.reason = reason;
return this;
}
public Counter noLastWarning() {
lastWarning = false;
return this;
}
protected synchronized void cancel() {
@ -159,22 +169,13 @@ public class ServerCloser {
while (true) {
if (canceled) return;
TGBridge.setShuttingDown(minLeft);
try {
this.wait(MINUTE);
} catch (InterruptedException ignored) {}
if (canceled) return;
if (!instance.server.getAllPlayers().isEmpty()) {
instance.plugin.logger.error("ServerCloser: 定时器发现服务器有人。这不应发生,因为定时器本应该被直接打断。");
TGBridge.error("ServerCloser: #bug @NaAlOH4 定时器发现服务器有人。这不应发生,因为定时器本应该被直接打断。");
canceled = true;
}
if (canceled) return;
minLeft--;
switch (minLeft) {
case 1 -> {
String msg = "服务器即将在一分钟后关机,使用 /fuck 以取消。";
instance.plugin.logger.info(msg);
TGBridge.log(msg);
if (lastWarning) {
TGBridge.log(msg);
}
}
case 0 -> {
String msg = "ServerCloser: " + reason.formatted(totalMin);
@ -190,6 +191,19 @@ public class ServerCloser {
}
default -> instance.plugin.logger.info("服务器即将在 {} 分钟后关机", minLeft);
}
try {
this.wait(MINUTE);
} catch (InterruptedException ignored) {}
if (canceled) return;
if (!instance.server.getAllPlayers().isEmpty()) {
instance.plugin.logger.error("ServerCloser: 定时器发现服务器有人。这不应发生,因为定时器本应该被直接打断。");
TGBridge.error("ServerCloser: #bug @NaAlOH4 定时器发现服务器有人。这不应发生,因为定时器本应该被直接打断。");
canceled = true;
}
if (canceled) return;
minLeft--;
}
}
}

View File

@ -174,7 +174,7 @@ public class TGBridge {
case "/shutdown" -> {
if (server.getAllPlayers().isEmpty()) {
ServerCloser.INSTANCE.fastShutdown();
outbound("server will shutdown in 1 minute.\nuse /fuck to cancel.");
outbound("服务器即将在一分钟后关机,使用 /fuck 以取消。");
} else {
outbound("still player online, can't shutdown.");
}