What do you think of commands like this?

Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Member Handsfree is offline
    MemberRank
    Aug 2007 Join Date
    73Posts

    What do you think of commands like this?

    Would you prefer coding commands like this?

    PHP Code:
        @Command
        
    @Syntax("@dispose")
        @
    Description("Fixes you if you are stuck.")
        @
    Alias({"fix""unbug"})
        @
    Tags({"tutorial"})
        public 
    void dispose() {
            
    NPCScriptManager.getInstance().dispose(Client);
            
    Client.announce(MaplePacketCreator.enableActions());
            
    Chr.message("Fixed.");
        }

        @
    Command(false)
        @
    Description("Not used.")
        public 
    void unused() {
        } 
    Spoiler:

    Old way
    PHP Code:
            // Cannot generate help messages.
            
    else if(splitted[0].equals("dispose") || splitted[0].equals("fix") || splitted[0].equals("unbug")) {
                
    NPCScriptManager.getInstance().dispose(c);
                
    c.announce(MaplePacketCreator.enableActions());
                
    c.getPlayer().message("Fixed.");
            } 


    The benefits:
    • Cleaner look.
    • Variables inherited from super class. Ex: Chr, Client, Wserv, Cserv, Args
    • An organized help menu can be generated using the information above the method.
    • Command alias' don't need another method for each one.
    • Commands can have tags that can be used to filter what commands can be used when. Example above uses the tag "tutorial". This means that this command can be used in the tutorial.
    • Commands don't need to be commented out to be disabled. Example above sets the value of Command to false. This disables the command making it so it won't execute when called.
    • Any commands without a syntax reverts to the default label. (Ex. @unused)
    • Any commands without a description does not get generated into the help.
    • Somewhat easy to transfer from existing methods.


    What do you think?
    Last edited by Handsfree; 03-05-12 at 03:01 AM.


  2. #2
    Account Upgraded | Title Enabled! Liv3 is offline
    MemberRank
    Dec 2011 Join Date
    CanadaLocation
    817Posts

    Re: What do you think of commands like this?

    Sure... but I don't mind making commands like normal.

  3. #3
    Omega sunnyboy is offline
    MemberRank
    Mar 2010 Join Date
    6,109Posts

    Re: What do you think of commands like this?

    Yeah.. I still prefer the old way.

  4. #4
    Account Upgraded | Title Enabled! Yaseen is offline
    MemberRank
    Nov 2011 Join Date
    /index.phpLocation
    430Posts

    Re: What do you think of commands like this?

    ...meh. It may be good for people who don't understand a thing of java, but once you learn how to code the commands, that way is kind of...different.

  5. #5
    Have Fun! SuPeR SoNiC is offline
    MemberRank
    Nov 2008 Join Date
    509Posts

    Re: What do you think of commands like this?

    Actually, I think it's pretty nice. I hate looking at my commands file - it's so messy and looks like a huge wall of code. A format like yours would make it look much cleaner, and code organizing is something which is very important for me. :)

  6. #6
    Account Upgraded | Title Enabled! daniel4evar is offline
    MemberRank
    Feb 2010 Join Date
    467Posts

    Re: What do you think of commands like this?

    I prefer the old way actually..

  7. #7
    return null; mertjuh is offline
    MemberRank
    Dec 2008 Join Date
    The NetherlandsLocation
    1,269Posts

    Re: What do you think of commands like this?

    It will be harder to maintain the commands when you have lots of them.

  8. #8
    Account Upgraded | Title Enabled! Liv3 is offline
    MemberRank
    Dec 2011 Join Date
    CanadaLocation
    817Posts

    Re: What do you think of commands like this?

    Quote Originally Posted by SuPeR SoNiC View Post
    Actually, I think it's pretty nice. I hate looking at my commands file - it's so messy and looks like a huge wall of code. A format like yours would make it look much cleaner, and code organizing is something which is very important for me. :)
    Using AuraSEA's way was pretty nice. A class(within another, which is called a sub-class) for each command.
    I still prefer the normal way.

  9. #9
    Have Fun! SuPeR SoNiC is offline
    MemberRank
    Nov 2008 Join Date
    509Posts
    Quote Originally Posted by mertjuh View Post
    It will be harder to maintain the commands when you have lots of them.
    That's true. There might be a way to make this more useful with some rework, though.

    Sent from my E15i using Tapatalk 2

  10. #10
    Account Upgraded | Title Enabled! aaronweiss is offline
    MemberRank
    Apr 2012 Join Date
    351Posts

    Re: What do you think of commands like this?

    I've been working on a way that I like quite a bit.
    Looks something like this:
    PHP Code:
    public class AdminCommands extends Commands {
        public static 
    boolean execute(MapleClient cString[] subchar heading) {
            
    MapleCharacter chr c.getPlayer();
            
    Channel cserv c.getChannelServer();
            
    MapleCharacter victim// For commands with targets.
            
    ResultSet rs// For commands with MySQL results.

            
    Command command Command.valueOf(sub[0]);
            switch (
    command) {
                default:
                    
    // chr.yellowMessage("Command: " + heading + sub[0] + ": does not exist.");
                    
    return false;
                case 
    setgmlevel:
                    
    victim c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
                    
    victim.saveToDB(true);
                    
    victim.setGM(Integer.parseInt(sub[2]));
                    
    chr.message("Done.");
                    
    victim.getClient().disconnect();
                    break;
            }
            return 
    true;
        }
        
        private static 
    enum Command {
            
    setgmlevel
        
    }

    The idea is you use enumerations and switch statements to produce clean, legible commands without having to deal with the massive if-else statement that is most command systems. It doesn't have anything for a help message, so that has to be manually created, but I like how it works for me so far.

  11. #11
    Account Upgraded | Title Enabled! F4keName is offline
    MemberRank
    Mar 2010 Join Date
    In Heaven BitchLocation
    271Posts

    Re: What do you think of commands like this?

    Quote Originally Posted by aaronweiss View Post
    I've been working on a way that I like quite a bit.
    Looks something like this:
    PHP Code:
    public class AdminCommands extends Commands {
        public static 
    boolean execute(MapleClient cString[] subchar heading) {
            
    MapleCharacter chr c.getPlayer();
            
    Channel cserv c.getChannelServer();
            
    MapleCharacter victim// For commands with targets.
            
    ResultSet rs// For commands with MySQL results.

            
    Command command Command.valueOf(sub[0]);
            switch (
    command) {
                default:
                    
    // chr.yellowMessage("Command: " + heading + sub[0] + ": does not exist.");
                    
    return false;
                case 
    setgmlevel:
                    
    victim c.getChannelServer().getPlayerStorage().getCharacterByName(sub[1]);
                    
    victim.saveToDB(true);
                    
    victim.setGM(Integer.parseInt(sub[2]));
                    
    chr.message("Done.");
                    
    victim.getClient().disconnect();
                    break;
            }
            return 
    true;
        }
        
        private static 
    enum Command {
            
    setgmlevel
        
    }

    The idea is you use enumerations and switch statements to produce clean, legible commands without having to deal with the massive if-else statement that is most command systems. It doesn't have anything for a help message, so that has to be manually created, but I like how it works for me so far.
    Lol, that's exactly what I wanted to do ever since Java 7, I'm still waiting for Moople 117

    First I just wanted to change everything to switch statements with strings, and then I thought about a key and value list, and then enums came into mind.

  12. #12
    while(true) spam(); kevintjuh93 is offline
    MemberRank
    Jun 2008 Join Date
    The NetherlandsLocation
    4,119Posts

    Re: What do you think of commands like this?

    Quote Originally Posted by F4keName View Post
    Lol, that's exactly what I wanted to do ever since Java 7, I'm still waiting for Moople 117

    First I just wanted to change everything to switch statements with strings, and then I thought about a key and value list, and then enums came into mind.
    Yus, Java 7 supports String switch cases.

  13. #13
    Member Handsfree is offline
    MemberRank
    Aug 2007 Join Date
    73Posts

    Re: What do you think of commands like this?

    I like this method mainly because of the automatic command info generation.

    It's nice how each command has is own method because netbeans shows you all the commands in a list and you can navigate easily through them. Also it works nicely with the editor because If you need you can collapse any method you don't want to see.

    It just makes it easier to find your commands.

    I do like the switch though. :)

  14. #14
    Account Upgraded | Title Enabled! SuperLol is offline
    MemberRank
    Jun 2010 Join Date
    801Posts

    Re: What do you think of commands like this?

    I create an instance of each command and add them into a map. Then when people use a command, it retrieves it from the map. This method is faster than using if statements every time. It uses slightly more memory (command object is small though). Handlers should actually be done this way too (how it is in odin)... it's more industry standard.

  15. #15
    Account Upgraded | Title Enabled! StripedCow is offline
    MemberRank
    Jun 2011 Join Date
    813Posts

    Re: What do you think of commands like this?

    Sorry, but the old way is better than OPs way.



Page 1 of 2 12 LastLast

Advertisement