Optional arguments

Discussion in 'Plugin Development' started by Ad237, Oct 29, 2013.

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

    Ad237

    Does anyone know a good system for optional arguments. By this I mean something similar to this

    /additem [id] [amount] [name] [durability] [enchantment]

    Players could skip an argument if they want though. Like if they didn't want to write the durability then it would just default to max.

    So I could write

    /additem id:276 durability:54

    and it would give me a diamond sword with 54 durability. The others would just default.

    To achieve this I had a few ideas but they all ended up with messy code and bugs. Sorry if i'm asking to much here but thanks for your help anyway.
     
  2. Offline

    amazed2025

    This is really neat, too bad I know nearly nothing about code :( Well hopefully you get helped! I'm struggling too aha.
     
  3. Offline

    Ad237

    Don't worry I found a solution.
     
  4. Offline

    JPG2000

    Ad237 Yes, switch the args.length and add arguments:
    Code:java
    1. switch (args.length()) {
    2. case: 1:
    3. //code for 1 argument
    4. break;
    5. case: 2:
    6. //code for 2 arguments
    7. break;
    8. //etc
    9. }
     
Thread Status:
Not open for further replies.

Share This Page