类org.bukkit.event.entity.PotionSplashEvent源码实例Demo

下面列出了怎么用org.bukkit.event.entity.PotionSplashEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: CardinalPGM   文件: FriendlyFire.java
@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);
            }
        }
    }
}
 
源代码2 项目: PGM   文件: EventFilterMatchModule.java
@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);
    }
  }
}
 
源代码3 项目: PGM   文件: DamageMatchModule.java
@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);
    }
  }
}
 
源代码4 项目: ProjectAres   文件: EventFilterMatchModule.java
@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);
        }
    }
}
 
源代码5 项目: ProjectAres   文件: DamageMatchModule.java
@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);
        }
    }
}
 
源代码6 项目: Guilds   文件: EntityListener.java
/**
 * 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));
            }
        }
    }

}
 
源代码7 项目: civcraft   文件: PlayerListener.java
@EventHandler(priority = EventPriority.LOW) 
public void onPotionSplash(PotionSplashEvent event) {
	for (PotionEffect effect : event.getPotion().getEffects()) {
		if (isPotionDisabled(effect)) {
			event.setCancelled(true);
			return;
		}
	}
}
 
源代码8 项目: HoloAPI   文件: IndicatorListener.java
@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());
            }
        }
    }
}
 
源代码9 项目: Shopkeepers   文件: LivingEntityShopListener.java
@EventHandler(ignoreCancelled = true)
void onPotionSplash(PotionSplashEvent event) {
	for (LivingEntity entity : event.getAffectedEntities()) {
		if (plugin.isShopkeeper(entity)) {
			event.setIntensity(entity, 0.0D);
		}
	}
}
 
源代码10 项目: Parties   文件: BukkitEventManager.java
public BukkitPartiesPotionsFriendlyFireBlockedEvent preparePartiesPotionsFriendlyFireBlockedEvent(PartyPlayer victim, PartyPlayer attacker, PotionSplashEvent originalEvent) {
	return new BukkitPartiesPotionsFriendlyFireBlockedEvent(victim, attacker, originalEvent);
}
 
源代码11 项目: Parties   文件: BukkitFightListener.java
@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);
							}
						}
					}
				}
			}
		}
	}
}
 
public BukkitPartiesPotionsFriendlyFireBlockedEvent(PartyPlayer victim, PartyPlayer attacker, PotionSplashEvent originalEvent) {
	super(false);
	this.victim = victim;
	this.attacker = attacker;
	this.originalEvent = originalEvent;
}
 
源代码13 项目: askyblock   文件: IslandGuard.java
/**
 * 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;
                }
            }
        }
    }
}
 
/**
 * Gets the original Bukkit event handled by Parties
 *
 * @return Returns the original {@link PotionSplashEvent}
 */
@NonNull
public PotionSplashEvent getOriginalEvent() {
	return originalEvent;
}
 
 类所在包
 同包方法