org.bukkit.entity.ThrownPotion Java Examples

The following examples show how to use org.bukkit.entity.ThrownPotion. 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: 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 #2
Source File: PotionLauncher.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
    int slot = player.getInventory().getHeldItemSlot();

    ItemStack potion = player.getInventory().getItem(slot + 1);
    Location loc = player.getLocation();
    if (potion != null && potion.getType().toString().contains("POTION")) {
        ThrownPotion tp = player.launchProjectile(ThrownPotion.class);
        EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f);

        try {
            tp.setItem(potion);
        } catch (IllegalArgumentException ex) {
            ItemStack pt = potion.clone();
            if (potion.getType().equals(Material.POTION) || potion.getType().equals(Material.LINGERING_POTION))
                pt.setType(Material.SPLASH_POTION);
            tp.setItem(pt);
        }

        tp.setBounce(false);
        tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier));
        if (!player.getGameMode().equals(GameMode.CREATIVE)) {
            potion.setAmount(potion.getAmount() - 1);
            player.getInventory().setItem(slot + 1, potion);
            player.updateInventory();
        }
        return true;
    } else {
        player.sendMessage(ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!");
        player.getWorld().playEffect(loc, Effect.CLICK1, 5);
    }
    return false;
}
 
Example #3
Source File: CraftEventFactory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * PotionSplashEvent
 */
public static PotionSplashEvent callPotionSplashEvent(net.minecraft.entity.projectile.EntityPotion potion, Map<LivingEntity, Double> affectedEntities) {
    ThrownPotion thrownPotion = (ThrownPotion) potion.getBukkitEntity();

    PotionSplashEvent event = new PotionSplashEvent(thrownPotion, affectedEntities);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
 
Example #4
Source File: EntityTracker.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
  if (entity instanceof ThrownPotion) {
    return new ThrownPotionInfo((ThrownPotion) entity, owner);
  } else if (entity instanceof FallingBlock) {
    return new FallingBlockInfo((FallingBlock) entity, owner);
  } else if (entity instanceof LivingEntity) {
    return new MobInfo((LivingEntity) entity, owner);
  } else {
    return new EntityInfo(entity, owner);
  }
}
 
Example #5
Source File: PotionEffectUtils.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
public static short guessData(final ThrownPotion p) {
	if (p.getEffects().size() == 1) {
		final PotionEffect e = p.getEffects().iterator().next();
		PotionType type = PotionType.getByEffect(e.getType());
		assert type != null;
		final Potion d = new Potion(type).splash();
		return d.toDamageValue();
	}
	return 0;
}
 
Example #6
Source File: ThrownPotionData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void set(final ThrownPotion entity) {
	if (types != null) {
		final ItemType t = CollectionUtils.getRandom(types);
		assert t != null;
		ItemStack i = t.getRandom();
		if (i == null)
			return; // Missing item, can't make thrown potion of it
		entity.setItem(i);
	}
}
 
Example #7
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 #8
Source File: EntityTracker.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public PhysicalInfo createEntity(Entity entity, @Nullable ParticipantState owner) {
    if(entity instanceof ThrownPotion) {
        return new ThrownPotionInfo((ThrownPotion) entity, owner);
    } else if(entity instanceof FallingBlock) {
        return new FallingBlockInfo((FallingBlock) entity, owner);
    } else if(entity instanceof LivingEntity) {
        return new MobInfo((LivingEntity) entity, owner);
    } else {
        return new EntityInfo(entity, owner);
    }
}
 
Example #9
Source File: PotionClassifier.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double getScore(ThrownPotion potion) {
  double score = 0;

  for (PotionEffect effect :
      Iterables.concat(
          potion.getEffects(),
          ((PotionMeta) potion.getItem().getItemMeta()).getCustomEffects())) {
    score += getScore(effect);
  }

  return score;
}
 
Example #10
Source File: ThrownPotionData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean match(final ThrownPotion entity) {
	if (types != null) {
		for (final ItemType t : types) {
			if (t.isOfType(entity.getItem()))
				return true;
		}
		return false;
	}
	return true;
}
 
Example #11
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 #12
Source File: ThrownPotionData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected boolean init(final @Nullable Class<? extends ThrownPotion> c, final @Nullable ThrownPotion e) {
	if (e != null) {
		final ItemStack i = e.getItem();
		if (i == null)
			return false;
		types = new ItemType[] {new ItemType(i)};
	}
	return true;
}
 
Example #13
Source File: ThrownPotionInfo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public ThrownPotionInfo(ThrownPotion entity, @Nullable ParticipantState owner) {
    super(entity, owner);
    this.effectType = PotionUtils.primaryEffectType(entity.getItem());
}
 
Example #14
Source File: NPCEntity.java    From NPCFactory with MIT License 4 votes vote down vote up
@Override
public boolean damageEntity(DamageSource source, float damage) {
    if(godmode || noDamageTicks > 0) {
        return false;
    }

    DamageCause cause = null;
    org.bukkit.entity.Entity bEntity = null;
    if(source instanceof EntityDamageSource) {
        Entity damager = source.getEntity();
        cause = DamageCause.ENTITY_ATTACK;
        if(source instanceof EntityDamageSourceIndirect) {
            damager = ((EntityDamageSourceIndirect) source).getProximateDamageSource();
            if(damager.getBukkitEntity() instanceof ThrownPotion) {
                cause = DamageCause.MAGIC;
            } else if(damager.getBukkitEntity() instanceof Projectile) {
                cause = DamageCause.PROJECTILE;
            }
        }

        bEntity = damager.getBukkitEntity();
    } else if(source == DamageSource.FIRE)
        cause = DamageCause.FIRE;
    else if(source == DamageSource.STARVE)
        cause = DamageCause.STARVATION;
    else if(source == DamageSource.WITHER)
        cause = DamageCause.WITHER;
    else if(source == DamageSource.STUCK)
        cause = DamageCause.SUFFOCATION;
    else if(source == DamageSource.DROWN)
        cause = DamageCause.DROWNING;
    else if(source == DamageSource.BURN)
        cause = DamageCause.FIRE_TICK;
    else if(source == CraftEventFactory.MELTING)
        cause = DamageCause.MELTING;
    else if(source == CraftEventFactory.POISON)
        cause = DamageCause.POISON;
    else if(source == DamageSource.MAGIC) {
        cause = DamageCause.MAGIC;
    } else if(source == DamageSource.OUT_OF_WORLD) {
        cause = DamageCause.VOID;
    }

    if(cause != null) {
        NPCDamageEvent event = new NPCDamageEvent(this, bEntity, cause, (double) damage);
        Bukkit.getPluginManager().callEvent(event);
        if(!event.isCancelled()) {
            return super.damageEntity(source, (float) event.getDamage());
        } else {
            return false;
        }
    }

    if(super.damageEntity(source, damage)) {
        if(bEntity != null) {
            Entity e = ((CraftEntity) bEntity).getHandle();
            double d0 = e.locX - this.locX;

            double d1;
            for(d1 = e.locZ - this.locZ; d0 * d0 + d1 * d1 < 0.0001D; d1 = (Math.random() - Math.random()) * 0.01D) {
                d0 = (Math.random() - Math.random()) * 0.01D;
            }

            a(e, damage, d0, d1);
        }

        return true;
    } else {
        return false;
    }
}
 
Example #15
Source File: CraftLivingEntity.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
 
Example #16
Source File: ThrownPotionData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<? extends ThrownPotion> getType() {
	return ThrownPotion.class;
}
 
Example #17
Source File: ThrownPotionInfo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public ThrownPotionInfo(ThrownPotion entity) {
    this(entity, null);
}
 
Example #18
Source File: LingeringPotionSplashEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public LingeringPotionSplashEvent(final ThrownPotion potion, final AreaEffectCloud entity) {
    super(potion);
    this.entity = entity;
}
 
Example #19
Source File: PotionSplashEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ThrownPotion getEntity() {
    return (ThrownPotion) entity;
}
 
Example #20
Source File: PotionSplashEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public PotionSplashEvent(final ThrownPotion potion, final Map<LivingEntity, Double> affectedEntities) {
    super(potion);

    this.affectedEntities = affectedEntities;
}
 
Example #21
Source File: ThrownPotionInfo.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public ThrownPotionInfo(ThrownPotion entity) {
  this(entity, null);
}
 
Example #22
Source File: ThrownPotionInfo.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public ThrownPotionInfo(ThrownPotion entity, @Nullable ParticipantState owner) {
  super(entity, owner);
  this.effectType = InventoryUtils.getPrimaryEffectType(entity.getItem());
}
 
Example #23
Source File: PotionClassifier.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean isHarmful(ThrownPotion potion) {
  return getScore(potion) <= HARMFUL;
}
 
Example #24
Source File: PotionSplashEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the potion which caused this event
 *
 * @return The thrown potion entity
 */
public ThrownPotion getPotion() {
    return (ThrownPotion) getEntity();
}