Solved command arguments

Discussion in 'Spigot Plugin Development' started by joeleoli, May 15, 2016.

  1. I'm attempting to make a ban system and while working on the ban command, I'm trying to figure out a way to make it so I can just type in "2d" as one of the arguments to represent a 2 day ban, or even "2w", "2m", etc.

    Any ideas?
     
  2. Code (Text):
    if(args[1].contains("m")){
            ban.setBan(ban.getBan() + ((20 * 60) * StringUtils.substringAfter(args[1], "m"));
    }
    Should set it to 20 ticks times 1 minute times the amount of minutes by parsing out the number before the m.
     
  3. What does that have to do with anything...?
    I'm trying to figure out how to take a specific argument and divide it into a coupe of pieces that will give me a time that I will create for a player to be banned. I have to store this.
     
  4. That's what I just did. I showed you how to divide the number and the letter
     
  5. Code (Text):
    if(args[1].contains("m")){
             ban.setBan(ban.getBan() + ((20 * 60) * StringUtils.substringAfter(args[1], "m"));
    }

    if(args[1].contains("h")){
             ban.setBan(ban.getBan() + ((20 * 60 * 60) * StringUtils.substringAfter(args[1], "h"));
    }

    It would add the amount of hours and minutes in args[1] to the ban count (whatever you're using).[/
     
  6. Look into substrings. You can divide the argument that way. Also, you can use
    Code (Text):
    if(yourString.endsWith("w") {
     // your code
    }
     
  7. I didn't even pay attention to the sub-string part, my bad.
    Thanks man. =)
     
    • Friendly Friendly x 1