added player head drop
This commit is contained in:
parent
f50f633310
commit
79de05fb84
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user