/*
 * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject to
 *  the following conditions:
 *
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package co.aikar.commands;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.plugin.Plugin;

import java.util.Map;

@SuppressWarnings("WeakerAccess")
public class BukkitCommandManager implements CommandManager {

    @SuppressWarnings("WeakerAccess")
    protected final Plugin plugin;
    protected CommandContexts contexts;
    protected CommandCompletions completions;

    public BukkitCommandManager(Plugin plugin) {
        this.plugin = plugin;
    }

    @Override
    public Plugin getPlugin() {
        return this.plugin;
    }

    @Override
    public CommandContexts getCommandContexts() {
        if (this.contexts == null) {
            this.contexts = new BukkitCommandContexts();
        }
        return contexts;
    }

    @Override
    public CommandCompletions getCommandCompletions() {
        if (this.completions == null) {
            this.completions = new BukkitCommandCompletions();
        }
        return completions;
    }

    @Override
    public boolean registerCommand(BaseCommand command) {
        final String plugin = this.plugin.getName().toLowerCase();
        final CommandMap commandMap = Bukkit.getServer().getCommandMap();
        command.onRegister(this);
        boolean allSuccess = true;
        for (Map.Entry<String, Command> entry : command.registeredCommands.entrySet()) {
            if (!commandMap.register(entry.getKey().toLowerCase(), plugin, entry.getValue())) {
                allSuccess = false;
            }
        }

        return allSuccess;
    }
}

@@ -1211,16 +1211,42 @@
 Bukkit;%0A
+import org.bukkit.Server;%0A
 import o
@@ -1272,16 +1272,16 @@
 ommand;%0A
-
 import o
@@ -1344,16 +1344,49 @@
 lugin;%0A%0A
+import java.lang.reflect.Method;%0A
 import j
@@ -1566,24 +1566,65 @@
 gin plugin;%0A
+    private final CommandMap commandMap;%0A
     protecte
@@ -1769,32 +1769,527 @@
 lugin = plugin;%0A
+        CommandMap commandMap = null;%0A        try %7B%0A            Server server = Bukkit.getServer();%0A            Method getCommandMap = server.getClass().getDeclaredMethod(%22getCommandMap%22);%0A            getCommandMap.setAccessible(true);%0A            commandMap = (CommandMap) getCommandMap.invoke(server);%0A        %7D catch (Exception e) %7B%0A            ACFLog.severe(%22Failed to get Command Map. ACF will not function.%22);%0A            ACFUtil.sneaky(e);%0A        %7D%0A        this.commandMap = commandMap;%0A
     %7D%0A%0A    @Over
@@ -2352,32 +2352,106 @@
 .plugin;%0A    %7D%0A%0A
+    public CommandMap getCommandMap() %7B%0A        return commandMap;%0A    %7D%0A%0A
     @Override%0A  
@@ -2920,24 +2920,24 @@
  command) %7B%0A
+
         fina
@@ -2995,82 +2995,8 @@
 ();%0A
-        final CommandMap commandMap = Bukkit.getServer().getCommandMap();%0A
     

Use reflection to get the command map to support CraftBukkit/Spigot