org.spongepowered.api.event.entity.DamageEntityEvent Java Examples
The following examples show how to use
org.spongepowered.api.event.entity.DamageEntityEvent.
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: PvpListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onEntityDamagedByPlayer(DamageEntityEvent event, @All(ignoreEmpty=false) EntityDamageSource[] sources) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetEntity().getWorld().getName()).getNode("enabled").getBoolean()) { return; } Entity attacker = null; for (int i = 0; i < sources.length; i++) { if (sources[i].getSource().getType() == EntityTypes.PLAYER || (sources[i] instanceof IndirectEntityDamageSource && ((IndirectEntityDamageSource) sources[i]).getIndirectSource().getType() == EntityTypes.PLAYER)) { attacker = sources[i].getSource(); } } if (attacker != null && event.getTargetEntity().getType() == EntityTypes.PLAYER) { if (!DataHandler.getFlag("pvp", attacker.getLocation()) || !DataHandler.getFlag("pvp", event.getTargetEntity().getLocation())) { event.setCancelled(true); return; } } }
Example #2
Source File: PlayerDamageListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onPlayerDamaged(DamageEntityEvent event) { if (event.getTargetEntity() instanceof Player) { Player player = (Player) event.getTargetEntity(); if (Utils.isTeleportCooldownEnabled() && EssentialCmds.teleportingPlayers.contains(player.getUniqueId())) { EssentialCmds.teleportingPlayers.remove(player.getUniqueId()); player.sendMessage(Text.of(TextColors.RED, "Teleportation canceled due to damage.")); } if (EssentialCmds.godPlayers.contains(player.getUniqueId())) { event.setBaseDamage(0); event.setCancelled(true); } } }
Example #3
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onFrameAndBoatBrake(DamageEntityEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - DamageEntityEvent event"); Entity ent = e.getTargetEntity(); Location<World> l = e.getTargetEntity().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r == null) return; if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) { if (!r.canFire()) { e.setCancelled(true); return; } } if ((ent instanceof Boat || ent instanceof Minecart) && e.getCause().first(Player.class).isPresent()) { Player p = e.getCause().first(Player.class).get(); if (!r.canMinecart(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbreak"); e.setCancelled(true); } } }
Example #4
Source File: GodListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onDamage(DamageEntityEvent event) { if (!(event.getTargetEntity() instanceof Player)) { return; } Player p = (Player) event.getTargetEntity(); UltimateUser up = UltimateCore.get().getUserService().getUser(p); if (up.get(GodKeys.GOD).orElse(false)) { event.setCancelled(true); //Send error message to player trying to hit, if player Player t = event.getCause().first(Player.class).orElse(null); if (t != null && t.getUniqueId() != p.getUniqueId()) { Messages.send(t, "god.onhit"); } } }
Example #5
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDamage(DamageEntityEvent event, @First DamageSource damageSource) { GDTimings.ENTITY_DAMAGE_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GDTimings.ENTITY_DAMAGE_EVENT.stopTimingIfSync(); }
Example #6
Source File: EntityEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.POST) public void onEntityDamageMonitor(DamageEntityEvent event) { if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getTargetEntity().getWorld().getUniqueId())) { return; } GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.startTimingIfSync(); //FEATURE: prevent players who very recently participated in pvp combat from hiding inventory to protect it from looting //FEATURE: prevent players who are in pvp combat from logging out to avoid being defeated if (event.getTargetEntity().getType() != EntityTypes.PLAYER || NMSUtil.getInstance().isEntityMonster(event.getTargetEntity())) { GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync(); return; } Player defender = (Player) event.getTargetEntity(); //only interested in entities damaging entities (ignoring environmental damage) // the rest is only interested in entities damaging entities (ignoring environmental damage) if (!(event.getCause().root() instanceof EntityDamageSource)) { GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync(); return; } GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(defender.getWorld(), defender.getUniqueId()); GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, defender.getLocation()); EntityDamageSource entityDamageSource = (EntityDamageSource) event.getCause().root(); GDTimings.ENTITY_DAMAGE_MONITOR_EVENT.stopTimingIfSync(); }
Example #7
Source File: EntityEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onEntityDamage(DamageEntityEvent event, @First DamageSource damageSource) { GPTimings.ENTITY_DAMAGE_EVENT.startTimingIfSync(); if (protectEntity(event, event.getTargetEntity(), event.getCause(), damageSource)) { event.setCancelled(true); } GPTimings.ENTITY_DAMAGE_EVENT.stopTimingIfSync(); }
Example #8
Source File: BloodListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onDamage(DamageEntityEvent event) { Entity en = event.getTargetEntity(); EntityType type = en.getType(); BloodEffect effect = BloodEffects.get(type).orElse(null); if (effect == null || !effect.isEnabled()) { return; } Location<World> loc = en.getLocation().add(effect.getCenterOffset()); loc.getExtent().spawnParticles(effect.getEffect(), loc.getPosition()); }
Example #9
Source File: PreventListener.java From FlexibleLogin with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerDamage(DamageEntityEvent damageEntityEvent, @First Player player) { //player is damage source checkLoginStatus(damageEntityEvent, player); }
Example #10
Source File: PreventListener.java From FlexibleLogin with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onDamagePlayer(DamageEntityEvent damageEntityEvent, @Getter("getTargetEntity") Player player) { //player is damage target checkLoginStatus(damageEntityEvent, player); }