Java Code Examples for org.bukkit.event.entity.EntityTargetEvent#getTarget()
The following examples show how to use
org.bukkit.event.entity.EntityTargetEvent#getTarget() .
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: DamageMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onTarget(EntityTargetEvent event) { if (!(event.getEntity() instanceof ExperienceOrb)) { ParticipantState victimState = null; if (event.getTarget() instanceof Player) { // Don't target allies MatchPlayer victim = getVictim(event.getTarget()); if (victim == null) return; victimState = victim.getParticipantState(); } else if (event.getTarget() != null) { // Don't target other mobs owned by allies victimState = tracker().getOwner(event.getTarget()); } if (victimState == null) return; DamageInfo damageInfo = tracker() .resolveDamage( EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity()); if (queryHostile(victimState, damageInfo).isDenied()) { event.setCancelled(true); } } }
Example 2
Source File: DamageMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onTarget(EntityTargetEvent event) { if(!(event.getEntity() instanceof ExperienceOrb)) { ParticipantState victimState = null; if(event.getTarget() instanceof Player) { // Don't target allies MatchPlayer victim = getVictim(event.getTarget()); if(victim == null) return; victimState = victim.getParticipantState(); } else if(event.getTarget() != null) { // Don't target other mobs owned by allies victimState = entityResolver.getOwner(event.getTarget()); } if(victimState == null) return; DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity()); if(queryHostile(event, victimState, damageInfo).isDenied()) { event.setCancelled(true); } } }
Example 3
Source File: CommonCustomMob.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void onTarget(EntityTargetEvent event) { if (event.isCancelled()) { return; } if ((event.getReason().equals(TargetReason.CLOSEST_PLAYER) || event.getReason().equals(TargetReason.OWNER_ATTACKED_TARGET)) && (event.getTarget() instanceof Player)) { double followRange = this.getFollowRange(); double distance = event.getEntity().getLocation().distance(event.getTarget().getLocation()); if ((distance-0.5) <= followRange) { this.targetName = ((Player)event.getTarget()).getName(); this.lastLocation = event.getEntity().getLocation(); } } else { this.targetName = null; this.lastLocation = null; } }
Example 4
Source File: EntityTarget.java From StaffPlus with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTarget(EntityTargetEvent event) { if(event.getTarget() instanceof Player) { Player player = (Player) event.getTarget(); if(userManager.get(player.getUniqueId()).getVanishType() != VanishType.TOTAL) { return; } event.setCancelled(true); } }
Example 5
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@EventHandler public void onGolemTarget(EntityTargetEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { if (event.getTarget() instanceof Player) { final Player player = (Player) event.getTarget(); if (game.isProtectionActive(player)) { event.setCancelled(true); return; } if (Main.isPlayerInGame(player)) { if (golem.getTeam() == game.getTeamOfPlayer(player)) { event.setCancelled(true); // Try to find enemy Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange()); if (playerTarget != null) { // Oh. We found enemy! ironGolem.setTarget(playerTarget); return; } } } } } } } } } }
Example 6
Source File: EventFilterMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityTrack(final EntityTargetEvent event) { // Handles mobs and XP orbs if (event.getTarget() != null) cancelUnlessInteracting(event, event.getTarget()); }
Example 7
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
@EventHandler public void onGolemTarget(EntityTargetEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { if (event.getTarget() instanceof Player) { final Player player = (Player) event.getTarget(); if (game.isProtectionActive(player)) { event.setCancelled(true); return; } if (Main.isPlayerInGame(player)) { if (golem.getTeam() == game.getTeamOfPlayer(player)) { event.setCancelled(true); // Try to find enemy Player playerTarget = MiscUtils.findTarget(game, player, golem.getFollowRange()); if (playerTarget != null) { // Oh. We found enemy! ironGolem.setTarget(playerTarget); return; } } } } } } } } } }
Example 8
Source File: EventFilterMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityTrack(final EntityTargetEvent event) { // Handles mobs and XP orbs if(event.getTarget() != null) cancelUnlessInteracting(event, event.getTarget()); }