1 out of 4 Commands are working, though very similar...

Discussion in 'Plugin Development' started by MrCyberMonkey, Apr 22, 2012.

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

    MrCyberMonkey

    First off here is the code:
    http://www.showmycode.com/?4124f41886eeeff2f1bec509e6c95c75

    Now, when I ran it on my test server with one of my admins. Only the /incap <player> part would work, not /uncap <player> or just /incap and /uncap, which should do the effect to me.

    Any help would be useful. Thanks in advance.

    Console Error:
    17:46:22 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'incap' in plugin Noveltys v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:473)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at me.mikey.com.main.onCommand(main.java:21)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 12 more
     
  2. Offline

    Njol

    1. You use arg[0] before checking whether args.length == 1
    2. You have to move the "uncap" part out of the "incap" part. The command can't be uncap and incap simultaneously.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[])
    2. {
    3. Player player = (Player)sender;
    4. String Player = player.getName();
    5. if(commandLabel.equalsIgnoreCase("incap"))
    6. {
    7. if(args.length == 0)
    8. {
    9. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 9999, 0));
    10. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 9999, 0));
    11. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 9999, 0));
    12. player.sendMessage((new StringBuilder()).append(ChatColor.RED).append("You were incapacitated").toString());
    13. }
    14. if(args.length == 1)
    15. {
    16. Player targetPlayer = player.getServer().getPlayer(args[0]);
    17. String tPlayer = targetPlayer.getName();
    18. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 9999, 0));
    19. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 9999, 0));
    20. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 9999, 0));
    21. player.sendMessage((new StringBuilder()).append(ChatColor.GRAY).append((new StringBuilder("You incapacitated ")).append(tPlayer).toString()).toString());
    22. targetPlayer.sendMessage((new StringBuilder()).append(ChatColor.RED).append((new StringBuilder("You were incapacitated by ")).append(Player).toString()).toString());
    23. }
    24.  
    25. }
    26. if(commandLabel.equalsIgnoreCase("uncap"))
    27. {
    28. if(args.length == 0)
    29. {
    30. player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 0, 0), true);
    31. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 0, 0), true);
    32. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 0, 0), true);
    33. player.sendMessage((new StringBuilder()).append(ChatColor.RED).append("You are no longer incapacitated!").toString());
    34. }
    35. if(args.length == 1)
    36. {
    37. Player targetPlayer = player.getServer().getPlayer(args[0]);
    38. String tPlayer = targetPlayer.getName();
    39. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 0, 0), true);
    40. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 0, 0), true);
    41. targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 0, 0), true);
    42. player.sendMessage((new StringBuilder()).append(ChatColor.GRAY).append((new StringBuilder("You un-incapacitated ")).append(tPlayer).toString()).toString());
    43. targetPlayer.sendMessage((new StringBuilder()).append(ChatColor.RED).append((new StringBuilder(String.valueOf(Player))).append(" un-incapacitated you!").toString()).toString());
    44. }
    45. }
    46. return false;
    47. }
     
Thread Status:
Not open for further replies.

Share This Page