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

The following examples show how to use org.bukkit.event.entity.EntityDamageByEntityEvent#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: Areas.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST,ignoreCancelled = true)
public void checkBreaks(EntityDamageByEntityEvent e)
{
	if(e.getDamager().getType() == EntityType.PLAYER && e.getEntity().getType() == EntityType.PLAYER)
	{
		Area a = this.getArea(new Loc(e.getDamager().getLocation(),false));
		if(a != null && !a.getAllowPVP())
		{
			e.setCancelled(true);
			return;
		}
		a = this.getArea(new Loc(e.getEntity().getLocation(),false));
		if(a != null && !a.getAllowPVP())
		{
			e.setCancelled(true);
			return;
		}
	}
}
 
Example 2
Source File: NoEntryListener.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void onCancelPVP(EntityDamageByEntityEvent e) {
    if(!e.isCancelled()) return;
    if(this.expansion.getNoEntryHandler().getNoEntryMode() != NoEntryMode.VULNERABLE) return;

    Entity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = (Player) entity;
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    e.setCancelled(false);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example 3
Source File: MenuConvIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void entityDamageByEntityEvent(EntityDamageByEntityEvent event) {
    if (event.getDamager() != player) {
        return;
    }

    event.setCancelled(true);

    if (debounce) {
        return;
    }

    if (event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) {

        if (controls.containsKey(CONTROL.LEFT_CLICK)) {

            switch (controls.get(CONTROL.LEFT_CLICK)) {
                case CANCEL:
                    if (!conv.isMovementBlock()) {
                        conv.endConversation();
                    }
                    debounce = true;
                    break;
                case SELECT:
                    conv.passPlayerAnswer(selectedOption + 1);
                    debounce = true;
                    break;
            case MOVE:
                break;
            default:
                break;
            }
        }
    }

}
 
Example 4
Source File: Kraken.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onSelfDamage(EntityDamageByEntityEvent event) {

    if (event.getDamager() instanceof Fireball && ((Fireball) event.getDamager()).getShooter() != null &&
            ((Fireball) event.getDamager()).getShooter() instanceof Squid) {
        event.setCancelled(true);
        removeFireball((Fireball) event.getDamager());
    }

}
 
Example 5
Source File: SentinelTrait.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Called when this sentinel attacks something, to correct damage handling.
 */
public void whenAttacksAreHappeningFromMe(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!npc.isSpawned()) {
        return;
    }
    if (SentinelPlugin.instance.alternateDamage) {
        if (canEnforce) {
            canEnforce = false;
            whenAttacksHappened(event);
            if (!event.isCancelled()) {
                ((LivingEntity) event.getEntity()).damage(event.getFinalDamage());
                if (event.getEntity() instanceof LivingEntity) {
                    weaponHelper.knockback((LivingEntity) event.getEntity());
                }
            }
            if (SentinelPlugin.debugMe) {
                debug("enforce damage value to " + event.getFinalDamage());
            }
        }
        else {
            if (SentinelPlugin.debugMe) {
                debug("refuse damage enforcement");
            }
        }
        event.setDamage(0);
        event.setCancelled(true);
        return;
    }
    event.setDamage(EntityDamageEvent.DamageModifier.BASE, getDamage(false));
}
 
Example 6
Source File: Conversation.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent event) {
    // prevent damage to (or from) player while in conversation
    if ((event.getEntity() instanceof Player && PlayerConverter.getID((Player) event.getEntity()).equals(playerID))
            || (event.getDamager() instanceof Player
            && PlayerConverter.getID((Player) event.getDamager()).equals(playerID))) {
        event.setCancelled(true);
    }
}
 
Example 7
Source File: ArmorStandListener.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Listener used to generate the ArmorStandDamageEvent.
 *
 * @param evt The initial EntityDamageByEntityEvent event
 *            used to generate the ArmorStandDamageEvent
 */
@EventHandler
public void onArmorStandDamage(EntityDamageByEntityEvent evt) {
    if (evt.getEntity().getType().equals(EntityType.ARMOR_STAND)
            && evt.getDamager().getType().equals(EntityType.PLAYER)) {
        ArmorStandDamageEvent event =
                new ArmorStandDamageEvent((Player) evt.getDamager(), evt.getEntity());
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            evt.setCancelled(true);
            return;
        }
    }
}
 
Example 8
Source File: LoveAtFirstSightListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.LOW)
public void onPlayerDamage(EntityDamageByEntityEvent e){
    if (e.getEntityType() != EntityType.PLAYER || !(e.getDamager() instanceof Player)){
        return;
    }

    PlayersManager pm = getPlayersManager();
    UhcPlayer uhcDamaged = pm.getUhcPlayer((Player) e.getEntity());
    UhcPlayer uhcDamager = pm.getUhcPlayer((Player) e.getDamager());

    if (getGameManager().getGameState() != GameState.PLAYING){
        return;
    }

    if (uhcDamaged.getTeam().isFull() || uhcDamager.getTeam().isFull()){
        return; // One of the teams is full so no team can be made
    }

    if (!uhcDamaged.getTeam().isSolo() && !uhcDamager.getTeam().isSolo()){
        return; // Neither of the players are solo so a team can't be created
    }

    if (getTeamManager().getPlayingUhcTeams().size() <= 2){
        return; // Only 2 teams left, don't team them up but let them first.
    }

    boolean result;
    if (uhcDamaged.getTeam().isSolo()){
        // add to damager team
        result = addPlayerToTeam(uhcDamaged, uhcDamager.getTeam());
    }else{
        // add damager to damaged
        result = addPlayerToTeam(uhcDamager, uhcDamaged.getTeam());
    }

    if (result){
        e.setCancelled(true);
    }
}
 
Example 9
Source File: FriendlyFire.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onEntityDamageEvent(EntityDamageByEntityEvent event) {
    if (!enabled) return;
    if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() == event.getEntity()){
        event.setCancelled(true);
    }
}
 
Example 10
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void cancelMemberDamage(Player p1, Player p2, EntityDamageByEntityEvent event) {
    IslandInfo is1 = plugin.getIslandInfo(p1);
    IslandInfo is2 = plugin.getIslandInfo(p2);
    if (is1 != null && is2 != null && is1.getName().equals(is2.getName())) {
        plugin.notifyPlayer(p1, tr("\u00a7eYou cannot hurt island-members."));
        event.setCancelled(true);
    }
}
 
Example 11
Source File: TNTSheepListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onDamageEntity(EntityDamageByEntityEvent event) {
  if (event.getCause().equals(DamageCause.CUSTOM) || event.getCause().equals(DamageCause.VOID)
      || event.getCause().equals(DamageCause.FALL)) {
    return;
  }

  if (event.getEntity() instanceof ITNTSheep) {
    event.setDamage(0.0);
    return;
  }

  if (!(event.getEntity() instanceof Player)) {
    return;
  }

  if (!(event.getDamager() instanceof TNTPrimed)) {
    return;
  }

  TNTPrimed damager = (TNTPrimed) event.getDamager();

  if (!(damager.getSource() instanceof Player)) {
    return;
  }

  Player damagerPlayer = (Player) damager.getSource();
  Player player = (Player) event.getEntity();
  Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player);

  if (game == null) {
    return;
  }

  if (game.getState() != GameState.RUNNING) {
    return;
  }

  if (game.isSpectator(damagerPlayer) || game.isSpectator(player)) {
    event.setCancelled(true);
    return;
  }

  Team damagerTeam = game.getPlayerTeam(damagerPlayer);
  Team team = game.getPlayerTeam(player);

  if (damagerTeam.equals(team) && !damagerTeam.getScoreboardTeam().allowFriendlyFire()) {
    event.setCancelled(true);
    return;
  }
}
 
Example 12
Source File: EntityDamageListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private void handleOfflinePlayers(EntityDamageByEntityEvent e){
    if (e.getEntityType() != EntityType.ZOMBIE || !(e.getDamager() instanceof Player)){
        return;
    }

    GameManager gm = GameManager.getGameManager();
    MainConfiguration cfg = gm.getConfiguration();
    PlayersManager pm = gm.getPlayersManager();
    
    // Offline players are disabled
    if (!cfg.getSpawnOfflinePlayers()){
        return;
    }

    Zombie zombie = (Zombie) e.getEntity();
    UhcPlayer damager = pm.getUhcPlayer((Player) e.getDamager());
    UhcPlayer owner = null;
    
    // Find zombie owner
    for (UhcPlayer uhcPlayer : pm.getPlayersList()){
        if (uhcPlayer.getOfflineZombie() != null && uhcPlayer.getOfflineZombie() == zombie){
            owner = uhcPlayer;
            break;
        }
    }
    
    // Not a offline player
    if (owner == null){
        return;
    }
    
    boolean pvp = gm.getPvp();
    boolean isTeamMember = owner.isInTeamWith(damager);
    boolean friendlyFire = gm.getConfiguration().getEnableFriendlyFire();
    
    // If PvP is false or is team member & friendly fire is off
    if (!pvp || (isTeamMember && !friendlyFire)){
        e.setCancelled(true);
        // Canceled due to friendly fire, so send message
        if (pvp){
            damager.sendMessage(Lang.PLAYERS_FF_OFF);
        }
    }
}
 
Example 13
Source File: Fireworks.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent event) {
    if (event.getDamager().hasMetadata(FIREWORK_METADATA)) event.setCancelled(true);
}
 
Example 14
Source File: PlayerDamageListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private void handleLightningStrike(EntityDamageByEntityEvent event){
	if(event.getDamager() instanceof LightningStrike && event.getEntity() instanceof Player){
		event.setCancelled(true);
	}
}
 
Example 15
Source File: EntityListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onAttack(EntityDamageByEntityEvent event) {
    if (listenerService.shouldCancelEvent(event.getDamager())) {
        event.setCancelled(true);
    }
}
 
Example 16
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
        return;
    }
    if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
        UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
        // Self damage
        if (attacker.equals(e.getEntity().getUniqueId())) {
            return;
        }
        Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
        boolean inNether = false;
        if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) {
            inNether = true;
        }
        // Monsters being hurt
        if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
            // Normal island check
            if (island != null && island.getMembers().contains(attacker)) {
                // Members always allowed
                return;
            }
            if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
                return;
            }
            // Not allowed
            e.setCancelled(true);
            return;
        }

        // Mobs being hurt
        if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman
                || e.getEntity() instanceof Villager) {
            if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker))) {
                return;
            }
            e.setCancelled(true);
            return;
        }

        // Establish whether PVP is allowed or not.
        boolean pvp = false;
        if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
            pvp = true;
        }

        // Players being hurt PvP
        if (e.getEntity() instanceof Player) {
            if (pvp) {
            } else {
                e.setCancelled(true);
            }
        }
    }
}
 
Example 17
Source File: FreezeListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamge(final EntityDamageByEntityEvent event) {
    if(freeze.isFrozen(event.getDamager())) {
        event.setCancelled(true);
    }
}
 
Example 18
Source File: FireworkDamageEvent.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@EventHandler
public void onFireworkDamage(EntityDamageByEntityEvent e) {
    if (fireworks.contains(e.getDamager())) {
        e.setCancelled(true);
    }
}
 
Example 19
Source File: SentinelTrait.java    From Sentinel with MIT License 4 votes vote down vote up
/**
 * Called when this sentinel attacks something with a projectile, to correct damage handling.
 */
public void whenAttacksAreHappeningFromMyArrow(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!npc.isSpawned()) {
        return;
    }
    if (SentinelPlugin.instance.alternateDamage) {
        if (canEnforce) {
            canEnforce = false;
            whenAttacksHappened(event);
            if (!event.isCancelled()) {
                ((LivingEntity) event.getEntity()).damage(getDamage(true));
                if (event.getEntity() instanceof LivingEntity) {
                    weaponHelper.knockback((LivingEntity) event.getEntity());
                }
            }
            if (SentinelPlugin.debugMe) {
                debug("enforce damage value to " + getDamage(true));
            }
        }
        else {
            if (SentinelPlugin.debugMe) {
                debug("refuse damage enforcement");
            }
        }
        event.setDamage(0);
        event.setCancelled(true);
        return;
    }
    double dam = getDamage(true);
    double modder = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
    double rel = modder == 0.0 ? 1.0 : dam / modder;
    event.setDamage(EntityDamageEvent.DamageModifier.BASE, dam);
    for (EntityDamageEvent.DamageModifier mod : EntityDamageEvent.DamageModifier.values()) {
        if (mod != EntityDamageEvent.DamageModifier.BASE && event.isApplicable(mod)) {
            event.setDamage(mod, event.getDamage(mod) * rel);
            if (SentinelPlugin.debugMe) {
                debug("Set damage for " + mod + " to " + event.getDamage(mod));
            }
        }
    }
}
 
Example 20
Source File: FreezeMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamge(final EntityDamageByEntityEvent event) {
  if (freeze.isFrozen(event.getDamager())) {
    event.setCancelled(true);
  }
}