Skip to content

Commit

Permalink
Merge branch 'master' into ver/1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle.kts
  • Loading branch information
acrylic-style committed Aug 21, 2024
2 parents 86efe14 + 944ec6f commit fd40643
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "net.azisaba"
version = "1.20.2+6.16.8a"
version = "1.20.2+6.16.9"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -16,7 +15,8 @@

public class ScheduleRestartCommand implements TabExecutor {
private static final Map<Integer, Set<Action>> ACTIONS = new HashMap<>();
private static final List<BukkitTask> tasks = new ArrayList<>();
private static final List<TimerTask> tasks = new ArrayList<>();
private static final Timer TIMER = new Timer();
private static boolean whitelistWasOn = false;
private final LifeCore plugin;

Expand All @@ -34,28 +34,36 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
plugin.getGcListener().triggerNow();
return true;
}
if (args[0].endsWith("s")) {
int seconds = Integer.parseInt(args[0].substring(0, args[0].length() - 1));
schedule(seconds);
return true;
}
int minutes = Integer.parseInt(args[0]);
schedule(minutes);
schedule(minutes * 60);
return true;
}

public static void schedule(int minutes) {
for (BukkitTask task : tasks) {
public static void schedule(int paramSeconds) {
for (TimerTask task : tasks) {
task.cancel();
}
tasks.clear();
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§d" + minutes + "分後" + "§aに再起動されます。");
int maxTicks = minutes * 60 * 20;
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§d" + paramSeconds + "秒後" + "§aに再起動されます。");
ACTIONS.forEach((seconds, actions) -> {
if (seconds < minutes * 60) {
BukkitTask task = Bukkit.getScheduler().runTaskLaterAsynchronously(LifeCore.getPlugin(LifeCore.class), () -> {
Bukkit.getScheduler().runTask(LifeCore.getPlugin(LifeCore.class), () -> {
for (Action action : actions) {
action.execute(seconds);
}
});
}, maxTicks - seconds * 20);
tasks.add(task);
if (seconds <= paramSeconds) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Bukkit.getScheduler().runTask(LifeCore.getPlugin(LifeCore.class), () -> {
for (Action action : actions) {
action.execute(seconds);
}
});
}
};
TIMER.schedule(timerTask, (paramSeconds - seconds) * 1000L);
tasks.add(timerTask);
}
});
}
Expand All @@ -69,28 +77,33 @@ public enum Action {
BROADCAST {
@Override
public void execute(int seconds) {
if (seconds >= 60) {
int minutes = seconds / 60;
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§d" + minutes + "分後" + "§aに再起動されます。");
} else {
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§c" + seconds + "秒後" + "§aに再起動されます。");
}
Bukkit.getScheduler().runTask(LifeCore.getPlugin(LifeCore.class), () -> {
if (seconds >= 60) {
int minutes = seconds / 60;
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§d" + minutes + "分後" + "§aに再起動されます。");
} else {
Bukkit.broadcastMessage("§6[§dお知らせ§6] §aこのサーバーは§c" + seconds + "秒後" + "§aに再起動されます。");
}
});
}
},
ENABLE_WHITELIST {
@Override
public void execute(int seconds) {
whitelistWasOn = Bukkit.hasWhitelist();
Bukkit.setWhitelist(true);
Bukkit.getScheduler().runTask(LifeCore.getPlugin(LifeCore.class), () -> {
whitelistWasOn = Bukkit.hasWhitelist();
Bukkit.setWhitelist(true);
});
}
},
SAVE_AND_KICK_ALL_PLAYERS {
@Override
public void execute(int seconds) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mpdb saveAndKick");
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer("Server closed");
}
Bukkit.getScheduler().runTask(LifeCore.getPlugin(LifeCore.class), () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer("Server closed");
}
});
}
},
SCHEDULE_SHUTDOWN_SERVER {
Expand Down

0 comments on commit fd40643

Please sign in to comment.