New to making plugins need a little help

Discussion in 'Plugin Development' started by spying247, Feb 19, 2014.

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

    spying247

    i hope this is the proper place to post this but i am stumped i have been working on this custom plugin for my server that removes any enchantments before sending the player to our pvp arena but for some reaason when i type /pvp it gives an internal error here is my code

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. Player player = (Player) sender;
    3. if(cmd.getName().equalsIgnoreCase("pvp")){
    4. ItemStack[] armor = player.getInventory().getArmorContents();
    5. ItemStack[] inv = player.getInventory().getContents();
    6.  
    7.  
    8. for(int i = 0; i < 5; i++){
    9. if(armor[I].containsEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL))[/I]
    10. [I]{ //Line 77 where the error points to ^[/I]
    11. [I] player.sendMessage("Prepare to have your armor raided");[/I]
    12. [I] armor[I].removeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL);[/I][/I]
    13. [I] player.sendMessage("Armor Enchant Removed");[/I]
    14. [I] }[/I]
    15. [I] }[/I]
    16. [I] for(int n = 0; n < 36; n++){[/I]
    17. [I] if(inv[n].containsEnchantment(Enchantment.DAMAGE_ALL)){[/I]
    18. [I] player.sendMessage("Prepare to have your weapons raided");[/I]
    19. [I] inv[n].removeEnchantment(Enchantment.DAMAGE_ALL);[/I]
    20. [I] player.sendMessage("Inventory Enchant Removed");[/I]
    21. [I] }[/I]
    22. [I] }[/I]
    23. [I] }[/I]
    24. [I] return false;[/I]
    25. [I] }[/I]


    And here is my error

    org.bukkit.command.CommandException: Unhandled exception executing command 'pvp' in plugin BannedItems v0.0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
    at me.spying247.banneditems.Main.onCommand(Main.java:77) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    ... 13 more
     
  2. Offline

    SourceForums

    spying247
    Wrong thread. I've reported this thread so please wait until an administrator move it to the right section. :D
     
  3. Offline

    Necrodoom

    Moved to correct section.
     
  4. For the first loop, change it to 4 instead of 5, then take 1 from I like so:
    Code:
    armor[I - 1].removeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL);
    
    And for the second loop, you also need to take 1 like so:
    Code:
    inv[n - 1].removeEnchantment(Enchantment.DAMAGE_ALL);
    
     
Thread Status:
Not open for further replies.

Share This Page