org.bukkit.event.entity.PotionSplashEvent Java Examples

The following examples show how to use org.bukkit.event.entity.PotionSplashEvent. 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: FriendlyFire.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
    boolean proceed = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
        if (effect.getType().equals(PotionEffectType.POISON) || effect.getType().equals(PotionEffectType.BLINDNESS) ||
                effect.getType().equals(PotionEffectType.CONFUSION) || effect.getType().equals(PotionEffectType.HARM) ||
                effect.getType().equals(PotionEffectType.HUNGER) || effect.getType().equals(PotionEffectType.SLOW) ||
                effect.getType().equals(PotionEffectType.SLOW_DIGGING) || effect.getType().equals(PotionEffectType.WITHER) ||
                effect.getType().equals(PotionEffectType.WEAKNESS)) {
            proceed = true;
        }
    }
    if (proceed && event.getPotion().getShooter() instanceof Player && Teams.getTeamByPlayer((Player) event.getPotion().getShooter()) != null) {
        Optional<TeamModule> team = Teams.getTeamByPlayer((Player) event.getPotion().getShooter());
        for (LivingEntity affected : event.getAffectedEntities()) {
            if (affected instanceof Player && Teams.getTeamByPlayer((Player) affected) != null && Teams.getTeamByPlayer((Player) affected).equals(team) && !affected.equals(event.getPotion().getShooter())) {
                event.setIntensity(affected, 0);
            }
        }
    }
}
 
Example #2
Source File: EventFilterMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
  for (LivingEntity entity : event.getAffectedEntities()) {
    if (entity instanceof Player && match.getParticipant(entity) == null) {
      event.setIntensity(entity, 0);
    }
  }
}
 
Example #3
Source File: DamageMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
  ThrownPotion potion = event.getPotion();
  if (!PotionClassifier.isHarmful(potion)) return;

  for (LivingEntity entity : event.getAffectedEntities()) {
    ParticipantState victim = match.getParticipantState(entity);
    DamageInfo damageInfo =
        tracker().resolveDamage(EntityDamageEvent.DamageCause.MAGIC, entity, potion);

    if (victim != null && queryDamage(event, victim, damageInfo).isDenied()) {
      event.setIntensity(entity, 0);
    }
  }
}
 
Example #4
Source File: EventFilterMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
    for(LivingEntity entity : event.getAffectedEntities()) {
        if(!getMatch().canInteract(entity)) {
            event.setIntensity(entity, 0);
        }
    }
}
 
Example #5
Source File: DamageMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPotionSplash(final PotionSplashEvent event) {
    final ThrownPotion potion = event.getPotion();
    if(PotionClassification.classify(potion) != PotionClassification.HARMFUL) return;

    for(LivingEntity victim : event.getAffectedEntities()) {
        final ParticipantState victimState = getMatch().getParticipantState(victim);
        final DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.MAGIC, victim, potion);

        if(victimState != null && queryDamage(event, victimState, damageInfo).isDenied()) {
            event.setIntensity(victim, 0);
        }
    }
}
 
Example #6
Source File: EntityListener.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Handles splash potions+
 *
 * @param event
 */
@EventHandler
public void onSplash(PotionSplashEvent event) {
    boolean isHarming = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
        if (bad.contains(effect.getType())) {
            isHarming = true;
            break;
        }
    }

    if (!isHarming)
        return;

    ThrownPotion potion = event.getPotion();

    if (!(potion.getShooter() instanceof Player))
        return;

    Player shooter = (Player) potion.getShooter();

    for (LivingEntity entity : event.getAffectedEntities()) {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            if (guildHandler.isSameGuild(shooter, player) && potion.getShooter() != player) {
                event.setCancelled(!settingsManager.getProperty(GuildSettings.GUILD_DAMAGE));
                return;
            }
            if (guildHandler.isAlly(shooter, player)) {
                event.setCancelled(!settingsManager.getProperty(GuildSettings.ALLY_DAMAGE));
            }
        }
    }

}
 
Example #7
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW) 
public void onPotionSplash(PotionSplashEvent event) {
	for (PotionEffect effect : event.getPotion().getEffects()) {
		if (isPotionDisabled(effect)) {
			event.setCancelled(true);
			return;
		}
	}
}
 
Example #8
Source File: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onSplashPotion(PotionSplashEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("potion")) {
        for (Entity e : event.getAffectedEntities()) {
            if ((event.getEntity() instanceof Player && Settings.INDICATOR_SHOW_FOR_PLAYERS.getValue("potion")) || Settings.INDICATOR_SHOW_FOR_MOBS.getValue("potion")) {
                this.showPotionHologram(e, event.getPotion().getEffects());
            }
        }
    }
}
 
Example #9
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onPotionSplash(PotionSplashEvent event) {
	for (LivingEntity entity : event.getAffectedEntities()) {
		if (plugin.isShopkeeper(entity)) {
			event.setIntensity(entity, 0.0D);
		}
	}
}
 
Example #10
Source File: BukkitEventManager.java    From Parties with GNU Affero General Public License v3.0 4 votes vote down vote up
public BukkitPartiesPotionsFriendlyFireBlockedEvent preparePartiesPotionsFriendlyFireBlockedEvent(PartyPlayer victim, PartyPlayer attacker, PotionSplashEvent originalEvent) {
	return new BukkitPartiesPotionsFriendlyFireBlockedEvent(victim, attacker, originalEvent);
}
 
Example #11
Source File: BukkitFightListener.java    From Parties with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onPotionSplash(PotionSplashEvent event) {
	if (BukkitConfigParties.FRIENDLYFIRE_ENABLE
			&& event.getEntity() instanceof Player
			&& event.getPotion().getShooter() instanceof Player) {
		Player attacker = (Player) event.getPotion().getShooter();
		PartyPlayerImpl ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
		BukkitPartyImpl party = (BukkitPartyImpl) plugin.getPartyManager().getParty(ppAttacker.getPartyName());
		
		if (party != null && party.isFriendlyFireProtected() && !attacker.hasPermission(PartiesPermission.ADMIN_PROTECTION_BYPASS.toString())) {
			boolean cancel = false;
			for (PotionEffect pe : event.getEntity().getEffects()) {
				switch (pe.getType().getName().toLowerCase(Locale.ENGLISH)) {
				case "harm":
				case "blindness":
				case "confusion":
				case "poison":
				case "slow":
				case "slow_digging":
				case "weakness":
				case "unluck":
					cancel = true;
					break;
				default:
					// Do not cancel
					break;
				}
				if (cancel)
					break;
			}
			if (cancel) {
				// Friendly fire not allowed here
				for (LivingEntity e : event.getAffectedEntities()) {
					if (e instanceof Player) {
						Player victim = (Player) e;
						if (!attacker.equals(victim)) {
							PartyPlayerImpl ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
							if (ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
								// Calling API event
								BukkitPartiesPotionsFriendlyFireBlockedEvent partiesFriendlyFireEvent = ((BukkitEventManager) plugin.getEventManager()).preparePartiesPotionsFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
								plugin.getEventManager().callEvent(partiesFriendlyFireEvent);
								
								if (!partiesFriendlyFireEvent.isCancelled()) {
									// Friendly fire confirmed
									User userAttacker = plugin.getPlayer(attacker.getUniqueId());
									userAttacker.sendMessage(
											plugin.getMessageUtils().convertAllPlaceholders(BukkitMessages.ADDCMD_PROTECTION_PROTECTED, party, ppAttacker)
											, true);
									party.warnFriendlyFire(ppVictim, ppAttacker);
									
									event.setIntensity(e, 0);
									plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_FRIENDLYFIRE_DENIED
											.replace("{type}", "potion splash")
											.replace("{player}", attacker.getName())
											.replace("{victim}", victim.getName()), true);
								} else
									plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_API_FRIENDLYFIREEVENT_DENY
											.replace("{type}", "potion splash")
											.replace("{player}", attacker.getName())
											.replace("{victim}", victim.getName()), true);
							}
						}
					}
				}
			}
		}
	}
}
 
Example #12
Source File: BukkitPartiesPotionsFriendlyFireBlockedEvent.java    From Parties with GNU Affero General Public License v3.0 4 votes vote down vote up
public BukkitPartiesPotionsFriendlyFireBlockedEvent(PartyPlayer victim, PartyPlayer attacker, PotionSplashEvent originalEvent) {
	super(false);
	this.victim = victim;
	this.attacker = attacker;
	this.originalEvent = originalEvent;
}
 
Example #13
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
        plugin.getLogger().info("splash entity = " + e.getEntity());
        plugin.getLogger().info("splash entity type = " + e.getEntityType());
        plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities());
        //plugin.getLogger().info("splash hit entity = " + e.getHitEntity());
    }
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    // Try to get the shooter
    Projectile projectile = e.getEntity();
    if (DEBUG)
        plugin.getLogger().info("splash shooter = " + projectile.getShooter());
    if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
        Player attacker = (Player)projectile.getShooter();
        // Run through all the affected entities
        for (LivingEntity entity: e.getAffectedEntities()) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: affected splash entity = " + entity);
            // Self damage
            if (attacker.equals(entity)) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Self damage from splash potion!");
                continue;
            }
            Island island = plugin.getGrid().getIslandAt(entity.getLocation());
            boolean inNether = false;
            if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) {
                inNether = true;
            }
            // Monsters being hurt
            if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
                // Normal island check
                if (island != null && island.getMembers().contains(attacker.getUniqueId())) {
                    // Members always allowed
                    continue;
                }
                if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) {
                    continue;
                }
                // Not allowed
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                e.setCancelled(true);
                return;
            }

            // Mobs being hurt
            if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman
                    || entity instanceof Villager) {
                if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) {
                    continue;
                }
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking");
                Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected);
                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)))) {
                if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed");
                pvp = true;
            }

            // Players being hurt PvP
            if (entity instanceof Player) {
                if (pvp) {
                    if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed");
                } else {
                    if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed");
                    Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea);
                    e.setCancelled(true);
                    return;
                }
            }
        }
    }
}
 
Example #14
Source File: BukkitPartiesPotionsFriendlyFireBlockedEvent.java    From Parties with GNU Affero General Public License v3.0 2 votes vote down vote up
/**
 * Gets the original Bukkit event handled by Parties
 *
 * @return Returns the original {@link PotionSplashEvent}
 */
@NonNull
public PotionSplashEvent getOriginalEvent() {
	return originalEvent;
}