Java Code Examples for org.spongepowered.api.event.entity.DestructEntityEvent#Death

The following examples show how to use org.spongepowered.api.event.entity.DestructEntityEvent#Death . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDeath(DestructEntityEvent.Death event) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }

    final Player player = (Player) event.getTargetEntity();
    GDCauseStackManager.getInstance().pushCause(player);
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
    Tristate keepInventory = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_INVENTORY)) {
        keepInventory = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_INVENTORY, claim);
    }
    if (keepInventory != Tristate.UNDEFINED) {
        event.setKeepInventory(keepInventory.asBoolean());
    }
    /*Tristate keepLevel = Tristate.UNDEFINED;
    if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_LEVEL)) {
        keepLevel = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_LEVEL, claim);
    }
    if (keepLevel != Tristate.UNDEFINED) {
        event.setKeepLevel(keepLevel.asBoolean());
    }*/
}
 
Example 2
Source File: SpongeDeathListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    long time = System.currentTimeMillis();
    Living dead = event.getTargetEntity();

    if (dead instanceof Player) {
        // Process Death
        SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died);
    }

    try {
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            EntityDamageSource damageSource = optDamageSource.get();
            Entity killerEntity = damageSource.getSource();
            handleKill(time, dead, killerEntity);
        }
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build());
    }
}
 
Example 3
Source File: PlayerDeathListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerDeath(final DestructEntityEvent.Death event, final @Getter("getTargetEntity") Player player)
{
    CompletableFuture.runAsync(() -> super.getPlugin().getPowerManager().decreasePower(player.getUniqueId()))
            .thenRun(() -> player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOUR_POWER_HAS_BEEN_DECREASED_BY, TextColors.RESET, ImmutableMap.of(Placeholders.NUMBER, Text.of(TextColors.GOLD, this.powerConfig.getPowerDecrement()))), "\n",
            TextColors.GRAY, Messages.CURRENT_POWER + " ", super.getPlugin().getPowerManager().getPlayerPower(player.getUniqueId()) + "/" + super.getPlugin().getPowerManager().getPlayerMaxPower(player.getUniqueId()))));

    final Optional<Faction> optionalChunkFaction = super.getPlugin().getFactionLogic().getFactionByChunk(player.getWorld().getUniqueId(), player.getLocation().getChunkPosition());
    if (this.protectionConfig.getWarZoneWorldNames().contains(player.getWorld().getName()) || (optionalChunkFaction.isPresent() && optionalChunkFaction.get().isWarZone()))
    {
        super.getPlugin().getPlayerManager().setDeathInWarZone(player.getUniqueId(), true);
    }

    if (this.factionsConfig.shouldBlockHomeAfterDeathInOwnFaction())
    {
        final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
        if (optionalChunkFaction.isPresent() && optionalPlayerFaction.isPresent() && optionalChunkFaction.get().getName().equals(optionalPlayerFaction.get().getName()))
        {
            super.getPlugin().getAttackLogic().blockHome(player.getUniqueId());
        }
    }

    if(super.getPlugin().getPVPLogger().isActive() && super.getPlugin().getPVPLogger().isPlayerBlocked(player))
    {
        super.getPlugin().getPVPLogger().removePlayer(player);
    }
}
 
Example 4
Source File: DeathListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onDeath(DestructEntityEvent.Death e) {
    if (!(e.getTargetEntity() instanceof Player))
        return;

    Player p = (Player) e.getTargetEntity();
    if (isOnPipe(p.getUniqueId()) && Via.getConfig().isShowNewDeathMessages() && checkGamerule(p.getWorld())) {
        sendPacket(p, e.getMessage().toPlain());
    }
}
 
Example 5
Source File: UCListener.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onDeath(DestructEntityEvent.Death e, @Getter("getTargetEntity") Player p) {
    if (UChat.get().getUCJDA() != null && !p.hasPermission(UChat.get().getConfig().root().discord.vanish_perm)) {
        Task.builder().async().execute(() ->
                UChat.get().getUCJDA().sendRawToDiscord(UChat.get().getLang().get("discord.death").replace("{player}", p.getName())));
    }
}
 
Example 6
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST)
public void onPlayerDeath(DestructEntityEvent.Death event, @Root DamageSource damageSource) {
    GPTimings.PLAYER_DEATH_EVENT.startTimingIfSync();
    if (!(event.getTargetEntity() instanceof Player) || !GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetEntity().getWorld().getProperties())) {
        GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync();
        return;
    }

    // FEATURE: prevent death message spam by implementing a "cooldown period" for death messages
    Player player = (Player) event.getTargetEntity();
    GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), event.getTargetEntity().getUniqueId());
    long now = Calendar.getInstance().getTimeInMillis();
    final String showDeathMessages = player.getWorld().getGameRule("showDeathMessages").orElse(null);
    if (showDeathMessages != null && showDeathMessages.equalsIgnoreCase("true") && GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled && (now - playerData.lastDeathTimeStamp) < GriefPreventionPlugin.getGlobalConfig().getConfig().spam.deathMessageCooldown * 1000) {
        event.setMessage(Text.EMPTY);
    }

    playerData.lastDeathTimeStamp = now;

    // these are related to locking dropped items on death to prevent theft
    World world = event.getTargetEntity().getWorld();
    if (world != null) {
        GriefPreventionConfig<?> activeConfig = GriefPreventionPlugin.getActiveConfig(world.getProperties());
        GPClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
        if ((claim.pvpRulesApply() && activeConfig.getConfig().pvp.protectItemsOnDeathPvp) ||
                (!claim.isPvpEnabled() && activeConfig.getConfig().general.protectItemsOnDeathNonPvp)) {
            playerData.dropsAreUnlocked = false;
            playerData.receivedDropUnlockAdvertisement = false;
        }
    }
    GPTimings.PLAYER_DEATH_EVENT.stopTimingIfSync();
}
 
Example 7
Source File: RPBlockListener7.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDie(DestructEntityEvent.Death e, @First Player p) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation(), this.getClass().getName());
    if (r != null && !r.keepInventory()) {
        e.setKeepInventory(true);
    }
}
 
Example 8
Source File: RPBlockListener8.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDie(DestructEntityEvent.Death e, @First Player p) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation(), this.getClass().getName());
    if (r != null && !r.keepInventory()) {
        e.setKeepInventory(true);
    }
}
 
Example 9
Source File: EntityListener.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Saves event records when an entity dies.
 *
 * @param event DestructEntityEvent.Death
 */
@Listener(order = Order.POST)
public void onDestructEntityDeath(DestructEntityEvent.Death event, @Getter("getTargetEntity") Entity entity) {
    if (!Prism.getInstance().getConfig().getEventCategory().isEntityDeath()) {
        return;
    }

    PrismRecord.create()
            .source(event.getCause())
            .event(PrismEvents.ENTITY_DEATH)
            .entity(event.getTargetEntity())
            .buildAndSave();
}