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


    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

    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();
    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( ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch( ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand( ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInChat.a( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a( [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( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t( [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    at [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 4
    at me.spying247.banneditems.Main.onCommand( ~[?:?]
    at org.bukkit.command.PluginCommand.execute( ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    ... 13 more
  2. Offline


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


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

Share This Page