Hi guys, as said in the title I want to save potions to config. I just did with ItemStacks, but not with potions. So can I convert the potion to an ItemStack? The potion tag is deprecated at the moment as it looks. I just tried this one: Code (Text): if(args[3].equals("373")) { int id = Integer.parseInt(args[4]); int amount= Integer.parseInt(args[5]); int effect = Integer.parseInt(args[6]); stack = new ItemStack(id, amount, (short) effect); } but the (short) effect is also deprecated. So is there a way? Saving into config should be no problem for me. Thank you!
Potions don't use durability anymore. If you want to save them to a config, just put the ItemStack in a ConfigurationSection. But your code looks like you are not trying to save to a config but to build one from a command? In that case you'd need to use PotionMeta to set the effects, maybe take an effect name in the command rather than a durability id.
Saving in config is no problem for me, I want to save it into a config after sending a command. Like /potion arg arg arg ID amount effectID
In that case just use PotionMeta: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/inventory/meta/PotionMeta.html After making the ItemStack a potion, get its ItemMeta, cast to PotionMeta, add effects, then call setItemMeta.
Use the ItemStack constructor that takes a Material- try to avoid the deprecated id-based methods if you can. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html There is Material.POTION, and separate materials for thrown and lingering potions.
Okay thank you, you helped me very much! I've just one little question, in this code Code (Text): pMeta.addCustomEffect(new PotionEffect(PotionEffectType.getByName(args[5]), 1200, 1200) , true); the both "1200" are the duration and the amplifier. Can those be set to the default value of the effect?
I don't think so, just look up what they should be on the mc wiki. I'm guessing default amplifier is normally zero so that one's easy.