mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Identify and warn if a plugin hijacks the command map
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.logging.Logger;
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
final class ACFLog {
|
||||
private static final Logger LOGGER = Bukkit.getLogger();
|
||||
public static final String PREFIX = "[ACF] ";
|
||||
|
||||
private ACFLog() {}
|
||||
|
||||
@@ -42,19 +43,19 @@ final class ACFLog {
|
||||
|
||||
public static void info(String message) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.info(s);
|
||||
LOGGER.info(PREFIX + s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warn(String message) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.warning(s);
|
||||
LOGGER.warning(PREFIX + s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void severe(String message) {
|
||||
for (String s : ACFPatterns.NEWLINE.split(message)) {
|
||||
LOGGER.severe(s);
|
||||
LOGGER.severe(PREFIX + s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ final class ACFLog {
|
||||
final StackTraceElement[] stack = dbg.getStackTrace();
|
||||
for (int i = 0; i < lines && i < stack.length; i++) {
|
||||
final StackTraceElement cur = stack[i];
|
||||
Logger.getGlobal().severe(" " + cur);
|
||||
severe(" " + cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
@@ -58,6 +59,10 @@ public class BukkitCommandManager extends CommandManager {
|
||||
Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap");
|
||||
getCommandMap.setAccessible(true);
|
||||
commandMap = (CommandMap) getCommandMap.invoke(server);
|
||||
if (!commandMap.getClass().equals(SimpleCommandMap.class)) {
|
||||
ACFLog.severe("ERROR: CommandMap has been hijacked! Offending command map is located at: " + commandMap.getClass().getName());
|
||||
ACFLog.severe("Commands are most likely broken unless the hijacker did it in a friendly way.");
|
||||
}
|
||||
Field knownCommands = commandMap.getClass().getDeclaredField("knownCommands");
|
||||
knownCommands.setAccessible(true);
|
||||
//noinspection unchecked
|
||||
|
||||
Reference in New Issue
Block a user