Solved command is working but give me error PLZ HELP ME!!! <-----------------

Discussion in 'Plugin Development' started by TheUpdater, Apr 25, 2013.

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

    TheUpdater

    when i do /rtd
    it gives me this plz help

    Usage: /RTD join
    Usage: /RTD Leave
    An interbal error occurred while arttempting to perform this command



    Code:
        public boolean onCommand(CommandSender sender, Command command, String cl, String[] args) {
            Player p = (Player) sender;
            if(cl.equalsIgnoreCase("RTD")) {
                if(args.length == 0 || args[0].equalsIgnoreCase("RTD")){
                p.sendMessage("Usage: /RTD join");
                p.sendMessage("Usage: /RTD Leave");
            }else{
               
            }
                if(args.length == 1 || args[1].equalsIgnoreCase("join")){
                    Bukkit.broadcastMessage(ChatColor.BOLD+p.getPlayer().getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
                }else{
                    p.sendMessage("Usage: /RTD join");
                    p.sendMessage("Usage: /RTD Leave");
                }
               
            }
            return false;
          }
     
  2. Offline

    stuntguy3000

    Post the error?
     
  3. Offline

    TheUpdater

    in game it says

    Usage: /RTD join
    Usage: /RTD Leave
    An interbal error occurred while attempting to perform this command

    in concol it says this is where error is
    if(args.length == 1 || args[1].equalsIgnoreCase("join")){

    BUMP!!

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

    repsor

    Is it an ArrayIndexOutOfBoundsException? Btw. be aware that when you use arg[1] you actually refer to args[2]. Use args[0]
     
  5. Offline

    TheUpdater

    yes =D
     
  6. Offline

    repsor

    TheUpdater Be aware that when you use arg[1] you actually use the second argument. Use this:
    Code:
    if(args.length == 2 || args[1].equalsIgnoreCase("join")){
     
  7. Offline

    TheUpdater

    post it in code plz

    still gives me

    Usage: /RTD join
    Usage: /RTD Leave
    An interbal error occurred while attempting to perform this command

    when do /rtd

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  8. Offline

    repsor

    Can I see the full error? Oh and make sure you've also changed this
    Code:
    if(args.length == 0 || args[0].equalsIgnoreCase("RTD")){
    into this
    Code:
    if(args.length == 1 || args[0].equalsIgnoreCase("RTD")){
    And the reason you still get the usage description, is that you don't return true :p
     
  9. Offline

    stuntguy3000

    You learn a new thing every day ;) Didn't know that.
     
  10. Offline

    TheUpdater

    when do /rtd
    i get this
    Usage: /RTD join
    Usage: /RTD Leave
    An interbal error occurred while attempting to perform this command

    concol error is
    java.lang.ArrayIndexOutOfBoundsException: 0
    at rollTheDice.RollTheDice.oncommand<RollTheDice.java:60>

    this is on line 60
    if(args.length == 1 || args[1].equalsIgnoreCase("join")){

    still get error =(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  11. Offline

    repsor

    I see... well, try replacing
    Code:
    ||
    with
    Code:
    &&
    And why are you using this?
    Code:
      if(args.length == 0 || args[0].equalsIgnoreCase("RTD")){
                p.sendMessage("Usage: /RTD join");
                p.sendMessage("Usage: /RTD Leave");
            }else{
           
            }
    Just delete it and use the usage function in your plugin.yml
     
  12. Offline

    TheUpdater

    i tryed the thing you told me then it only gives me error

    plz fix it =(
    Code:
        public boolean onCommand(CommandSender sender, Command command, String cl, String[] args) {
            Player p = (Player) sender;
            if(cl.equalsIgnoreCase("RTD")) {
                if(args.length == 0 || args[0].equalsIgnoreCase("RTD")){
                p.sendMessage("Usage: /RTD join");
                p.sendMessage("Usage: /RTD Leave");
            }else{
               
            }
                if(args.length == 2 || args[2].equalsIgnoreCase("join")){
                    Bukkit.broadcastMessage(ChatColor.BOLD+p.getPlayer().getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
                }else{
                    p.sendMessage("Usage: /RTD join");
                    p.sendMessage("Usage: /RTD Leave");
                }
               
            }
            return true;
          }
    ???

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  13. Offline

    repsor

    ;)

    Sorry TheUpdater, but your code is just really sloppy.... No offense, but you'll really need to know java before asking this kind of things on the forum, because this way you're going to rely on copy and pasting code that others wrote for you....

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  14. Offline

    TheUpdater

    better???
    Code:
        public boolean onCommand(CommandSender sender, Command command, String cl, String[] args) {
            Player p = (Player) sender;
            if(cl.equalsIgnoreCase("RTD")) {
                if(args.length == 1 || args[1].equalsIgnoreCase("join")){
                    Bukkit.broadcastMessage(ChatColor.BOLD+p.getPlayer().getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");   
                }
            }   
            return true;
          }
     
  15. Offline

    repsor

    That depends on if you get an error or not :p
    But if I were you, I would use:


    Code:
      public boolean onCommand(CommandSender sender, Command command, String cl, String[] args) {
            Player p = (Player) sender;
            if(cl.equalsIgnoreCase("RTD")) {
                if(args.length == 1 && args[0].equalsIgnoreCase("join")){
                    Bukkit.broadcastMessage(ChatColor.BOLD+p.getPlayer().getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1"); 
                }
            } 
            return true;
          }
     
  16. Offline

    kreashenz

    TheUpdater They've told you almost exactly what to do.. This here, is simple Java knowledge. Maybe not arrays, but catching and fixing them SOMETIMES can be very easy.. In your case, it's very easy.. Here's the updated code, instead of just placing it in there, and letting us do the work, read it along side, and find out where you've done wrong. When I get some * easy * errors I do, I read them side by side to see what I've done wrong, and I seem to learn something new most of those times. Here :
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) {
    3. Player p = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("rtd")) {
    5. if(args.length == 0){
    6. p.sendMessage("Usage: /rtd join");
    7. p.sendMessage("Usage: /rtd Leave");
    8. } else {
    9. if(args[0].equalsIgnoreCase("join")){
    10. Bukkit.broadcastMessage(ChatColor.BOLD+p.getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
    11. }
    12. if(args[0].equalsIgnoreCase("leave")){
    13. Bukkit.broadcastMessage(p.getName() + "left because he is a poo head :p");
    14. }
    15. if(!(args[0].equalsIgnoreCase("leave") || args[0].equalsIgnoreCase("join")))p.sendMessage("You can only leave/join the RTD");
    16. }
    17. }
    18. return true;
    19. }
     
  17. Offline

    TheUpdater

    still get me An internal error occcurred while

    but when do /rtd join it works

    ty <3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  18. Offline

    repsor

    Maybe a little improvement? (nothing big)

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) {
        Player p = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("rtd")) {
        if(args.length => 1){
        if(args[0].equalsIgnoreCase("join")){
        Bukkit.broadcastMessage(ChatColor.BOLD+p.getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
        }else
        if(args[0].equalsIgnoreCase("leave")){
        Bukkit.broadcastMessage(p.getName() + "left because he is a poo head :p");
        }else{p.sendMessage("You can only leave/join the RTD");}
        }
        return true;
        }
     
  19. Offline

    TheUpdater

    what is cmd.getname
    never see that befor
     
  20. Offline

    kreashenz

    TheUpdater .-. ... That's to get the damn command!! Don't use the String, because you can't set it with aliases in plugin.yml.. Even drtshock explained this in one my previous posts..
     
  21. Offline

    TheUpdater

    ok ty can you help me whit 1 more thing sy if am noob
     
  22. Offline

    kreashenz

  23. Offline

    TheUpdater

    save an location i added 1 more command and i look and learn
    but now i need to save location
    when do /rtd setspawn
    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) {
            Player p = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("rtd")) {
                if(args.length == 0){
                    p.sendMessage("Usage: /rtd join");
                    p.sendMessage("Usage: /rtd Leave");
                } else {
                    if(args[0].equalsIgnoreCase("join")){
                        Bukkit.broadcastMessage(ChatColor.BOLD+p.getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
                        RTDJOIN.add(p);
                        p.teleport(RTDspawn.getLocation());
                    }
                    if(args[0].equalsIgnoreCase("leave")){
                        Bukkit.broadcastMessage(ChatColor.GREEN+p.getName() + " Left Roll The Dice v1");
                        RTDJOIN.remove(p);         
                    }
                    if(args[0].equalsIgnoreCase("setspawn")){
                        Bukkit.broadcastMessage(ChatColor.GREEN+"Spawn Is Set");
     
                    }
                    if(!(args[0].equalsIgnoreCase("leave") || args[0].equalsIgnoreCase("join") || args[0].equalsIgnoreCase("setspawn")))p.sendMessage("You can only leave/join the RTD");
                }                 
            }
            return true;
        }
     
  24. Offline

    stuntguy3000

    Ok, Thank you. Can you help me with one more thing? Sorry if I am a noob.
     
    kreashenz likes this.
  25. Offline

    kreashenz

    Where's the co-ords supposed to save to? Config.yml, I suppose?
     
  26. Offline

    TheUpdater

    yeah =)
     
  27. Offline

    kreashenz

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String cl, String[] args) {
    3. Player p = (Player) sender;
    4. if(cmd.getName().equalsIgnoreCase("rtd")) {
    5. if(args.length == 0){
    6. p.sendMessage("Usage: /rtd join");
    7. p.sendMessage("Usage: /rtd Leave");
    8. } else {
    9. if(args[0].equalsIgnoreCase("join")){
    10. Bukkit.broadcastMessage(ChatColor.BOLD+p.getName()+ChatColor.GREEN+" Has Joined Roll The Dice v1");
    11. RTDJOIN.put(p.getName(), p.getName());
    12. p.teleport(RTDspawn.getLocation());
    13. }
    14. if(args[0].equalsIgnoreCase("leave")){
    15. Bukkit.broadcastMessage(ChatColor.GREEN+p.getName() + " Left Roll The Dice v1");
    16. RTDJOIN.remove(p);
    17. }
    18. if(args[0].equalsIgnoreCase("setspawn")){
    19. Location loc = p.getLocation();
    20. double x = loc.getX();
    21. double y = loc.getY();
    22. double z = loc.getZ();
    23. double yaw = loc.getYaw();
    24. double pitch = loc.getPitch();
    25. World world = p.getWorld();
    26. getConfig().set("Spawn.x", Double.valueOf(x));
    27. getConfig().set("Spawn.y", Double.valueOf(y));
    28. getConfig().set("Spawn.z", Double.valueOf(z));
    29. getConfig().set("Spawn.yaw", Double.valueOf(yaw));
    30. getConfig().set("Spawn.pitch", Double.valueOf(pitch));
    31. getConfig().set("Spawn.world", world.getName());
    32. }
    33. if(!(args[0].equalsIgnoreCase("leave") || args[0].equalsIgnoreCase("join") || args[0].equalsIgnoreCase("setspawn")))p.sendMessage("You can only leave/join the RTD");
    34. }
    35. }
    36. return true;
    37. }

    TheUpdater
     
  28. Offline

    TheUpdater

    it dosent show in config.yml
    and how do i load somthing

    sy but am really noob at commands and locations

    this is onEnable
    Code:
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents((Listener) this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    ok well it saved to config but how do i load it at /rtd join

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  29. Offline

    kreashenz

  30. Offline

    TheUpdater

    well read that -.- am pretty new to locations and stuff / config i never use config xD

    this wont work

    double x = getConfig().getDouble("s");
    p.teleport(x);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page