[SPIGOT-6026] PotionEffectType inconsistency on EntityPotionEffectEvent Created: 24/Jul/20 Updated: 05/Dec/23 Resolved: 05/Dec/23 |
|
| Status: | Resolved |
| Project: | Spigot |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Marco | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | bug, poison | ||
| Environment: |
OS: PopOS! 20.04 |
||
| Attachments: |
|
| Version: | git-Spigot-0509002-7c03d25 (MC: 1.16.1) (Implementing API version 1.16.1-R0.1-SNAPSHOT) |
| Guidelines Read: | Yes |
| Description |
|
When listening to the "EntityPotionEffectEvent" and retrieving the new applied effect with event#getNewEffect() and then getting the type of the PotionEffect , the type does not match with the APIs PotionEffectType enums. I cannot see a reason for this to not be working if not because of a spigot bug\improper code.
// java @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onEntityPotionEffect(final EntityPotionEffectEvent event) { final Entity entity = event.getEntity(); if (!(entity instanceof LivingEntity)) return; final LivingEntity livingEntity = (LivingEntity) entity; final EntityPotionEffectEvent.Action action = event.getAction(); final EntityPotionEffectEvent.Cause cause = event.getCause(); final PotionEffect potionEffect = event.getNewEffect(); if (potionEffect == null) return; final PotionEffectType potionEffectType = potionEffect.getType(); if (potionEffectType != PotionEffectType.POISON) { System.out.println(String.format("This is not poison, it is %s", potionEffectType.getName())); return; }
When a poison potion effect gets applied to the player, either via a bottle, or via the command "/effect give TheViperShow poison 15 0" , the condition that check that the potionEffectType is NOT EQUAL to Poison , always fails, however it prints this:
NOTE: This bugs also affects many other versions, I've tested 1.15.2 and 1.14.4 which had the same exact issue. |
| Comments |
| Comment by md_5 [ 28/Jul/20 ] |
|
This seems user error. They're not enums and therefore you can't expect to use == on them |
| Comment by Marco [ 27/Jul/20 ] |
|
Thank you. equals() should work |
| Comment by Black Hole [ 24/Jul/20 ] |
|
Looking at the source code, Spigot is using CraftPotionEffectType while the constants in the class PotionEffectType are using PotionEffectTypeWrapper. As a workaround you should not compare instances and use the equals method or Objects.equals(). |