[Class] ShadowCommands! Simple commands without plugin.yml

Discussion in 'Resources' started by MrAwellstein, Apr 30, 2014.

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


    This is a simple class that I created, used for creating commands without having to register them in the plugin.yml. This class is easy to use, and seems to work without problems although there might be one or two, as I was writing it late at night. Using this class it is possible to wrap over other commands, which gives the possibility of creating easy masking if you want to hide a plugin completely, or troll some people.

    Anyway, this is the step by step instructions. First create a listener in the onEnable method. I believe you can put it on onLoad() but keep it on onEnable() to be safe.
    2. @Override public void onEnable(){
    3. ShadowCommand.startListener(this);
    4. }
    5. //Please note that calling this method twice will cause a [b]AlreadyListeningException[/b].
    6. //If you supply it with a null Plugin, it will cause a [b]NullPointerException[/b]

    Now its time to create our first ShadowCommand. This command will echo back the users responses.
    2. public class EchoBack extends ShadowCommand{
    4. @Override public String CommandString(){
    5. return "echo"; //This is our command string.
    6. }
    8. @Override public boolean ActUpon(){
    9. //this is as simple as normal command, but wait, it doesn't have anything to work with?
    10. if(getArguments()!= null){
    11. String temp = "";
    12. for(String s: getArguments()){
    13. temp += s+" ";
    14. }
    15. temp.trim();
    16. getPlayer().sendMessage(temp);
    17. return true;
    18. }
    19. getPlayer().sendMessage(ChatColor.RED+"Invalid use of command");
    20. return true;
    21. }
    22. }

    Finally we need to register our command, so lets go back to our onEnable() method.
    2. @Override public void onEnable(){
    3. ShadowCommand.startListener(this);
    4. ShadowCommand.addCommand(new EchoBack());
    5. }

    And just like that we have a newly registered command.
    If you have any suggestions feel free to pitch in.
    Brought to you by, The ShadowCasted Team.

    here are the methods that you can use in your ShadowCommand class:
    public final static void setVisibleInConsole(boolean b);
    public final static boolean isVisibleInConsole();
    public final static Plugin getPlugin();
    public final static PlayerCommandPreprocessEvent getEvent();
    public final static boolean isCanceled();
    public final static void setCanceled(boolean b);
    public final static String getCommand();
    public final static void setCommand(String command);
    public final static Player getPlayer();
    public final static void setPlayer(Player p);
    public final static String[] getArguments();
    public final static void setArguments(String[] args);
    public final static void doCommand();
    //Run this if and when you are done changing variables like setPlayer(), getArguments(), or anything in similar 
    link: https://github.com/ShadowCasted/Buk...ukkit/magic/shadowcommand1/ShadowCommand.java
    au2001 and BetrayedQU like this.
  2. Offline


    I fixed an issue where getArguments() returned an invalid array as I uploaded an older version by mistake.
  3. Offline


    You shouldn't be using CommandPreProcessEvent to make commands. There are other ways of registering actual commands and actual help without touching the plugin.yml.
  4. Offline


    This isn't only to make commands. I am using it in a plugin to override other commands, to hide said commands. Plus i don't see why not to use it. Could you possibly give me a reason why?
  5. Offline


    If you're overriding commands, you could remove them from the commandmap and input yours, or use the event. But not for every command. You should register all commands into the CommandMap, with their respective HelpTopics, and for the overriden commands use the event.
  6. Offline


    I'll add that to the next update.

    Forgot to say, Despite overriding them, I'm not fully overriding them. I'm canceling them from even running for some players, and replacing what results happen to make it seem like they don't exist (the commands that are prevented from being acknowledged aren't from my plugin. if they were then it would be simple to fix it). Anyways there are other purposes for overriding a command per player that I could see. By the way what do you mean by overriding methods (I assumed you meant commands)?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 7, 2016
  7. Offline


    I meant commands, my bad, wasn't thinking there apparently. But you're not completely overriding the command. They still exist in the help topics and in the commandmap. If you removed the previous ones from the command map, and then put the one you want to override, then they won't exist at all.
  8. Offline


    The point is to not completely override. I'm not entirely sure but that could conflict with other plugins. Doing a soft override (or really redirect) allows the commands to still exist, but with the new command deciding what happens when someone calls them.
  9. Offline


    I know that post is kind of old, but I have a great example.
    My Permissions Utility uses the command /give <username> permission <perm> and to be able to even create that I have to soft override the /give command. Since I'm not completely overriding the command, the default /give command still works, while my command works as well.
  10. Offline


Thread Status:
Not open for further replies.

Share This Page