Hide plugin.yml ingame

Discussion in 'Spigot Plugin Development' started by Minimigamer, Jan 8, 2020.


Have you got any Ideas how i could solve this issue ?

Poll closed Jan 22, 2020.
  1. Hide the plugin.yml

    0 vote(s)
  2. set command in plugin.yml when its executor is set

    1 vote(s)
Multiple votes are allowed.
  1. Hey guys I need some help here.
    I want to make a Plugin where u can disable spesific command so im looking if the command is enabled in my config and if yes, I set the executor with:
    getCommand("spawn").setExecutor(new hub_cmds());
    but if it is disabled i just dont set the Executor. But if I'm ingame and to /<PLUGIN> help it shows all the commands the plugin contains. Because i have to put them in the plugin.yml. so is there a way that if your ingame and you do /<PLUGIN> help you can only see the commands where I've set the executor?
  2. For 1.13+ you'd have to unregister the commands so they don't show up in the client.
  3. I have worked with regestering commands on runtime with my own plugins and if you want to remove a command you need to have this bit of code:
    Code (Java):
            SimplePluginManager spm = (SimplePluginManager) Bukkit.getServer().getPluginManager();
            Field f;
            SimpleCommandMap localSimpleCommandMap = null;
            try {
                f = SimplePluginManager.class.getDeclaredField("commandMap");
                localSimpleCommandMap = (SimpleCommandMap) f.get(spm);
            } catch (Exception e) {
                getLogger().log(Level.WARNING, "There went something wrong with getting the CommandMap.");
                getLogger().log(Level.WARNING, "Message: " + e.getMessage());
    And then if you want to remove the commands You have to do some extra work because the SimpleCommandMap doesn't have a methode to remove a command. So what you have to do is:

    1. Save all commands to an Collection
    2. Clone that Collection as it's unmodifiable (see SimpleCommandMap)
    3. Remove the command that you want to remove
    4. Register all commands again.

    I hope this helped a bit.
  4. Better use reflection to access the knownCommands field directly. Then deleting is easy again.
  5. Oh boy I wouldn’t want a plugin using this type of stuff on my server are you serious xD. Just use permissions!
  6. This is unrelated and doesn't answer the OP's question, nor does it improve upon an answer.
    • Funny Funny x 1
  7. It does answer: don’t use reflection it’s much more likely going to break something than using permissions. Instead use permissions which are built in and easy to use.
  8. I might be missing something here but permissions wont help in this case. The OP wants to remove commands that are disabled from being shown in a command, I don't see how permissions will help?
  9. That’s correct, but it doesn’t mean my answer is “unrelated,” I brought up how one solution offered here used reflection and the OP should be very careful with it and try to avoid if there are better alternatives, such as adding permission support instead of removing the command.

  10. do you might have an code example ? im not really sure how to do this?
  11. Strahan


    Well, yea, it really is. Your suggestion about reflection may be apt, but your answer to negate permissions has no relation to the OPs stated goal. The only relation is in that it is about commands in general. Negating permissions does absolutely nothing as far as suppressing completion.

    Personally, I'd do it as the link Kieraaaan posted suggests.
    • Informative Informative x 1
  12. In newer versions it should also hide the commands from the command list sent to the client for tab completion.
  13. Strahan


    True, I haven't tested newer versions so I should not speak in absolutes.
  14. But if u have op you can see the commands although their executer hasn't been set
  15. the3rdnumber is correct, if a player doesn't have the permission listed in plugin.yml for the command they wont see the command. You should also set
    send-namespaced: false
    in spigot.yml (its true by default for some bizarre reason)

    Using reflection is perfectly safe and i use it in addition to the items listed above.
    Code (Java):
        private void unregisterCommand(PluginCommand command) {
            Field commandMap;
            Field knownCommands;
            try {
                commandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
                knownCommands = SimpleCommandMap.class.getDeclaredField("knownCommands");
                ((Map<String, Command>) knownCommands.get((SimpleCommandMap) commandMap.get(Bukkit.getServer())))
                command.unregister((CommandMap) commandMap.get(Bukkit.getServer()));
            } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
                StringBuilder err = new StringBuilder("Failed to unregister command '");
                err.append("'! ");