Solved PlayerDeathEvent Drops

Discussion in 'Plugin Development' started by SuperboyDev, Aug 9, 2015.

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

    SuperboyDev

    Hi, I am making a plugin where when people are killed, a skull is dropped and can be crafted with gold ingots into a golden apple. This is my code:
    Code:
    public class Main extends JavaPlugin {
     
        @Override
        public void onEnable() {
            ItemStack goldenapple = new ItemStack(Material.GOLDEN_APPLE, 2);
            ItemMeta meta = goldenapple.getItemMeta();
            meta.setDisplayName(ChatColor.BLUE + "Golden Apple");
            meta.setLore(Arrays.asList(ChatColor.GOLD + "Contains the power",ChatColor.GOLD + "of the fallen heroes."));
            goldenapple.setItemMeta(meta);
         
         
         
            ShapedRecipe hrecipe = new ShapedRecipe(goldenapple).shape("***", "*%*", "***")
                    .setIngredient('*', Material.GOLD_INGOT)
                    .setIngredient('%', Material.SKULL_ITEM);
         
            getServer().addRecipe(hrecipe);
        }
     
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onPlayerDeath(PlayerDeathEvent event) {
            Player player = event.getEntity();
            event.getDrops().clear();
            event.getDrops().add(new ItemStack(Material.SKULL_ITEM));
            Bukkit.broadcastMessage(ChatColor.DARK_RED + player.getName() + ChatColor.RED +" has been killed! Use his skull to craft golden apples!");
        }
    }
    The crafting code works fine! My only problem is that it doesn't drop a golden apple when a player is killed. Could you give me some code to help me through. :p (I'm new at developing) Thanks a tonne!
     
  2. Offline

    Eos

    Code:
            event.getEntity().getWorld().dropItem()
    
     
  3. Code:
            event.getDrops().add(new ItemStack(Material.SKULL_ITEM));
    You are only dropping a skull item :p
     
  4. Offline

    SuperboyDev

    I tried it, but I asked for a location of the player. I don't know how to do that. :p Is it player.getLocation(); ?

    I don't understand what you mean :p
     
  5. Offline

    Eos

    pretty much
     
  6. Offline

    SuperboyDev

    It says "The method dropItem(Location, ItemStack) in the type World is not applicable for the arguments (Location, Material)"

    Oh never mind. I figured out my problem. Sorry!
    But the code still doesn't work. :(

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited: Aug 9, 2015
  7. Code:
    event.getDrops().add(new ItemStack(Material.SKULL_ITEM));
    You aren't dropping a golden apple.
     
  8. You can also set the skulls skin:
    Code:
    ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
    SkullMeta meta = (SkullMeta) skull.getItemMeta();
    meta.setOwner(player.getName());
    skull.setItemMeta(meta);
    //add skull to drops
     
  9. Offline

    SuperboyDev

    Sorry I changed it back :p
    Thanks, that helped, but I still can't drop a player head when he is killed. Could anyone write the code for me? I'm stuck
     
  10. Offline

    Eos

    Took this straight from my hub
    Code:
           
    ItemStack skull = new ItemStack(Material.SKULL_ITEM);
            skull.setDurability( (short) 3);
            SkullMeta sm = (SkullMeta) skull.getItemMeta();
            sm.setOwner(player.getName());
            skull.setItemMeta(sm);
            // Ends here
    
            player.getInventory().setItem(8, ex.applyHotbar(skull,
                    ChatColor.GREEN + "" + ChatColor.BOLD + "My Profile"));
     
  11. Offline

    SuperboyDev

    Thanks guys, I found my mistake. Thanks to you'll I did it! :D
     
Thread Status:
Not open for further replies.

Share This Page