Remove minecraft:commad

Discussion in 'Spigot Plugin Help' started by Peng1104, Jul 11, 2018.

  1. Hello comunity exist a way to remove the minecraft:command (I have a method that get All the comands EXEPT the minecraft ones (I mean it gets pluginname:tell but not get minecraft:tell) can some one help me??

    Here is the method:

    Code (Java):
    private static Field getBukkitCommandMap() throws NoSuchFieldException, SecurityException {
            Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
            bukkitCommandMap.setAccessible(true);
            return bukkitCommandMap;
        }
       
        private static Field getbukkitknownCommands() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
            Field bukkitknownCommands = commandMap().getClass().getDeclaredField("knownCommands");
            bukkitknownCommands.setAccessible(true);
            return bukkitknownCommands;
        }
       
        private static CommandMap commandMap() {
            try {
                return (CommandMap) getBukkitCommandMap().get(Bukkit.getServer());
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
                e.printStackTrace();
                return null;
            }
        }
       
        @SuppressWarnings("unchecked")
        private static Map<String, Command> knownCommands() {
            try {
                return (Map<String, Command>) getbukkitknownCommands().get(commandMap());
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
                e.printStackTrace();
                return null;
            }
        }
    to print all the commands I use: (it gets all the plugins registerd comands (including the bukkit and spigot commands)

    Code (Java):
    System.out.println(knownCommands().keySet())
     
  2. Optic_Fusion1

    Resource Staff

    minecraft commands are not part of Bukkit or spigot so you won't be able to get them that way, and honestly i can't really think of how you would go about getting them even with NMS
     
  3. But I have see plugins been able to do this...
     
  4. Optic_Fusion1

    Resource Staff

    link a plugin that's able to do this?
    It wouldn't be hard for me to get the code they use for that
     
  5. MiniDigger

    Supporter

    I guess they just use the command events to "remove" the commands.
     
  6. electronicboy

    IRC Staff

    Do it on the first tick, vanilla commands are registered into that map, albeit they're copied over from the vanilla servers command map and wrapped; CB redirects all command execution to the bukkit command map
     
    • Like Like x 1
  7. do you know on whitch class are the commands of minecaft saved on the map so that i could get them? So that on the second method (Command Map it self) I get the instance were all the comands are saved?
     
  8. This is the way I am doing it basicly making a command that start with "minecraft:" lost the prefix (but stiil it dont remove from the tab (when you are searching for a command)) For this I use the commandmap there if you remove 1 of the commands it does not show more on the tab (I have a special method that use this)
     
  9. Hey, still open, know how to do, I have done this for my server, stop command, and tab