Development Assistance Creating a command system(Not a dup. This time I'm asking for someone to CREATE a cmd system maybe)

Discussion in 'Plugin Help/Development/Requests' started by Lightspeed, Apr 18, 2015.

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

    Lightspeed

    title continued:Not how to create one
    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    Code:
    protected <clazzname>(String cmd)
    {
    super("cmdhere");
    }
    
    
    //basic command void/boolean wutever that i can edit here
    Can someone create this so it will auto register the command and not use listeners like most command systems

    And if someone does create it have it use the plugin yaml still like essentials


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Apr 18, 2015
  2. Offline

    pie_flavor

    @Lightspeed I'm not sure what you're asking for. You do know how to use onCommand() and CommandExecutors right?
     
  3. Offline

    Lightspeed

    Yes just you have to register each command
     
  4. Offline

    pie_flavor

    @Lightspeed so why do you need a custom system? can't you just register them with plugin.yml?
     
  5. Offline

    Lightspeed

    commands:
    cmd:

    like that?

    Don't you have to getCommand("LOL").setExecutor?
     
  6. Offline

    pie_flavor

    @Lightspeed Yeah. Why can't you just use that? Why do you need a custom system?
     
  7. Offline

    Lightspeed

    I have over 50 commands I need to add Not 50 but a ton :p
     
  8. Offline

    pie_flavor

    @Lightspeed
    Code:
    List<MyCommandExecutor> executors = Arrays.asList(new MyCommandExecutor[]{new MyExecutor(), new MyExecutor2, new MyExecutor3 /*...*/});
    for (MyCommandExecutor exec : executors) {
        getCommand(exec.cmd()).setExecutor(exec);
    }
    Make an interface MyCommandExecutor or whatever you want to name it, that extends CommandExecutor and has an additional cmd() method that returns a String. Make all your command executor classes implement it instead of CommandExecutor, and then put the above code in onEnable, with all your classes.
     
  9. Offline

    Lightspeed

    @pie_flavor new MyExecutor(), new MyExecutor2, new MyExecutor3 /*...*/});

    is this for every command I create or can I somehow have it add this "MyExecutor" autimaticly
     
  10. Offline

    pie_flavor

    just invoke the constructor of all of your executors
    the more automatic it is, the larger it is and the most complicated it is.
     
  11. Online

    timtower Administrator Administrator Moderator

    @Lightspeed Why not make it yourself instead? Or have a class with a static list where you add the command class.
    Similar effect as @pie_flavor told but then it will register on the command class side.
     
  12. Offline

    Lightspeed

    @timtower because everytime I try to do it myself it fails :\ I need it like essentials but, without there custom command method I'd want a normal boolean

    Code:
    package com.earth2me.essentials.commands;
    
    import com.earth2me.essentials.CommandSource;
    import static com.earth2me.essentials.I18n.tl;
    import com.earth2me.essentials.User;
    import org.bukkit.Server;
    
    
    public class Commandburn extends EssentialsCommand 
    {
        public Commandburn()
        {
            super("burn");
        }
    
        @Override
        protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
        {
            if (args.length < 2)
            {
                throw new NotEnoughArgumentsException();
            }
    
            if (args[0].trim().length() < 2)
            {
                throw new NotEnoughArgumentsException();
            }
    
            User user = getPlayer(server, sender, args, 0);
            user.getBase().setFireTicks(Integer.parseInt(args[1]) * 20);
            sender.sendMessage(tl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1])));
        }
    }
    Whats the point of this? Adding tons of command by just creating a class extending a class to register teh command automaticly THUS adding more command in very little time. There are other reasons but this reply is getting too long
     
  13. Online

    timtower Administrator Administrator Moderator

    @Lightspeed Did you read the part with the list? Or have it register itself.
    Command(plugin plugin){
    commandstuff.setexecutor(this)
    }
     
  14. Offline

    Lightspeed

    @timtower Register itself wut is this Can you give me an example I don't know if I'm understanding this correctly
    I did read the list but, I don't understand this "register itself"
     
    Last edited: Apr 19, 2015
  15. Offline

    pie_flavor

    @Lightspeed PluginCommand has a method called setExecutor. Where you actually call it is completely up to you.
    Code:
    public MyCommandExecutor(MyMainClass plugin) {
        plugin.getCommand("mycommand").setExecutor(this);
    }
     
    timtower likes this.
  16. Offline

    Lightspeed

    But I still have to initialize teh class right for it to work?
     
  17. Online

    timtower Administrator Administrator Moderator

    @Lightspeed Yup, unless you use reflection or some other hacky stuff.
     
  18. Offline

    Lightspeed

    I have a reflection system from my old threads
    Code:
    ClassPath path = null;
            try
            {
                path = ClassPath.from(getClassLoader());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            for (ClassPath.ClassInfo info : path.getTopLevelClassesRecursive("net.core.commands")) {
                try
                {
                    Class<?> clazz = Class.forName(info.getName(), true, getClassLoader());
    // somthing here
                }
                catch (Throwable e)
                {
                    e.printStackTrace();
                }
            }
    would this work?
     
  19. Online

    timtower Administrator Administrator Moderator

  20. Offline

    Lightspeed

    @timtower Where do I find my old threads?
     
  21. Online

    timtower Administrator Administrator Moderator

    @Lightspeed I was talking about try the code. And click your name, there should be a button "threads started" or something like that
     
  22. Offline

    Lightspeed

  23. Online

    timtower Administrator Administrator Moderator

    @Lightspeed Nobody will make you a command system.
    We gave multiple alternatives already.
    For you: I still suggest the static list with classes in it.
     
  24. Offline

    pie_flavor

    @Lightspeed Nobody is going to make about five classes so that you can avoid putting a long line with every classname in your plugin. No offense, but deal with it. Essentials's command system exists because they try to make other plugins' commands override their own.
     
  25. Offline

    Lightspeed

    @pie_flavor What do these 5 classes do?
    ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    All I want is a very small command system; so I extend that class in the constructor, put ||super("cmdhere");||, then cntrl + space and Ohhh look a cmd method I can double click and add amazing things to.
    ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    Thats all I want in a command system I'd add the User and the other things like that later when I have a reason to add them
     
    Last edited: Apr 20, 2015
  26. Offline

    pie_flavor

    @Lightspeed Dude. Really. Where you would put super("cmd here"), put plugin.getCommand("cmdhere").setExecutor(this);
    If you really, really, really want it to be exactly how you did it, then you can go ahead and make an abstract class that does that in its constructor.
     
    timtower likes this.
  27. Offline

    Lightspeed

    @pie_flavor If it's so easy(how you explained it) I thoguth someone would create it in a maximum of 2 hours and also use it themself because it saves alot of work and creating big plugins would be many times easier.

    EDIT: wouldent make it that much easier but much cleaner(Unclean code annoys me)
     
    Last edited: Apr 21, 2015
  28. Offline

    pie_flavor

    @Lightspeed It's not something you create. I do use this in my plugins. It takes a maximum of 10 seconds for each class, and you don't download anything or add dependencies. Do your own work, for chrissakes.
     
  29. Offline

    Lightspeed

    I'm confused @pie_flavor are you saying you use normal methods or my method(or one like mine)?
     
  30. Offline

    pie_flavor

    Dude.
     
Thread Status:
Not open for further replies.

Share This Page