added player head drop

This commit is contained in:
Niklas 2020-06-26 17:28:40 +02:00
parent f50f633310
commit 79de05fb84
2 changed files with 43 additions and 1 deletions

View File

@ -7,6 +7,6 @@ public class HardcoreRevive extends JavaPlugin {
@Override
public void onEnable() {
this.getLogger().info("hardcore-revive plugin enabled");
this.getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
}
}

View File

@ -0,0 +1,42 @@
package org.kapelle.hardcore_revive;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.java.JavaPlugin;
public class PlayerDeathListener implements Listener {
private JavaPlugin plugin;
public PlayerDeathListener(JavaPlugin plugin){
this.plugin = plugin;
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event){
this.plugin.getLogger().info("Player died. Dropping head");
try{
Player player = event.getEntity();
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
assert headMeta != null;
headMeta.setDisplayName("Hopes and dreams of " + player.getDisplayName());
headMeta.setOwningPlayer(player);
head.setItemMeta(headMeta);
player.getWorld().dropItemNaturally(player.getLocation(),head);
}catch (Exception e){
this.plugin.getLogger().severe("Failed to drop player head: " + e.getMessage());
}
}
}