Java Code Examples for org.bukkit.potion.PotionEffectType#POISON

The following examples show how to use org.bukkit.potion.PotionEffectType#POISON . 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: Poisonous.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
public PotionEffect getPotionEffect(@Nullable Event event, @Nullable Entity entity, @NotNull Player player, @NotNull ItemStack tool) {
	int level = modManager.getModLevel(tool, this);
	int duration = (int) (this.duration * Math.pow(this.durationMultiplier, (level - 1)));
	int amplifier = this.effectAmplifier * (level - 1);
	if (entity == null) {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")");
	} else {
		ChatWriter.logModifier(player, event, this, tool,
				"Duration(" + duration + ")",
				"Amplifier(" + amplifier + ")",
				"Entity(" + entity.getType().toString() + ")");
	}

	return new PotionEffect(PotionEffectType.POISON, duration, amplifier, false, false);
}
 
Example 2
Source File: PotionDamageResolver.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public @Nullable PotionInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    // If potion is already resolved (i.e. as a splash potion), leave it alone
    if(damager instanceof PotionInfo ||
       damager instanceof ProjectileInfo && ((ProjectileInfo) damager).getProjectile() instanceof PotionInfo) {
        return null;
    }

    final PotionEffectType effect;
    switch(damageType) {
        case POISON: effect = PotionEffectType.POISON; break;
        case WITHER: effect = PotionEffectType.WITHER; break;
        case MAGIC: effect = PotionEffectType.HARM; break;
        default: return null;
    }

    return new GenericPotionInfo(effect);
}
 
Example 3
Source File: EffPoison.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(final Event e) {
	for (final LivingEntity le : entites.getArray(e)) {
		if (!cure) {
			Timespan dur;
			int d = (int) (duration != null && (dur = duration.getSingle(e)) != null ? 
					(dur.getTicks_i() >= Integer.MAX_VALUE ? Integer.MAX_VALUE : dur.getTicks_i()) : DEFAULT_DURATION);
			if (le.hasPotionEffect(PotionEffectType.POISON)) {
				for (final PotionEffect pe : le.getActivePotionEffects()) {
					if (pe.getType() != PotionEffectType.POISON)
						continue;
					d += pe.getDuration();
				}
			}
			le.addPotionEffect(new PotionEffect(PotionEffectType.POISON, d, 0), true);
		} else {
			le.removePotionEffect(PotionEffectType.POISON);
		}
	}
}
 
Example 4
Source File: PotionDamageResolver.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public @Nullable PotionInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  PotionEffectType effect;
  switch (damageType) {
    case POISON:
      effect = PotionEffectType.POISON;
      break;
    case WITHER:
      effect = PotionEffectType.WITHER;
      break;
    case MAGIC:
      effect = null;
      break;
    default:
      return null;
  }

  // If potion is already resolved (i.e. as a splash potion), leave it alone
  if (damager instanceof PotionInfo
      || damager instanceof ProjectileInfo
          && ((ProjectileInfo) damager).getProjectile() instanceof PotionInfo) {
    return null;
  }

  return new GenericPotionInfo(effect);
}
 
Example 5
Source File: Poisonous.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
	if (!dropPoisonedMeat) {
		return;
	}

	LivingEntity mob = event.getEntity();
	Player player = mob.getKiller();

	if (player == null) {
		return;
	}

	if (Lists.WORLDS.contains(player.getWorld().getName())) {
		return;
	}

	boolean isPoisoned = false;

	for (PotionEffect potionEffect : mob.getActivePotionEffects()) {
		if (potionEffect.getType() == PotionEffectType.POISON) {
			isPoisoned = true;
			break;
		}
	}

	if (!isPoisoned) {
		return;
	}

	int numberOfMeat = 0;
	int numberOfPotatoes = 0;

	Iterator<ItemStack> iterator = event.getDrops().iterator();

	while (iterator.hasNext()) {
		ItemStack drop = iterator.next();
		if (isMeat(drop)) {
			iterator.remove();
			numberOfMeat++;
		} else if (drop.getType() == Material.POTATO) {
			iterator.remove();
			numberOfPotatoes++;
		}
	}

	ChatWriter.logModifier(player, event, this, player.getInventory().getItemInMainHand(),
			"Entity(" + event.getEntity().getType().toString() + ")");

	if (numberOfMeat > 0) event.getDrops().add(new ItemStack(Material.ROTTEN_FLESH, numberOfMeat));
	if (numberOfPotatoes > 0) event.getDrops().add(new ItemStack(Material.POISONOUS_POTATO, numberOfPotatoes));
}