use of org.bukkit.event.entity.PlayerDeathEvent in project Denizen-For-Bukkit by DenizenScript.
the class EntityDeathScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
// finish this
String lower = CoreUtilities.toLowerCase(determination);
// Deprecated
if (lower.startsWith("drops ")) {
lower = lower.substring(6);
determination = determination.substring(6);
}
//Handle no_drops and no_drops_or_xp and just no_xp
if (lower.startsWith("no_drops")) {
drops.clear();
changed_drops = true;
if (lower.endsWith("_or_xp")) {
xp = 0;
}
} else if (lower.equals("no_xp")) {
xp = 0;
} else if (lower.equals("keep_inv")) {
keep_inv = true;
} else if (lower.equals("keep_level")) {
keep_level = true;
} else // Change xp value only
if (aH.matchesInteger(determination)) {
xp = aH.Argument.valueOf(lower).asElement().asInt();
} else // Change dropped items if dList detected
if (aH.Argument.valueOf(lower).matchesArgumentList(dItem.class)) {
drops.clear();
changed_drops = true;
dList drops_list = dList.valueOf(determination);
drops_list.filter(dItem.class);
for (String drop : drops_list) {
dItem item = dItem.valueOf(drop);
if (item != null) {
// TODO: Why not just store the dItem in an arraylist?
drops.add(item.identify());
}
}
} else // String containing new Death Message
if (event instanceof PlayerDeathEvent) {
message = new Element(determination);
} else {
return super.applyDetermination(container, determination);
}
return true;
}
use of org.bukkit.event.entity.PlayerDeathEvent in project Denizen-For-Bukkit by DenizenScript.
the class EntityDeathScriptEvent method onEntityDeath.
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
LivingEntity livingEntity = event.getEntity();
dEntity.rememberEntity(livingEntity);
entity = new dEntity(livingEntity);
dPlayer player = null;
if (entity.isPlayer()) {
player = entity.getDenizenPlayer();
}
damager = null;
EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
if (lastDamage != null) {
if (lastDamage instanceof EntityDamageByEntityEvent) {
damager = new dEntity(((EntityDamageByEntityEvent) lastDamage).getDamager()).getDenizenObject();
}
}
message = null;
inventory = null;
PlayerDeathEvent subEvent = null;
if (event instanceof PlayerDeathEvent) {
subEvent = (PlayerDeathEvent) event;
message = new Element(subEvent.getDeathMessage());
// Null check to prevent NPCs from causing an NPE
if (player != null) {
inventory = player.getInventory();
}
keep_inv = subEvent.getKeepInventory();
keep_level = subEvent.getKeepLevel();
}
cause = null;
if (event.getEntity().getLastDamageCause() != null) {
cause = new Element(event.getEntity().getLastDamageCause().getCause().toString());
}
drops = new dList();
for (ItemStack stack : event.getDrops()) {
if (stack == null) {
drops.add("i@air");
} else {
drops.add(new dItem(stack).identify());
}
}
changed_drops = false;
xp = event.getDroppedExp();
this.event = event;
fire();
event.setDroppedExp(xp);
if (changed_drops) {
event.getDrops().clear();
for (String drop : drops) {
dItem item = dItem.valueOf(drop);
if (item != null) {
event.getDrops().add(item.getItemStack());
}
}
}
if (event instanceof PlayerDeathEvent) {
((PlayerDeathEvent) event).setKeepInventory(keep_inv);
((PlayerDeathEvent) event).setKeepLevel(keep_level);
}
if (message != null && subEvent != null) {
subEvent.setDeathMessage(message.asString());
}
if (cancelled && subEvent != null) {
subEvent.setDeathMessage(null);
}
dEntity.forgetEntity(livingEntity);
}
Aggregations