Search in sources :

Example 1 with PlayerDeathEvent

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;
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent)

Example 2 with PlayerDeathEvent

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);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) ItemStack(org.bukkit.inventory.ItemStack) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Aggregations

net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)2 Element (net.aufdemrand.denizencore.objects.Element)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 PlayerDeathEvent (org.bukkit.event.entity.PlayerDeathEvent)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)1 LivingEntity (org.bukkit.entity.LivingEntity)1 EventHandler (org.bukkit.event.EventHandler)1 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)1 EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1