Java Code Examples for org.bukkit.event.entity.PotionSplashEvent#setIntensity()

The following examples show how to use org.bukkit.event.entity.PotionSplashEvent#setIntensity() . 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: 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 7
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);
							}
						}
					}
				}
			}
		}
	}
}