What's wrong here? [I iz nub]

Discussion in 'Plugin Development' started by Mcay, Oct 15, 2013.

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

    Mcay

    Hello, I'm just starting to learn Bukkit, and I'm stuck trying to make a simple dice plugin.
    Basically, there's 2 commands, /dice roll, and /dice forceroll <number>.
    /dice roll works fine, but /dice forceroll doesn't for some reason.

    Here's my full code : http://pastebin.com/Zp2gKkzi

    When I type the command with not enough arguments, it shows the message properly, but when I type the command with too many arguments, or try to use the command properly, it doesn't return anything. Sorry if it turns out to be some noob mistake, I'm still learning and stuff. :)

    Note : Bukkit API is 1.6.2, I use Eclipse.
     
  2. Offline

    DSH105

    Mcay You have checked if your argument length is greater than 2 inside your args.length == 1 check. This means that this part of your plugin will never be called (as 1 argument can never be greater than 2 :)).
     
  3. Offline

    Mcay

    Thanks, I edited it and it works fine now. :)

    Additionally, how do I test if an argument is a number?
    I'm adding a command to set the Max you can get from rolling the dice, and I want to return an error if the user inputs a word instead of a number.
     
  4. Offline

    WauloK

    You'll need to catch the exception after trying to use the argument as a number.
     
  5. Offline

    Chinwe

    Here is a simple method for checking if an integer is entered (by catching the exception like WauloK said)
     
  6. Offline

    Mcay

    Can you associate where and how I would do this in the plugin I'm trying to make? (link on OP)
    I'm not sure where I would put this, and where I would put the code if it is an integer, and if it isn't. Thanks in advance.
     
  7. Offline

    DSH105

    Mcay
    **if (isInteger(args[NUMBER]))** will return whether that argument is an integer. Make sure you have knowledge of the Java language before you try and make Bukkit plugins.
     
  8. Offline

    JPG2000

    Mcay That method, checks if a string is an integer. You surely don't want to make an integer, and assume that the player typed a number. Thats a setup for errors. Use it when ever you need to. I would use it, when a player is supossed to type a number. Check if its a number, if so, do code. If not, send them an erorr message or something!
     
Thread Status:
Not open for further replies.

Share This Page