-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReloadCatcher.java
More file actions
44 lines (37 loc) · 1.37 KB
/
Copy pathReloadCatcher.java
File metadata and controls
44 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ru.cwcode.cwutils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerLoadEvent;
import org.jetbrains.annotations.NotNull;
public class ReloadCatcher implements Listener {
private static void sendWarning() {
Bukkit.getLogger().severe(warningMessage());
}
private static void sendWarning(CommandSender sender) {
sender.sendMessage(warningMessage());
}
private static @NotNull String warningMessage() {
return "Restarting a Minecraft server with the /reload confirm command can be dangerous," +
" as it reloads all plugins and configuration files without completely rebooting the server." +
" This can lead to: Loss of data or progress;" +
" Plugins not working correctly;" +
" Possible crashes and errors.";
}
@EventHandler
void onCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (event.getMessage().equals("/reload confirm")) {
event.setCancelled(true);
sendWarning(event.getPlayer());
}
}
@EventHandler
void onServerReload(ServerLoadEvent event) {
if (event.getType() == ServerLoadEvent.LoadType.RELOAD) {
sendWarning();
Bukkit.getServer().shutdown();
}
}
}