[SPIGOT-1638] Potion class error Created: 02/Mar/16  Updated: 12/Mar/16  Resolved: 12/Mar/16

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: LEGOlord 208 Assignee: Black Hole
Resolution: Fixed Votes: 9
Labels: 1.9, bug, potion, spigot

Attachments: PNG File 2016-03-04_13.48.25.png    

 Description   

The Potion class is broken. Use it and you just get an untextured water bottle
https://pbs.twimg.com/media/Cci7AToW4AA7ckf.jpg:large



 Comments   
Comment by Faris Rehman [ 11/Mar/16 ]

Thanks tastybento. I use my own class, however your class seems more neater and useful. I'll be making a remake of yours using reflection and if you don't mind, I could post it here.

LEGOlord 208, 'it's not that hard to use' for normal developers, but for new people, this would be hard to use. I myself have made a version using reflection but someone new to programming bukkit plugins most likely won't be able to do what I did.

Everything that PseudoKnight said, I agree with.

Comment by PseudoKnight [ 11/Mar/16 ]

Your comment is problematic. There are multiple reasons the API exists, and ease-of-use is only one of those. I've done workarounds for my server's issues related to this. But for the users of the plugin I contribute to, this isn't workable. Even if I was okay with doing a temporary patch using the NBT or the nms.PotionRegistry, this could cause more problems later for a couple reasons.

Comment by LEGOlord 208 [ 11/Mar/16 ]

In that case you have to use NBT tags. Come on it's not that hard to use. I had to do it instead of SpawnEgg#getType, and to make an item glowing effect. It's easy! So you don't have to hurry spigot so much!

Comment by tastybento [ 11/Mar/16 ]

For those who want a stand-in class for Potions, I'm using this on ASkyblock. https://github.com/tastybento/askyblock/blob/master/src/com/wasteofplastic/askyblock/util/Potion1_9.java

Comment by Faris Rehman [ 10/Mar/16 ]

LEGOlord 208, what about getting the actual main type of potion (e.g. serializing/saving a regeneration II potion)? It's not part of getCustomEffect, it's in the NBT tags.

Comment by LEGOlord 208 [ 10/Mar/16 ]

You should use ItemMeta for setting. And you can loop through getCustomEffects for getter

Comment by Faris Rehman [ 09/Mar/16 ]

Agreed.

I have no idea why it's taking so long for Spigot to fix this, unless they avoid NBT tags completely which I doubt.

I've already made my own NBT tag reader and setter using reflection:
https://github.com/KingFaris10/KingKits/blob/master/src/main/java/com/faris/kingkits/helper/util/PotionUtilities.java

Comment by Kimberly Boynton [ 09/Mar/16 ]

This is not a minor bug. This is holding up my server's entire switch over to 1.9

Comment by Faris Rehman [ 08/Mar/16 ]

Is there any progress on it, or anything on this issue?

Comment by PseudoKnight [ 08/Mar/16 ]

If we're listing reasons why this is important, I contribute to a large scripting plugin where the item objects depend on this when doing anything with potions that aren't custom potions. It's one of the last things that is keeping me from updating my server to 1.9. I can workaround the issue on my own server with NMS, but I shouldn't have to push something like that to the scripting plugin.

I have the same problem with the new spawn eggs, which unfortunately are used on my server a lot too. SPIGOT-1592

Comment by Faris Rehman [ 07/Mar/16 ]

Same with mine and many others. For now, I'm making a public Potion API that uses reflection.

I attempted to make a duplicate with a higher priority and md_5 marked it as duplicate (therefore showing he acknowledges this exists).
https://hub.spigotmc.org/jira/browse/SPIGOT-1817

Comment by Sven Olderaan [ 07/Mar/16 ]

Should probably set the priority to critical. My entire plugin is broken.

Comment by Faris Rehman [ 06/Mar/16 ]

Indeed, you must use NBT reading. However, there's still the fact Spigot needs to fix its Potion class. This way, we won't even need to use NBT reading as Spigot would handle it.

Comment by LEGOlord 208 [ 06/Mar/16 ]

Nevermind! I was wrong the whole time! I just assumed getMainEffect existed. I can't help you, but I would recommend NBT reading.

Comment by LEGOlord 208 [ 06/Mar/16 ]

Go to the JavaDocs, navigate to PotionMeta, and see what methods are available

Comment by PseudoKnight [ 06/Mar/16 ]

No, getMainEffect() does not exist in the entire server, working or not. I just checked for it in 1.8.8 too.

Am I in the right ticket here? I didn't want to duplicate, but the core issue that we can't identify potions regardless of method. I can see the necessary information in nms.ItemPotion and nms.PotionRegistry.

Comment by Faris Rehman [ 05/Mar/16 ]

getType() does exist in the 'Potion' class, not PotionMeta. However, 'Potion' does not even work as it relies on durabilities.

This is an issue on Spigot's side.

Comment by PseudoKnight [ 05/Mar/16 ]

I try and be as thorough as I can be before posting here. I checked the JavaDocs everywhere I could think of looking. I even looked some in the source code, to get some more clues. I'm not denying that I may be missing something, but it's definitely not in PotionMeta. getMainEffect() does not exist. I noticed setMainEffect() right away, though. But that's not it either. That's just the first index of the custom effects, which would be returned with getCustomEffects().

Comment by LEGOlord 208 [ 05/Mar/16 ]

Yes there is. getMainEffect()
And I think getCustomEffects are ALL effects.

For further questions, it would be nice if you use the JavaDocs, as that is what they are made for
https://hub.spigotmc.org/javadocs/spigot/

Comment by PseudoKnight [ 05/Mar/16 ]

Yes, that's not the issue, though. Custom effects work fine. However, if I take a regular potion of fire resistance out from the creative menu, there's no method that I know of that can determine that it's a fire resistance potion.

Comment by LEGOlord 208 [ 05/Mar/16 ]

Since 1.7 I believe a Potion can have multiple effects. Use PotionMeta.getCustomEffects()

Comment by PseudoKnight [ 05/Mar/16 ]

Is there a way to get what PotionEffect a normal potion ItemStack is? It's not PotionMeta. I think it needs to be updated.

Comment by tastybento [ 04/Mar/16 ]

[Edit] I just needed a way to tell if an itemstack that I know is potion is a potion or just water. This simple code appears to work (I put it in an NMS class for 1.9 only).

    public boolean isPotion(ItemStack item) {
        net.minecraft.server.v1_9_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = stack.getTag();
        if (tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty()) {
            return false;
        }
        return true;
    }

I'd like to look into this whole NMS thing and see if I can submit a pull request to rewrite the Potion class using the new tags, but it's my first time so others may get there before me!

Comment by PC Luddite [ 03/Mar/16 ]

There should be a mechanism in place for converting potions serialized in 1.8 to be deserialized in 1.9.

Comment by LEGOlord 208 [ 03/Mar/16 ]

PotionMeta is driving me nuts! I am searching for a weird bug in my code like crazy lel

Comment by Black Hole [ 03/Mar/16 ]

Related to SPIGOT-1673

Comment by LEGOlord 208 [ 02/Mar/16 ]

Thanks! I hope this class gets deprecated so it isn't missleading

Comment by Black Hole [ 02/Mar/16 ]

Potion data values are not used in 1.9 anymore, you should use PotionMeta.

Comment by LEGOlord 208 [ 02/Mar/16 ]

What do you mean? Brewing stands are in the Minecraft code... They do not use the Spigot Potion class?
I'll do some testing, but they really worked exactly like a sharm using 1.8.8 / 1.8.9...

Comment by kdthehun [ 02/Mar/16 ]

Brewing stand makes them as well by default. Also the brewing stand doesn't require fuel to brew, it can brew without it just fine.

Comment by LEGOlord 208 [ 02/Mar/16 ]

My code is spread out and hard to find. It worked great in 1.8, and I see nothing that could be the cause of it. Also I'm thinking it could have with the new 1.9 potion features to do.

Comment by William Surgeon [ 02/Mar/16 ]

From what I'm seeing that is most likely a potion with invalid data. Do you have any code associated with this issue?

Generated at Tue Apr 22 03:30:26 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.