Util Remove /help message!

Discussion in 'Resources' started by mine-care, Mar 21, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    mine-care

    It has been asked, how to block the bukkit help command (/bukkit:help), there are ways like overriding the class, creating and overriding the command itself but they will not allow customization... To do that i found out how to remove it and probably add your own custom messages under it also known as HelpTopics;

    The methods can be found here:
    Code (open)

    Code:
    public static void setHelpMap(HelpTopic...topic) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{
            CraftServer s = (CraftServer)Bukkit.getServer();
            SimpleHelpMap m = new SimpleHelpMap(s);
            for(HelpTopic t : topic) m.addTopic(t);
            Field f = s.getClass().getDeclaredField("helpMap");
            f.setAccessible(true);
            f.set(s, new SimpleHelpMap(s));
        }
    
        public static void setHelpMapVersionIndep(HelpTopic... topic)
                throws NoSuchFieldException, SecurityException,
                IllegalArgumentException, IllegalAccessException,
                ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException{
            Object s = Bukkit.getServer();
            String bukkitversion = Bukkit.getServer().getClass().getPackage().getName().substring(23);
            Object simplehmap = Class.forName("org.bukkit.craftbukkit."+bukkitversion+".help.SimpleHelpMap").getDeclaredConstructor(s.getClass()).newInstance(s);
            for(HelpTopic t : topic) simplehmap.getClass().getDeclaredMethod("addTopic", HelpTopic.class).invoke(simplehmap, t);
            Field f = s.getClass().getDeclaredField("helpMap");
            f.setAccessible(true);
            f.set(s, simplehmap);
        }


    From the code above ^ method 1 is the non version independed one, and the second is version independed. i understand there are a ton of exceptions thrown but, thats reflection... You can replace all the thrown exception with ReflectiveOperationException that is superclass for all of them,

    How to use:
    Invoke one of the abve methods on plugin enable, if you want custom topics provide them as:
    method(paramTopic,paramTopic,ParamTopic);
    you can also call this method without parameters at all, this way it will clear it up.

    How to use:
    The methods above take as parameter HelpTopic(s), A HelpTopic is an abstract class, so here is an example use:

    Here i cerate a class that extends HelpTopic, this class will be the one ill pass to the method above.

    Code:
    public class CommandGuiHelpTopic extends HelpTopic {
    
        private String command = "command";
        @Override
        public String getName() {
            return "Command"; //The name of the plugin displayed with gold color when you do /help
        }
    
        @Override
        public String getShortText() {
            return "Find the list of commands for Command."; //The description shown next to the name (see getName ^ )
        }
    
        @Override
        public String getFullText(CommandSender sender) {
            /*
             * Full text is displayed to the player when /help <nameofplugin> so if the name of the plugin (see getName ^ )
             * is "Command", and  i perform /help Command it will display the message returned by this method.
             *
             * The reason why you get a CommandSender as parameter, is because this command might not be executable by all command senders :- (
             * Like if the command above opens a gui, it cannot be executed by anything else other than a player.
             * So use it acordingly :- )
             */
            if (sender instanceof Player)
                return ChatColor.DARK_GREEN + "Use /" + command
                        + " to open Command";
            if (sender instanceof ConsoleCommandSender)
                return "Unfortunately, you cannot open Command from console.";
            else
                return "To open Command for a player type /" + command
                        + " <playername>";
        }
    
        @Override
        public boolean canSee(CommandSender s) {
            //In this method you can toggle the visibility for each command sedner :- ) so lets say i want
            //the command to be visible only for players, i check if the sender is a player and return the according value.
                return true;
        }
    
    }
    Then when i register it it magically apears in the help list as:

    Command: Find the list of commands for Command.
    :D

    hope you like it!
     
    Last edited: Apr 10, 2015
    CodePlaysMinecraft likes this.
  2. Offline

    Hawktasard

    @mine-care
    cool tutorial I guess but you misspelled the word been.
     
  3. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page