下面列出了org.bukkit.potion.PotionEffectType#POISON 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@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);
}
@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);
}
}
}
@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);
}
@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));
}