Give a player a custom potion

Discussion in 'Spigot Plugin Development' started by Hello1231, Sep 13, 2019 at 11:36 PM.

  1. Hello, I am trying to make a splash potion of levitation, but it acts like a splash water bottle. Everything else about it works, just not the effect. Here is the code:
    Code (Text):
    ItemStack pot1 = new ItemStack(Material.SPLASH_POTION, 1);
                        PotionMeta meta = (PotionMeta) pot1.getItemMeta();
                        meta.addCustomEffect(new PotionEffect(PotionEffectType.LEVITATION, 10, 0), true);
                        meta.setDisplayName(ChatColor.WHITE + "Potion Of Levitation");
                        List<String> potLore = new ArrayList<String>();
                        potLore.add(ChatColor.translateAlternateColorCodes('&', "&e10 Seconds Of Levitation"));
    Any Ideas? Thanks.:)
  2. try to set the itemmeta only one time
    • Like Like x 1
  3. Changed it, still not working.:( Thanks anyway, don't know how I didn't see that.(y)
  4. Mmm potion meta works with Material.POTION, if you want to launch an splash_potion use another method, but, i don't know how this don't works,mmmm try to change the values of time and amplifier of potion
    • Useful Useful x 1
  5. Just make the item stack into the potion itself?

    Add the code of the potion as a short
    Code (Text):
    • Like Like x 1
  6. but if it want to change the velocity of the levitation?
    • Like Like x 1
  7. I may have found a workaround!
    I used this:
    Code (Text):

    ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
    String command = "minecraft:give " + player.getName() + " minecraft:splash_potion{CustomPotionEffects:[{Id:25,Duration:200}],CustomPotionColor:16777215,display:{Name:\"\\\"Potion Of Levitation\\\"\"}}";
    Bukkit.dispatchCommand(console, command);
    I got the command from
    It works.:):):)
  8. maybe depends of commands it's not the best way :/
    • Agree Agree x 1
  9. Try with this

    Code (Java):

                Player pl = event.getPlayer();
                ItemStack poti = new ItemStack(Material.SPLASH_POTION);
                PotionMeta meta = (PotionMeta)poti.getItemMeta();
                meta.addCustomEffect(new PotionEffect(PotionEffectType.POISON, this.val$to, this.val$to), true);
                ThrownPotion pot = (ThrownPotion)pl.getWorld().spawn(pl.getLocation().add(0,0,1), (Class)ThrownPotion.class);
    Or If you want add potion effect to an Player
    Code (Java):

    Player p = event.getPlayer();
    p.addPotionEffects(new PotionEffect(PotionEffectType.LEVITATION, 10, 10, true);
    • Like Like x 1
  10. Tried this.
    Code (Text):
    cannot be resolved or is not a field, and it says "Type safety: The expression of type Class needs unchecked conversion to conform to Class" for
    Code (Text):
      <Entity> pl.getWorld().spawn(pl.getLocation().add(0,0,1), (Class)ThrownPotion.class);
    Was I supposed to replace those with something? Sorry if the problem is my limited knowledge of coding.:confused:
  11. The val$to is in place of the values needed for the constructors.

    You don't need to cast with (Class)ThrownPotion.class iirc, so it should work just fine as ThrownPotion.class for the parameter.