GlowstoneMC / Glowstone-Legacy

An open-source server for the Bukkit Minecraft modding interface
Other
363 stars 122 forks source link

Potion code incomplete / inoperable #588

Closed turt2live closed 9 years ago

turt2live commented 9 years ago

Looks like the potion code in master is not complete.

Root cause: Plugin induced failure (Essentials) relating to potion effects. Valid issue for Glowstone to resolve.

General Information:

Error appears several thousand times in the log (L629) (see additional information) after a plugin-added potion effect is added to the player.

Applicable Log Segment:

2014/12/12 15:15:38 [INFO] BosKat123 issued command: /vanish
2014/12/12 15:15:38 [SEVERE] Error occurred while pulsing world world
java.lang.ClassCastException: org.bukkit.potion.PotionEffectTypeWrapper cannot be cast to net.glowstone.constants.GlowPotionEffect
    at net.glowstone.entity.GlowLivingEntity.pulse(GlowLivingEntity.java:137)
    at net.glowstone.entity.GlowHumanEntity.pulse(GlowHumanEntity.java:139)
    at net.glowstone.entity.GlowPlayer.pulse(GlowPlayer.java:383)
    at net.glowstone.GlowWorld.pulse(GlowWorld.java:384)

Additional Information:

Testing has not been done to verify this issue is valid. If you have any information, please post it below.


Change History

Tonodus commented 9 years ago

Imagine the following piece of code (in a plugin f.e.):

LivingEntity#addPotionEffect(new PotionEffect(PoitionEffectType.HUNGER, ...));

This will call (GlowLivingEntity.java):

Map<PotionEffectType, PotionEffect> potionEffects = ...;

...

boolean addPotionEffect(PotionEffect effect) {
    potionEffects.put(effect.getType(), effect);
}

and then throw the exception here (GlowLivingEntity.java):

void pulse() {
    List<PotionEffect> effects = new ArrayList<>(potionEffects.values());
    for (PotionEffect effect : effects) {
        //effect.getType() == PoitionEffectType.HUNGER
        //effect.getType() instanceof PotionEffectTypeWrapper

        //ClassCastExcpetion:
        GlowPotionEffect type = (GlowPotionEffect) effect.getType(); 
    }
}

To solve this problem, addPotionEffect should be changed so it only uses GlowPotionEffect, and no PotionEffectTypeWrapper. See:

boolean addPotionEffect(PotionEffect effect) {
    GlowPotionEffect type = (GlowPotionEffect) PotionEffectType.getById(effect.getType().getId());
    potionEffects.put(type, effect);
}

Warning: I only spend a few minutes with looking at this bug, so this might correct, but further investigation has to be done.