Problem whit args[1]

Discussion in 'Plugin Development' started by lolgrapig112, Feb 16, 2013.

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

    lolgrapig112

    Dear,

    I am trying to get my plugin working but there is somthing wrong whit my args.

    My on command code:
    My code thats is not working
    It does work when I do this:
    The problem is that my second arg is not working.

    I don't get a error message and yes i now how to check for arguments but this is just a test command.

    Thanks alot for helping.

    Dear regrads,
    lolgrapig112
     
  2. Offline

    ZeusAllMighty11

    You have to check if args length > 0
     
  3. Offline

    lolgrapig112

    Got this now but still not working it only works when I use one arg.

    Realy need to get this fixed. The problem is that none of my args[1-1000] is working only arg[0] is working

    So if i only use arg[0] it works fine and it just promps the message as soon as I yous 2 or more args it does nothing any more it even doesn't show a error message.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    xGamingDudex

    You should do:
    Code:
    If(args.lenght > 1){
    // Code
    }
    When you have 2 args you should check if there is 2 args, as for now you are only checking if there is 1 arg
     
  5. Offline

    lolgrapig112

    i will try this I will keep you post :p

    The code now but still not working!
    Console:

    The wirth thing it also doesn't gives a bug here is my full code: http://pastebin.com/6RDTupja

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    keensta


    You haven't told your class to look out for commands change
    public final class spirox extends JavaPlugin implements Listener {
    to
    public final class spirox extends JavaPlugin implements Listener, CommandExecutor {

    Also before you use a command you have to use getCommand("test").setExecutor(this); this should be placed with in the onEnable() method.
     
  7. Offline

    lolgrapig112

    Will try this soon not at home now I will keep you post! :)
     
  8. Offline

    Burnett1

    Can i see the whole code as a one please. Also why are you assigning the args to a string just use the args. With the Player p = (Player) sender; u only need it once and put it under the "public boolean onCommand(CommandSender sender, Command cmd,
    String commandLabel, String[] args) {"
     
  9. Offline

    macguy8

    What about if the sender is a Console? You don't need a player object for this command anyway, you can just use sender.sendMessage, and you will be able to run the command from the Console as well without getting the error you would on ALL commands if you put Player p = (Player) sender. You always want to check if they are a player first
    Code:java
    1. if (sender instanceof Player) {
    2. //It's ok to cast to player
    3. } else {
    4. //Don't cast to player, as it will throw an error
    5. }
     
  10. Offline

    Burnett1

    Ye forgot to mention that.
     
  11. Offline

    lolgrapig112

    I know but not all commands are an instance of a player
     
  12. Offline

    Burnett1

    lolgrapig112 Copy and paste the entire class code inside the code brackets.
     
Thread Status:
Not open for further replies.

Share This Page