Solved Event Error

Discussion in 'Plugin Development' started by Leon0983X, Aug 28, 2015.

Thread Status:
Not open for further replies.
  1. Hey, i wrote a little plugin but it doesn't work. Here's the Code:
    Code:
        @EventHandler
        public void throwSnowball(PlayerInteractEvent event){
            Player player = (Player)event.getPlayer();
            ItemStack item = event.getItem();
            Entity e = (Entity) event.getItem();
            if(item.getType().equals(org.bukkit.Material.SNOW_BALL)){
                int snowballID = e.getEntityId();
                player.sendMessage("ID: " + snowballID);
            }
        }
    And here is the Error

    I don't know where the Error is. Can somebody help?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Leon0983X
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventor
    y.CraftItemStack cannot be cast to org.bukkit.entity.Entity
    Why are you casting before you check the type?
     
  3. Offline

    maxecito

    @Leon0983X
    Check if the item is instanceof Entity...
    Although Im pretty sure it wont trigger unless dropped/thrown, so you could delay it
     
  4. Oh, sorry just came home. I already fixed it, just forgot to set prefix.
     
Thread Status:
Not open for further replies.

Share This Page