org.spongepowered.api.event.entity.DestructEntityEvent Java Examples

The following examples show how to use org.spongepowered.api.event.entity.DestructEntityEvent. 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: WebHookService.java    From Web-API with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE)
public void onEntityDespawn(DestructEntityEvent event) {
    Entity ent = event.getTargetEntity();
    if (ent instanceof Player) {
        notifyHooks(WebHookService.WebHookType.PLAYER_DEATH, event);
    } else {
        notifyHooks(WebHookService.WebHookType.ENTITY_DESPAWN, event);
    }
}
 
Example #7
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 #8
Source File: PlayerDeathListener.java    From EssentialCmds with MIT License 5 votes vote down vote up
@Listener
public void onPlayerDeath(DestructEntityEvent event)
{
	if (event.getTargetEntity() instanceof Player)
	{
		Player died = (Player) event.getTargetEntity();

		Utils.savePlayerInventory(died, died.getWorld().getUniqueId());
		Utils.setLastTeleportOrDeathLocation(died.getUniqueId(), died.getLocation());
	}
}
 
Example #9
Source File: ItemFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onDeath(DestructEntityEvent event) {
    if (event.getTargetEntity() instanceof Player) {
        Player p = (Player) event.getTargetEntity();
        if (p.getName().equals(this.player.getName())) {
            close(true);
        }
    }
}
 
Example #10
Source File: FlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onDeath(DestructEntityEvent event) {
    if (event.getTargetEntity() instanceof Player) {
        Player p = (Player) event.getTargetEntity();
        if (p.getName().equals(this.player.getName())) {
            close(true);
        }
    }
}
 
Example #11
Source File: MobFlagGui.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onDeath(DestructEntityEvent event) {
    if (event.getTargetEntity() instanceof Player) {
        Player p = (Player) event.getTargetEntity();
        if (p.getName().equals(this.player.getName())) {
            close(true);
        }
    }
}
 
Example #12
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 #13
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 #14
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();
}
 
Example #15
Source File: EntityEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onDestructEntity(DestructEntityEvent event) {
  //  Thread.dumpStack();
}
 
Example #16
Source File: DeathmessageListener.java    From UltimateCore with MIT License 4 votes vote down vote up
@Listener
public void onDeath(DestructEntityEvent event) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Player p = (Player) event.getTargetEntity();

    //Get the translation, because for some reason sponge hides it in a lot of children
    Text orgmessage = event.getOriginalMessage();
    while (!(orgmessage instanceof TranslatableText) && !orgmessage.getChildren().isEmpty()) {
        for (Text child : orgmessage.getChildren()) {
            if (child instanceof TranslatableText) {
                break;
            }
        }
        orgmessage = orgmessage.getChildren().get(0); //Safe because of while loop
    }

    if (orgmessage instanceof TranslatableText) {
        //Id
        TranslatableText org = (TranslatableText) orgmessage;
        String id_mc = org.getTranslation().getId();
        if (!id_mc.startsWith("death.")) {
            return;
        }
        String id_uc = id_mc.toLowerCase().replaceFirst("death\\.", "deathmessage.message.");

        //Item
        ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND);
        Text item = stack.get(Keys.DISPLAY_NAME).orElse(Text.of(stack.getTranslation().get()));

        //Final message //TODO hover
        Text message = Messages.getFormatted(id_uc, "%player%", VariableUtil.getNameSource(p), "%item%", item);

        //Custom args
        int i = 1;
        for (Object ob : org.getArguments()) {
            message = TextUtil.replace(message, "%arg" + i + "%", ob instanceof Text ? ((Text) ob) : Text.of(ob.toString()));
            i++;
        }

        event.setMessage(message);
    }
}