Solved Spawning Zombies

Discussion in 'Plugin Development' started by MrGiGimz, May 12, 2014.

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

    MrGiGimz

    So im trying to spawn some "Custom Zombies" and this is my code:

    Code:java
    1. if(cmd.getLabel().equalsIgnoreCase("cz")){
    2. if(args[0].equalsIgnoreCase("spawn")){
    3. if(args[1].equalsIgnoreCase("diamond")){
    4. if(p.isOp() && p.getWorld().getName().equals("world")){
    5. Zombie zombie = (Zombie) p.getWorld().spawnEntity(p.getEyeLocation(), EntityType.ZOMBIE);
    6. zombie.setBaby(true);
    7. zombie.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 99999, 20));
    8. zombie.setCanPickupItems(false);
    9. ItemStack helmet = new ItemStack(Material.DIAMOND_HELMET);
    10. helmet.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5);
    11. ItemStack chestplate = new ItemStack(Material.DIAMOND_CHESTPLATE);
    12. chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5);
    13. ItemStack leggings = new ItemStack(Material.DIAMOND_LEGGINGS);
    14. leggings.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5);
    15. ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS);
    16. boots.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5);
    17. ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
    18. sword.addEnchantment(Enchantment.DAMAGE_ALL, 5);
    19. zombie.getEquipment().setHelmet(helmet);
    20. zombie.getEquipment().setChestplate(chestplate);
    21. zombie.getEquipment().setLeggings(leggings);
    22. zombie.getEquipment().setBoots(boots);
    23. zombie.getEquipment().setItemInHand(sword);
    24. p.sendMessage(ChatColor.GOLD+"Diamond Zombie has Been Spawned!");
    25. }
    26. }
    27. }
    28. }



    when i type /cz spawn diamond it will spawn the zombie with no diamond armor and sword and this comes up in my console:

    Code:
    12.05 21:25:08 [Server] INFO ... 13 more
    12.05 21:25:08 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at me.MrGiGimz.CustomZombies.MainClass.onCommand(MainClass.java:41) ~[?:?]
    12.05 21:25:08 [Server] INFO at org.bukkit.inventory.ItemStack.addEnchantment(ItemStack.java:430) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO Caused by: java.lang.IllegalArgumentException: Enchantment level is either too low or too high (given 5, bounds are 1 to 4)
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:459) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:548) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:250) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.MinecraftServer.v(MinecraftServer.java:657) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.ServerConnection.c(SourceFile:134) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.NetworkManager.a(NetworkManager.java:147) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.PacketPlayInChat.handle(PacketPlayInChat.java:47) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.PacketPlayInChat.a(PacketPlayInChat.java:28) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.PlayerConnection.a(PlayerConnection.java:814) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at net.minecraft.server.v1_7_R2.PlayerConnection.handleCommand(PlayerConnection.java:952) [minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at org.bukkit.craftbukkit.v1_7_R2.CraftServer.dispatchCommand(CraftServer.java:696) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3041jnks]
    12.05 21:25:08 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'cz' in plugin CustomZombies v1.0
    12.05 21:25:08 [Server] ERROR null

    if anyone could help me solve this i would love them forever <3
     
  2. Offline

    tryy3

    use addUnsafeEnchantment instead, you are trying to give a enchantment that can only be level 1-4
     
  3. Offline

    MrGiGimz

    that worked thanks tryy3
     
  4. Offline

    Mayoz

    He's right and it says it right in the error in perfect English.
    12.05 21:25:08 [Server] INFO Caused by: java.lang.IllegalArgumentException: Enchantment level is either too low or too high (given 5, bounds are 1 to 4)
     
  5. Offline

    rsod

    hmm, Actually I belive that you can get sharpness 5 legitimately. According to Wiki, you can get sharp 5 by combining two sharp 4 swords on anvil. That should be bukkit bug.
     
    I8ML likes this.
Thread Status:
Not open for further replies.

Share This Page