Esempio n. 1
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPotionSplashEvent(PotionSplashEvent event) {
    LivingEntity shooter = event.getPotion().getShooter();
    if (!(shooter instanceof Player)) return;
    Player damager = (Player) shooter;

    // So, the idea here is because we can't really determine how much damage a potion actually
    // caused
    // somebody (like poison, weakness, or the API doesn't even seem to tell you the difference
    // between harm I and harm II),
    // we just award 6 damage points to the thrower as long as the potion is sufficiently bad.
    int damage = 6;

    boolean badpotion = false;
    for (PotionEffect effect : event.getPotion().getEffects()) {
      // apparently these aren't really enums, because == doesn't work
      if (effect.getType().equals(PotionEffectType.HARM)
          || effect.getType().equals(PotionEffectType.POISON)
          || effect.getType().equals(PotionEffectType.WEAKNESS)) {
        badpotion = true;
        break;
      }
    }

    if (!badpotion) // don't award damage for helpful or do-nothing potions, to prevent pearl
      // stealing
      return;

    for (Entity entity : event.getAffectedEntities()) {
      if (!(entity instanceof Player)) continue;

      recordDamage((Player) entity, damager, damage);
    }
  }
Esempio n. 2
0
 @EventHandler
 public void splash(PotionSplashEvent event) {
   Collection<PotionEffect> effects = event.getPotion().getEffects();
   for (PotionEffect effect : effects) {
     if (effect.getType() == PotionEffectType.INCREASE_DAMAGE) {
       if (effect.getAmplifier() > 0) {
         event.setCancelled(true);
       }
     }
     if (effect.getType() == PotionEffectType.INVISIBILITY) {
       event.setCancelled(true);
     }
   }
 }
Esempio n. 3
0
 @EventHandler
 public void potionSplash(PotionSplashEvent event) {
   if (!event.getPotion().getWorld().getName().equals(getName())) return;
   event.setCancelled(true);
   Iterator iterator = event.getAffectedEntities().iterator();
   while (iterator.hasNext()) {
     LivingEntity target = (LivingEntity) iterator.next();
     if (event.getEntity().getShooter().equals(target)) {
       Player p = (Player) target;
       p.sendMessage(ChatColor.RED + "You cannot heal yourself!");
     } else {
       target.addPotionEffect(event.getPotion().getEffects().iterator().next());
     }
   }
 }
 @EventHandler(priority = EventPriority.NORMAL)
 public void onSplashPotion(PotionSplashEvent event) {
   if (event.isCancelled()) return;
   Entity ent = event.getEntity();
   boolean srcpvp = Residence.getPermsByLoc(ent.getLocation()).has("pvp", true);
   Iterator<LivingEntity> it = event.getAffectedEntities().iterator();
   while (it.hasNext()) {
     LivingEntity target = it.next();
     if (target.getType() == EntityType.PLAYER) {
       Boolean tgtpvp = Residence.getPermsByLoc(target.getLocation()).has("pvp", true);
       if (!srcpvp || !tgtpvp) {
         event.setIntensity(target, 0);
       }
     }
   }
 }
Esempio n. 5
0
 @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 public void onPotionSplash(final PotionSplashEvent event) {
   ThrownPotion potion = event.getPotion();
   Collection<PotionEffect> effects =
       ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects();
   Bukkit.broadcastMessage(
       "A "
           + event.getEntity().getType().getName()
           + " splashed a potion with "
           + effects.size()
           + " effects attached:");
   for (PotionEffect effect : effects) {
     Bukkit.broadcastMessage(
         "Type: "
             + effect.getType().getName()
             + ", Level: "
             + (effect.getAmplifier() + 1)
             + ", Duration: "
             + effect.getDuration());
   }
 }
Esempio n. 6
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onPotionSplash(PotionSplashEvent event) {
    if (event.isCancelled() == false && !worlds.contains(event.getPotion().getWorld().getName())) {
      ThrownPotion potion = event.getPotion();

      for (Entity e : event.getAffectedEntities()) {
        if (e instanceof Player) {
          Player p = (Player) e;
          playerStatManager
              .getPlayerBlob(p.getName())
              .getStat("potions", "splashhit")
              .incrementStat(1);
          // added per potion details
          for (PotionEffect potionEffect : potion.getEffects()) {
            String effect = potionEffect.getType().toString().toLowerCase().replaceAll("_", "");
            playerStatManager
                .getPlayerBlob(p.getName())
                .getStat("potions", "splash" + effect)
                .incrementStat(1);
          }
        }
      }
    }
  }
 @EventHandler(ignoreCancelled = true)
 public void onPotionSplash(PotionSplashEvent event) {
   if (projectiles.containsKey(event.getPotion())) {
     event.setCancelled(true);
   }
 }