Hmm? What am I doing wrong?

Discussion in 'Plugin Development' started by bremdecoolste, Sep 17, 2013.

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

    bremdecoolste

    When I'm doing /tp bremdecoolste blabla it says " Unhandled exception executing command 'tp' in plugin TqCommands v1.0"

    java file:
    Code:java
    1. package me.bremdecoolste.TqCommands;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class TqCommands extends JavaPlugin{
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static TqCommands plugin;
    17.  
    18.  
    19. @Override
    20. public void onEnable()
    21. {
    22. PluginDescriptionFile pdfFile = this.getDescription();
    23. getLogger().info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " TqCommands has been loaded! ");
    24. }
    25.  
    26.  
    27. @Override
    28. public void onDisable()
    29. {
    30. PluginDescriptionFile pdfFile = this.getDescription();
    31. getLogger().info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " TqCommands has been stopped! ");
    32. }
    33.  
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    36. {
    37. Player player = (Player) sender;
    38.  
    39.  
    40. //TP COMMAND
    41.  
    42. if(commandLabel.equalsIgnoreCase("tp"));
    43. {
    44. if(args.length == 0)
    45. {
    46. player.sendMessage(ChatColor.DARK_RED + "/tp <target>");
    47. }
    48. else if(args.length == 1);
    49. {
    50. Player targetPlayer = player.getServer().getPlayer(args[0]);
    51. Location targetPlayerLocation = targetPlayer.getLocation();
    52. player.teleport(targetPlayerLocation);
    53. player.sendMessage(ChatColor.GRAY + "Teleporting to " + targetPlayer.getName());
    54. }
    55. if(args.length == 2)
    56. {
    57. Player targetPlayer1 = player.getServer().getPlayer(args[1]);
    58. Player targetPlayer2 = player.getServer().getPlayer(args[2]);
    59. Location targetPlayer2Location = targetPlayer2.getLocation();
    60. targetPlayer1.teleport(targetPlayer2Location);
    61. player.sendMessage(ChatColor.GRAY + "Teleporting " + targetPlayer1.getName() + " to " + targetPlayer2.getName());
    62. targetPlayer1.sendMessage(ChatColor.GRAY + "You have been teleported to " + targetPlayer2.getName());
    63. }
    64.  
    65. }


    plugin.yml:
    Code:java
    1. name: TqCommands
    2. main: me.bremdecoolste.TqCommands.TqCommands
    3. version: 1.0
    4. description: >
    5. My FIRST plugin!
    6. commands:
    7. heal:
    8. description: Heals a player
    9. feed:
    10. description: Heals a player
    11. tp:
    12. description: Heals a player


    What am I doing wrong?
     
  2. Offline

    CeramicTitan

    Stacktrace please
     
  3. Offline

    bremdecoolste

  4. Offline

    CeramicTitan

    stacktrace = error, the whole error
     
  5. Offline

    bremdecoolste

    Show Spoiler
    Code:
    [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tp' in plugin TqCommands v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
    at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:954)
    at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:872)
    at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:829)
    at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
    at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
    at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
    at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
    at me.bremdecoolste.TqCommands.TqCommands.onCommand(TqCommands.java:125)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more

    CeramicTitan
     
  6. Offline

    CeramicTitan

    at me.bremdecoolste.TqCommands.TqCommands.onCommand(TqCommands.java:125) What is on line 125 in your tq command class?

    EDIT: Your problem is this:
    Player targetPlayer1 = player.getServer().getPlayer(args[1]);
    Player targetPlayer2 = player.getServer().getPlayer(args[2]);

    change to this:
    Player targetPlayer1 = player.getServer().getPlayer(args[0]);
    Player targetPlayer2 = player.getServer().getPlayer(args[1]);
     
  7. Offline

    bremdecoolste

    CeramicTitan

    Player targetPlayer2 = player.getServer().getPlayer(args[2]);
     
  8. Offline

    CeramicTitan

    and you should be adding null checks
     
  9. Offline

    bremdecoolste

    THANKS! It works now! And what do you mean with adding null checks?
     
  10. Offline

    CeramicTitan

    Instead, let me ask you a question, What do you do if args[0] or one of the target players are not online?
     
  11. Offline

    bremdecoolste

    Aah, itll send an error message (supposed to do that). So I can check it with if player == null
     
  12. Offline

    CeramicTitan

    check if the player is not null(!= null) after you declare your player variable
     
Thread Status:
Not open for further replies.

Share This Page