Command Interpreter

Discussion in 'Spigot Plugin Development' started by Stuperfied, Apr 13, 2017.

  1. Wasn't sure where to post this but I am in need of willing contributors to help with a project. So if your between projects and looking for a fill in, I could use the help. The project is a command interpreter which is a part of a utilities plugin. I wouldn't normally ask but I do believe this project is worth the time and effort.
    <GitHub Link>

    <Resource Link>

    Currently requires work on integrating some of the code listed on the resource page and some time put into the javadocs.
     
  2. I've done something kinda like this, and after looking at your resource page, I noticed you are still registering your commands with hard files. You could just register the commands in the plugin if you wanted to. That way it wouldn't require messing with any files outside of it.
     
  3. I kinda follow you, I think your referring to the sample code which creates commands.yml. Yeah, I found its a bit of a tossup trying to anticipate how the user is going to interact with the plugin. Its one of the main reasons I didn't incorporate that code into the plugin in the first place, there are so many different approaches that I wanted to allow the user the flexibility to choose whilst still providing something a novice would understand and be able to use.

    In the end, the plugin requires the user to provide their commands, the mapped classes with methods and any arguments to the constructors. Its really user choice where the commands are stored but I still feel that the plugin should be handling the mapping internally and an example of the plugins usage should be available in some form.
     
  4. Yea I gotchu. You also mentioned you want the mapping to be handled internally, the way I accomplished this was by getting the class and looping through annotated methods. The entire system was done basically through annotations, and the only thing needed to register the command was one, small, line in the onEnable. https://github.com/NJDaeger/BukkitCommonLib here is the project if you want to look at it.

    tl;dr
    I looped through the class I registered and got all the correctly annotated methods. I mapped the method names, and I mapped the class the method was in. Whenever the command was run I simply invoked the method which then ran the command.
     
  5. 3am here. Just getting a drink, i'll take a look and get back to you both in the morning. Thank you for the replies.
     
  6. Just got time to look further into this. After looking at these I am convinced that there has to be a best practice and it may be a combination of a few different methods. It needs a way for the user to easily provide thier commands, subcommands and arguments to the constructors. MaTaMoR_ seems to have a good way of storing the commands but I am keen to see how they are loaded.

    @NJDaeger That is certainly a novel idea and practical also. Still sorting through how it all works but I assume the person making the plugin would need to provide your plugin a list of their executing classes for it to iterate over. How was this accomplished?

    @MaTaMoR_
    Your code seems to be some sort dictionary for mapping commands and subcommands. It also looks like you have routines for validating a command and checking permissions before passing the arguments to your executing class. Still trying to figure out exactly how your using it but I enjoyed reading this, its quite refined and a joy to read. What method are you using to load the commands into this?
     
  7. I have a class in there that is called Lib.java. Inside contains a method Lib#addCommand(Class<?> cls); That is what you will do to register the class for being a command holder basically. So when the class gets loaded it loops through all the methods inside the class that are annotated with Cmd and saves the method. (hopefully, this answers your question)

    Someone else you may want to talk to about commands as well is @Sxtanna because he made this: https://github.com/Project-Coalesce/Core/tree/master/src/main/java/com/coalesce/command

    It's rather interesting to use, and it's really simple.
     
  8. look at the method 'register()' it registers the command directly.
     
  9. @NJDaeger Just reading through it now.


    @MaTaMoR_So your getting the command from bukkitcommand which the user typed and then checking if they have permission to execute it and then it looks like you execute the command yourself. At what point do you invoke the class which actually performs the functions required by the command? I mean, can you show the calling method and an example of an extending class?
     
    #10 Stuperfied, Apr 14, 2017
    Last edited: Apr 15, 2017
  10. Code (Java):

    public class HelloCommand extends ICommand {
       
        public HelloCommand(Plugin plugin) {
            super(plugin, "hello");
        }

        @Override
        public void onCommand(CommandArgs commandArgs) {
            commandArgs.sendMessage("Hello");
        }
    }

    @Override
    public void onEnable() {
     HelloCommand helloCommand = new HelloCommand(this);
     helloCommand.register(); //Register the command
    }
     
     
  11. My brain is ticking over now. You've both given me some really good ideas. At the absolute minimum a user must in some way indicate which command goes with which method. We cannot expect the users commands and or subcommands to bear the same name as the executing class or method.

    @NJDaeger, Can you show an example of the annotation the user would have had in their class?