88 lines
2.8 KiB
Java
88 lines
2.8 KiB
Java
package ca.thetechrobo.smp;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.SkullMeta;
|
|
|
|
public class DeathListener implements Listener {
|
|
public ScoreboardWrapper scores;
|
|
private ArrayList<String> skulllore;
|
|
@EventHandler
|
|
public void onDeath(PlayerDeathEvent e) {
|
|
this.scores.dieHearts(e.getEntity(), 4);
|
|
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
|
|
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
|
meta.setOwningPlayer(e.getEntity());
|
|
meta.setLore(this.skulllore);
|
|
ItemMeta newmeta = this.scores.save(meta, 69, "IsDroppedSkull");
|
|
skull.setItemMeta(newmeta);
|
|
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), skull);
|
|
}
|
|
@EventHandler
|
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
|
this.scores.addPlayerToScoreboard(e.getPlayer());
|
|
}
|
|
@EventHandler
|
|
public void onPlayerUse(PlayerInteractEvent e) {
|
|
Player p = e.getPlayer();
|
|
ItemStack i = p.getInventory().getItemInMainHand();
|
|
if (!(i.hasItemMeta())) return;
|
|
Life d = new Life();
|
|
d.create();
|
|
|
|
Boolean rightclickair = (e.getAction() == Action.RIGHT_CLICK_AIR);
|
|
if (!rightclickair) {
|
|
return;
|
|
}
|
|
Boolean condition1a = (i.getItemMeta().getDisplayName().equals(d.dn));
|
|
Boolean condition1b = (i.getType() == d.m);
|
|
Boolean lifeblock = (condition1a && condition1b && rightclickair);
|
|
Boolean heartblock = (i.getType() == Material.PLAYER_HEAD && rightclickair);
|
|
if (lifeblock) {
|
|
this.scores.die(p, -1);
|
|
p.getInventory().removeItem(d.item);
|
|
return;
|
|
}
|
|
if (heartblock) {
|
|
this.scores.dieHearts(p, -4.0);
|
|
ItemStack newi = i.clone();
|
|
newi.setAmount(1);
|
|
p.getInventory().removeItem(newi);
|
|
return;
|
|
}
|
|
LifeExtractor f = new LifeExtractor();
|
|
f.create();
|
|
if ((i.getType() == f.m) && (i.getItemMeta().getDisplayName().equals(f.dn))) {
|
|
if (p.getInventory().firstEmpty() == (-1)) {
|
|
p.sendMessage("§4Not enough room in your inventory.");
|
|
p.playSound(p, Sound.ENTITY_ENDERMAN_TELEPORT, 76, 0);
|
|
return;
|
|
}
|
|
if (this.scores.die(p, 0) == 1) {
|
|
p.sendMessage("§4Performing this operation will cause you to get banned. Cancelled.");
|
|
p.playSound(p, Sound.ENTITY_ENDERMAN_TELEPORT, 69, 0);
|
|
return;
|
|
}
|
|
this.scores.die(p, 1);
|
|
d.add(p);
|
|
}
|
|
}
|
|
public void initialise(LifestealPlugin pl) {
|
|
this.scores = new ScoreboardWrapper();
|
|
this.scores.initialise(pl);
|
|
this.skulllore = new ArrayList<String>();
|
|
this.skulllore.add("Can be used as a Life.");
|
|
}
|
|
}
|