[SPIGOT-1673] Potion Class Created: 03/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: Michael Forseth Assignee: Unassigned
Resolution: Fixed Votes: 6
Labels: 1.9, bug, error, post, spigot
Environment:

Not important



 Description   

There are two problems I have experienced with the Potion class.

1. Using the method "fromItemStack(ItemStack item)" it throws an exception if the potion is a lingering potion or splash potion. Probably because of the ID switch in 1.9.

Here is the stack trace:

[Server thread/ERROR]: Could not pass event InventoryClickEvent to Feudal vBeta-1.0.0
org.bukkit.event.EventException
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1815) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:33) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:10) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [my.jar:git-Spigot-3af4605-ed8cef0]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
	at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [my.jar:git-Spigot-3af4605-ed8cef0]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
Caused by: java.lang.IllegalArgumentException: item is not a potion
	at org.bukkit.potion.Potion.fromItemStack(Potion.java:417) ~[my.jar:git-Spigot-3af4605-ed8cef0]
	at us.forseth11.feudal.classes.XP.inventoryClick(XP.java:436) ~[?:?]
	at us.forseth11.feudal.core.EventManager.click(EventManager.java:235) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[my.jar:git-Spigot-3af4605-ed8cef0]

2. Potions which do load return null when using the getType method in the Potion class.

Stack trace:

[Server thread/ERROR]: Could not pass event InventoryClickEvent to Feudal vBeta-1.0.0
org.bukkit.event.EventException
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [my.jar:git-Spigot-3af4605-ed8cef0]
	at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1815) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:33) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PacketPlayInWindowClick.a(SourceFile:10) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [my.jar:git-Spigot-3af4605-ed8cef0]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
	at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [my.jar:git-Spigot-3af4605-ed8cef0]
	at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [my.jar:git-Spigot-3af4605-ed8cef0]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
Caused by: java.lang.NullPointerException
	at us.forseth11.feudal.classes.XP.inventoryClick(XP.java:442) ~[?:?]
	at us.forseth11.feudal.core.EventManager.click(EventManager.java:235) ~[?:?]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]
	at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[my.jar:git-Spigot-3af4605-ed8cef0]

I am assuming if problem 1 is solved then problem 2 will be resolved. Based on what is happening, I am assuming the method fromItemStack gets the potion using its durability data. Since 1.9 does not use durability data to define potions anymore, this becomes a problem.



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

Then this should be 'Major' since 'plugin functionality' in almost any item based plugin is broken (since most item based plugins use potions), e.g. kits.

Also, yes but I'm talking about the updated plugins, the ones that are active. It'd be a lot easier if we could have a 'new API' that lets us get the potion effect type by item. I.e. I was talking about this Potion class rewrite, not using data values but NBT tags.

I had to make my own class that reads NBT tag 'Potion' from items using reflection, which isn't ideal, especially for someone who's new to Bukkit/Spigot plugin programming as they most likely won't know reflection nor NMS.

Comment by md_5 [ 10/Mar/16 ]

Critical - Server is Non Functional
Major - Core Gameplay or Plugin Functionality is Broken
Minor - Everything Else
Trivial - One Line Fixes

This requires essentially a whole new API to be written, and old plugins probably won't even work with that new API. There is simply no way to reconcile potion NBT back to a data value.

Comment by Michael Forseth [ 10/Mar/16 ]

I set it as critical, but md changed it. I wrote this class to fix this btw: https://gist.github.com/forseth11/31b914badd376dbd38e2

Comment by Faris Rehman [ 10/Mar/16 ]

How does this have a 'minor' priority. It's broken many plugins and it's extremely difficult without knowing how to use reflection or NMS (which isn't even advised) to store and load potion data.

Comment by Black Hole [ 03/Mar/16 ]

Related to SPIGOT-1638

Generated at Sat Apr 05 09:04:19 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.