Solved Normal Head Drops

Discussion in 'Plugin Development' started by SkyLarkPvP, Aug 13, 2014.

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

    SkyLarkPvP

    Hey, so i'm trying to make a plugin that has a 20% chance to drop the players head on death, the problem is that it only drops a normal steve head.
    Here's my code:

    private Random rand = new Random();
    @EventHandler
    public void onKill(PlayerDeathEvent e) {
    Player killer = e.getEntity().getKiller();
    Player killed = e.getEntity();
    if(killer instanceof Player && killer !=killed && (rand.nextInt(100) < 20) ) {
    ItemStack skullitem = new ItemStack(Material.SKULL_ITEM, 1, ((short)3));
    SkullMeta skullmeta = (SkullMeta) skullitem.getItemMeta();
    skullmeta.setOwner(killed.getName());
    skullmeta.setDisplayName(killed.getName() + "'s Head");
    World world = killed.getWorld();
    world.dropItem(killed.getLocation(), skullitem)

    }}}

    and yes, i have registered the events.
     
  2. Offline

    Esophose

  3. Offline

    SkyLarkPvP

    Esophose sorry, but what do you mean by that?
     
  4. Offline

    Zandor300

    You need to add the SkullMeta to the ItemStack like this:
    Code:java
    1. skullitem.setItemMeta(skullmeta);

    Place that line under
    Code:java
    1. skullmeta.setDisplayName(killed.getName() + "'s Head");
     
  5. Offline

    Cloaking_Ocean

    private Random rand = new Random();
    @EventHandler
    public void onKill(PlayerDeathEvent e) {
    Player killer = e.getEntity().getKiller();
    Player killed = e.getEntity();
    if(killer instanceof Player && killer !=killed && (rand.nextInt(100) < 20) ) {
    ItemStack skullitem = new ItemStack(Material.SKULL_ITEM, 1, ((short)3));
    SkullMeta skullmeta = (SkullMeta) skullitem.getItemMeta();
    skullmeta.setOwner(killed.getName());
    skullmeta.setDisplayName(killed.getName() + "'s Head");
    World world = killed.getWorld();
    world.dropItem(killed.getLocation(), skullitem)

    }}}

    In your code you set the skullmeta but you never set the skullmeta of the skullitem. to do this simply add this:

    skullitem.setItemMeta(skullmeta);

    put this line after:

    skullmeta.setDisplayName(killed.getName() + "'s Head");
     
  6. Offline

    SkyLarkPvP

    -FIXED-
     
Thread Status:
Not open for further replies.

Share This Page