Solved Randomly dropping items on entity death

Discussion in 'Plugin Development' started by kember007, Mar 22, 2015.

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

    kember007

    Im trying to create a plugin which will or will not drop specific items on a mob's death.
    this is the code I have...
    Code:
    public void death(final EntityDeathEvent event)
        {
            Entity entity = event.getEntity();
            Location location = entity.getLocation();
           
            ItemStack legendaryDrop = new ItemStack(Material.DIAMOND);
            legendaryDrop.setAmount(1);
            ItemStack uniqueDrop = new ItemStack(Material.GOLD_INGOT);
            uniqueDrop.setAmount(1);
            ItemStack rareDrop = new ItemStack(Material.IRON_INGOT);
            rareDrop.setAmount(1);
            int rare = (int) Math.random();
            int rareTwo = (int) Math.random();
            int rareThree = (int) Math.random();
            if (rare < 9)
            {
                location.getWorld().dropItem(location, legendaryDrop);
            }
            if (rareTwo < 21)
            {
                location.getWorld().dropItem(location, uniqueDrop);
            }
            if (rareThree < 31)
            {
                location.getWorld().dropItem(location, rareDrop);
            }
            location.getWorld().dropItem(location, legendaryDrop);
        }
    
     
  2. Offline

    tomudding

    You registered the event? Did you use the "@EventHandler" annotation? What happens when an entity dies? Errors?

    More information is needed to help you!
     
  3. Offline

    kember007

    Ill add the @EventHandler as it wasn't there, I don't see any errors when I start or reload the server though.

    Ah, yes it was the @EventHandler! Thankyou very much!
     
    Last edited by a moderator: Mar 22, 2015
  4. Offline

    tomudding

    Can you please mark this thread as finished?
     
  5. Marked as Solved and Locked.
     
Thread Status:
Not open for further replies.

Share This Page