Very simple parameter/argument "parser"

Discussion in 'Resources' started by sourcemaker, Jan 10, 2012.

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

    sourcemaker

    When I was trying to find a solution for a very simple parameter/argument parser, I found some sources in the www and combined it to s.th. you possibly find useful:

    Code:
    // predef vars
    String playername = "";
    
    // doing the hashmap
    HashMap hm = new HashMap();
    try {
    for ( String arg : args ) {
        String[] tokens = arg.split(":");
        hm.put(tokens[0], tokens[1]);
    } } catch (Exception e) { }
    
    // select from params
    if (hm.containsKey("player")) {
        playername = hm.get("player").toString();
    }

    Then you're be able to request every parameter with key and value.
    For example:
    /mycommand player:testplayer123 second:value key:value

    Please don't comment my coding style, just take it or make it better
    Want to say thanks anyway? Then just click that "Like" button :p
     
Thread Status:
Not open for further replies.

Share This Page