Java Code Examples for org.bukkit.event.entity.EntityTargetEvent#setCancelled()

The following examples show how to use org.bukkit.event.entity.EntityTargetEvent#setCancelled() . 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 vote down vote up
@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 vote down vote up
@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: EntityTarget.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
@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 4
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityTarget(EntityTargetEvent event) {
    if (listenerService.shouldCancelEvent(event.getTarget())) {
        event.setTarget(null);
        event.setCancelled(true);
    }
}
 
Example 5
Source File: GolemListener.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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: GolemListener.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 7
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onEntityTarget(EntityTargetEvent event) {
	if (plugin.isShopkeeper(event.getEntity()) || plugin.isShopkeeper(event.getTarget())) {
		event.setCancelled(true);
	}
}