9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-21 07:49:18 +00:00

update reload command; update branding; remove timings configuration; hide unnecessary compilation warnings

This commit is contained in:
NONPLAYT
2024-05-20 07:39:30 +03:00
parent ceababc81d
commit 82ac2dcca1
5 changed files with 202 additions and 60 deletions

View File

@@ -3,29 +3,24 @@ From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 12 Jun 2023 00:23:38 +0300
Subject: [PATCH] Disable reload command by default
This is fully rewritten reload command. Reloading in Bukkit VERY, VERY UNSTABLE and I removed it
This is fully rewritten reload command, you can enable or disable it with -DDivineMC.EnableReloadCommand flag
Read this article why reload is VERY UNSAFE in Bukkit: https://madelinemiller.dev/blog/problem-with-reload/
diff --git a/src/main/java/org/bukkit/command/defaults/ReloadCommand.java b/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
index bdfe68b386b5ca2878475e548d3c9a3808fce848..ce4aa866eacd5c07f915986cee740edf007e6978 100644
index bdfe68b386b5ca2878475e548d3c9a3808fce848..0a21f2138969f75425b720487e626aac796821d1 100644
--- a/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
+++ b/src/main/java/org/bukkit/command/defaults/ReloadCommand.java
@@ -1,13 +1,10 @@
@@ -1,8 +1,7 @@
package org.bukkit.command.defaults;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
+
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
+import net.kyori.adventure.text.format.NamedTextColor; // DivineMC
public class ReloadCommand extends BukkitCommand {
public ReloadCommand(@NotNull String name) {
@@ -15,7 +12,7 @@ public class ReloadCommand extends BukkitCommand {
@@ -15,7 +14,7 @@ public class ReloadCommand extends BukkitCommand {
this.description = "Reloads the server configuration and plugins";
this.usageMessage = "/reload [permissions|commands|confirm]"; // Paper
this.setPermission("bukkit.command.reload");
@@ -34,7 +29,7 @@ index bdfe68b386b5ca2878475e548d3c9a3808fce848..ce4aa866eacd5c07f915986cee740edf
}
@org.jetbrains.annotations.ApiStatus.Internal // Paper
@@ -25,48 +22,12 @@ public class ReloadCommand extends BukkitCommand {
@@ -25,48 +24,53 @@ public class ReloadCommand extends BukkitCommand {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) { // Paper
if (!testPermission(sender)) return true;
@@ -48,23 +43,47 @@ index bdfe68b386b5ca2878475e548d3c9a3808fce848..ce4aa866eacd5c07f915986cee740edf
- } else if ("commands".equalsIgnoreCase(args[0])) {
- if (Bukkit.getServer().reloadCommandAliases()) {
- Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Command aliases successfully reloaded.", net.kyori.adventure.text.format.NamedTextColor.GREEN));
- } else {
+ // DivineMC start - disable reload command by default & add startup flag
+ if (System.getProperty("DivineMC.EnableReloadCommand") == null || false) {
+ sender.sendMessage(net.kyori.adventure.text.Component.text("Operation denied, command disabled.", net.kyori.adventure.text.format.NamedTextColor.RED ));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("Reload command SHOULD NEVER be used in whatever circumstances.", net.kyori.adventure.text.format.NamedTextColor.YELLOW));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("DivineMC has intentionally disabled it in order to stop you using it, instead of restarting your server.", net.kyori.adventure.text.format.NamedTextColor.YELLOW));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("If you still want to enable reload command, add -DDivineMC.EnableReloadCommand=true flag to your startup arguments.", net.kyori.adventure.text.format.NamedTextColor.YELLOW));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("---------------------------------------------", net.kyori.adventure.text.format.NamedTextColor.GREEN));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("RESTART YOUR SERVER AND NEVER USE /reload", net.kyori.adventure.text.format.NamedTextColor.YELLOW));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("To learn more, read this article: https://madelinemiller.dev/blog/problem-with-reload", net.kyori.adventure.text.format.NamedTextColor.GREEN));
+ } else {
+ if (args.length == 1) {
+ if (args[0].equalsIgnoreCase("permissions")) {
+ Bukkit.getServer().reloadPermissions();
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Permissions successfully reloaded.", net.kyori.adventure.text.format.NamedTextColor.GREEN));
+ return true;
+ } else if ("commands".equalsIgnoreCase(args[0])) {
+ if (Bukkit.getServer().reloadCommandAliases()) {
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Command aliases successfully reloaded.", net.kyori.adventure.text.format.NamedTextColor.GREEN));
+ } else {
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("An error occurred while trying to reload command aliases.", net.kyori.adventure.text.format.NamedTextColor.RED));
+ }
+ return true;
} else {
- Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("An error occurred while trying to reload command aliases.", net.kyori.adventure.text.format.NamedTextColor.RED));
- }
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Usage: " + usageMessage, net.kyori.adventure.text.format.NamedTextColor.RED));
+ return true;
}
- return true;
- } else if ("confirm".equalsIgnoreCase(args[0])) {
- confirmed = true;
- } else {
- Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Usage: " + usageMessage, net.kyori.adventure.text.format.NamedTextColor.RED));
- return true;
- }
}
- }
- if (!confirmed) {
- Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Are you sure you wish to reload your server? Doing so may cause bugs and memory leaks. It is recommended to restart instead of using /reload. To confirm, please type ", net.kyori.adventure.text.format.NamedTextColor.RED).append(net.kyori.adventure.text.Component.text("/reload confirm", net.kyori.adventure.text.format.NamedTextColor.YELLOW)));
- return true;
- }
- // Paper end
-
- Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
- Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
- // Paper start - lifecycle events
@@ -74,15 +93,25 @@ index bdfe68b386b5ca2878475e548d3c9a3808fce848..ce4aa866eacd5c07f915986cee740edf
- if (ex.getMessage().equals(RELOADING_DISABLED_MESSAGE)) {
- Command.broadcastCommandMessage(sender, ChatColor.RED + RELOADING_DISABLED_MESSAGE);
- return true;
- }
- }
+ Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
+ Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
+ // Paper start - lifecycle events
+ try {
+ Bukkit.reload();
+ } catch (final IllegalStateException ex) {
+ if (ex.getMessage().equals(RELOADING_DISABLED_MESSAGE)) {
+ Command.broadcastCommandMessage(sender, ChatColor.RED + RELOADING_DISABLED_MESSAGE);
+ return true;
+ }
}
+ // Paper end - lifecycle events
+ Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
+
+ return true;
}
- // Paper end - lifecycle events
- Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
-
+ // DivineMC start - Disable reload command by default
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Reloading disabled by default in DivineMC.", NamedTextColor.RED));
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("This is a permanent change!", NamedTextColor.RED));
+ Command.broadcastCommandMessage(sender, net.kyori.adventure.text.Component.text("Read here why it is unsafe: https://madelinemiller.dev/blog/problem-with-reload", NamedTextColor.GREEN));
return true;
+ // DivineMC end
}