Java Code Examples for org.spongepowered.api.event.entity.DestructEntityEvent#getTargetEntity()
The following examples show how to use
org.spongepowered.api.event.entity.DestructEntityEvent#getTargetEntity() .
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: WebHookService.java From Web-API with MIT License | 5 votes |
@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 2
Source File: PlayerDeathListener.java From EssentialCmds with MIT License | 5 votes |
@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 3
Source File: ItemFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@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 4
Source File: FlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@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 5
Source File: MobFlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@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 6
Source File: DeathmessageListener.java From UltimateCore with MIT License | 4 votes |
@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); } }