forked from upstream/ProAntiTab
Fix / & Skript Commands
This commit is contained in:
1 parent
72fed10eac
commit
2199baf178
2 files changed
+26
-17
No files matched your search
@@ -49,6 +49,8 @@ public class BukkitLoader extends JavaPlugin {
|
||||
plugin = this;
|
||||
logger = getLogger();
|
||||
|
||||
loadCommandMap();
|
||||
|
||||
Reflection.initialize(getServer());
|
||||
Storage.CURRENT_VERSION = getDescription().getVersion();
|
||||
|
||||
@@ -85,20 +87,6 @@ public class BukkitLoader extends JavaPlugin {
|
||||
|
||||
if(getServer().getPluginManager().getPlugin("ViaVersion") != null)
|
||||
ViaVersionAdapter.initialize();
|
||||
|
||||
try {
|
||||
if (Bukkit.getPluginManager() instanceof SimplePluginManager) {
|
||||
Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getPluginManager());
|
||||
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
commandsMap = (Map<String, Command>)knownCommandsField.get(simpleCommandMap);
|
||||
}
|
||||
}catch (Throwable ignored) { }
|
||||
|
||||
if(commandsMap == null)
|
||||
Logger.warning("Failed injection task! Skript commands won't be detected with that.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -188,9 +176,9 @@ public class BukkitLoader extends JavaPlugin {
|
||||
BukkitAntiTabListener.handleTabCompletion(Storage.ConfigSections.Settings.TURN_BLACKLIST_TO_WHITELIST.ENABLED ? Storage.Blacklist.getBlacklist().getCommands() : getNotBlockedCommands());
|
||||
}
|
||||
|
||||
public static boolean doesCommandExist(String command) {
|
||||
public static boolean doesCommandExist(String command, boolean replace) {
|
||||
if(commandsMap == null) return false;
|
||||
if(command.startsWith("/")) command = StringUtils.replaceFirst(command, "/", "");
|
||||
if(command.startsWith("/") && replace) command = StringUtils.replaceFirst(command, "/", "");
|
||||
|
||||
for (String currentCommand : commandsMap.keySet())
|
||||
if (currentCommand.equals(command)) return true;
|
||||
@@ -198,6 +186,22 @@ public class BukkitLoader extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void loadCommandMap() {
|
||||
try {
|
||||
if (Bukkit.getPluginManager() instanceof SimplePluginManager) {
|
||||
Field commandMapField = SimplePluginManager.class.getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getPluginManager());
|
||||
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
commandsMap = (Map<String, Command>)knownCommandsField.get(simpleCommandMap);
|
||||
}
|
||||
}catch (Throwable ignored) { }
|
||||
|
||||
if(commandsMap == null)
|
||||
Logger.warning("Failed injection task! Skript commands won't be detected with that.");
|
||||
}
|
||||
|
||||
public static List<String> getNotBlockedCommands() {
|
||||
List<String> commands = new ArrayList<>();
|
||||
Bukkit.getHelpMap().getHelpTopics().stream()
|
||||
@@ -206,6 +210,11 @@ public class BukkitLoader extends JavaPlugin {
|
||||
return commands;
|
||||
}
|
||||
|
||||
public static List<String> getAllCommands() {
|
||||
if(commandsMap == null) return getNotBlockedCommands();
|
||||
return Arrays.asList(commandsMap.keySet().toArray(new String[] { }));
|
||||
}
|
||||
|
||||
public static Plugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class BukkitBlockCommandListener implements Listener {
|
||||
HelpTopic helpTopic = Bukkit.getHelpMap().getHelpTopic(command);
|
||||
|
||||
if(helpTopic == null && !event.isCancelled()) {
|
||||
if(!BukkitLoader.doesCommandExist(command)) {
|
||||
if(!BukkitLoader.doesCommandExist(command, false)) {
|
||||
event.setCancelled(true);
|
||||
MessageTranslator.send(player, Storage.ConfigSections.Settings.CUSTOM_UNKNOWN_COMMAND.MESSAGE);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user