[SPIGOT-1164] Potion.getType() NPE when the type is WATER Created: 03/Sep/15 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: | Major |
| Reporter: | t. hartmann | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | 1.8.8, spigot | ||
| Environment: |
Spigot 1.8.8-R0.1-SNAPSHOT |
||
| Plugin: | Working on it |
| Description |
|
When i get the type of a potion and the type is WATER, Potion.getType() return NULL. |
| Comments |
| Comment by t. hartmann [ 08/Nov/15 ] |
|
hi, i create the ItemStack with: player.getItemInHand(); if the potion, that the player hold in hand, is a water potion, then it return null, not PotionType.WATER. |
| Comment by DemonWav [ 08/Nov/15 ] |
|
Potion.fromItemStack() gets the Potion from Potion.fromDamage(). fromDamage() can return a Potion with a null PotionType when the given damage doesn't correspond with a Potion. fromItemStack() uses the item's durability (or damage value) for this. You probably have an itemstack with a weird durability for some reason. The bug here is probably just poor documentation. If that's not the issue please show the ItemStacks you are using to create the Potion. |
| Comment by t. hartmann [ 06/Sep/15 ] |
|
thats the code snipped: public static List<String> CreateItemStackMessage(ItemStack item,myTrade plugin) { String strItem=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Item : "; String strDurability=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Haltbarkeit : "; String strAnz=ChatColor.GOLD.toString() +ChatColor.ITALIC +"Anzahl : "; List<String> mess=new ArrayList<String>(); //************ NAME *********** Material mat=item.getType(); if(mat==Material.POTION) { int data=item.getDurability(); if(data==16) mess.add(strItem+"Seltsamer Trank"); else if(data==32) mess.add(strItem+"Dickflüssiger Trank"); else if(data==64) mess.add(strItem+"Gewöhnlicher Trank (verlängert)"); else if(data==8192) mess.add(strItem+"Gewöhnlicher Trank"); else { //HIER !!!! Potion po=Potion.fromItemStack(item); String wurf="",level=""; if(po.isSplash()) wurf="Wurf"; if(po.getLevel()==2) level=" II"; else if(po.getLevel()>2) level=String.valueOf(po.getLevel()); int dauer=0; for(PotionEffect effect :po.getEffects()) dauer=effect.getDuration()/20; int min=dauer/60; dauer=dauer-min*60; //***** HERE **** if(po.getType()==null) plugin.getLogger().warning("***************** NULL"); else plugin.getLogger().warning("*****************"+po.getType()); mess.add(strItem+wurf+plugin.PotionNames.get(po.getType().toString())+level+" ("+min+":"+dauer+")"); } } ...... |
| Comment by md_5 [ 06/Sep/15 ] |
|
Can you be specific with your code? The following unit test passes: |
| Comment by t. hartmann [ 03/Sep/15 ] |
|
same with the Spigot version: [18:02:34 INFO]: git-Spigot-0359393-9a17f01 - 1.8.8-R0.1-SNAPSHOT) |
| Comment by SpigotMC [ 03/Sep/15 ] |
|
Your build is not the latest and therefore may be the reason you are having this issue. Spigot is 1 version(s) behind. CraftBukkit is 1 version(s) behind. This message was automatically generated and is not guaranteed to be a solution to your issue. |