1.15.2 Custom Potions

Discussion in 'Spigot Plugin Development' started by ArKeid0s, Feb 15, 2020.

  1. Hello I am trying to create potions that heals a custom value.
    As far as i am concerned, the amplifier value is linked to the default minecraft values, i can't have custom values with that
    Code (Java):
    ItemStack potion = new ItemStack(Material.POTION, 1);
    PotionMeta potionmeta = (PotionMeta) potion.getItemMeta();
    PotionEffect heal = new PotionEffect(PotionEffectType.HEAL, 1, 6);
    potionmeta.addCustomEffect(heal, true);
    potionmeta.setDisplayName("ยง9HEALPOTION");
    potion.setItemMeta(potionmeta);
    Here i wanted a healing potion that gives 3 hearts back
    But it is not working because of the amplifier. So I started that :
    Code (Java):

    if(item.equals(main.iM.getPotionItemStack(Color.RED, main.iM.itHeal1, main.iM.itHeal1Lore))) {
                if(player.getHealth() != 20) {
                    if((player.getHealth() + heal1) > 20) {
                        player.setHealth(player.getHealth() + (20 - player.getHealth()));
                    }
                    else {
                        player.setHealth(player.getHealth() + heal1);
                    }
                    player.getInventory().getItemInMainHand().setAmount(0);
                    player.getInventory().addItem(new ItemStack(Material.GLASS_BOTTLE));
                }
     
    but it is very time consuming and not very effective i think

    What do you think ? what is the best solution ?
     
  2. yeah this is what i am doing in the second part of the code here is all the class
    Code (Java):
    public void onItemConsume(PlayerItemConsumeEvent e) {
            Player player = e.getPlayer();
            ItemStack item = e.getItem();

            // - POTIONS

            // - HEAL
            // - Potion of Healing -> 3 <3
            if(item.equals(main.iM.getPotionItemStack(Color.RED, main.iM.itHeal1, main.iM.itHeal1Lore))) {
                if(player.getHealth() != 20) {
                    if((player.getHealth() + heal1) > 20) {
                        player.setHealth(player.getHealth() + (20 - player.getHealth()));
                    }
                    else {
                        player.setHealth(player.getHealth() + heal1);
                    }
                    player.getInventory().getItemInMainHand().setAmount(0);
                    player.getInventory().addItem(new ItemStack(Material.GLASS_BOTTLE));
                }
     
  3. It's probably one of the best way to do this, yes.
     
  4. How do I do for the lingering potions ?
     
  5. I have a problem with my lingering potion how can i get the players in the cloud ?
    Code (Java):
        @EventHandler
        public void potionLingering(LingeringPotionSplashEvent e) {
            Player player = (Player) e.getEntity();
            ItemStack potion = e.getEntity().getItem();
            Collection<Entity> entities = e.getAreaEffectCloud().getNearbyEntities(e.getAreaEffectCloud().getWidth(), e.getAreaEffectCloud().getHeight(), e.getAreaEffectCloud().getWidth());

            if(potion == null) {
                return;
            }

            if(potion.equals(main.iM.getHealLingeringPotionItemStack(Color.RED, main.iM.itHealLingering1, main.iM.itHealLingering2Lore1, main.iM.itHealLingering1Lore2))) {
                if(entities instanceof Player) {
                    for(Entity players : entities) {
                            if(entities.getHealth() != 20) {
                                if((players.getHealth() + healSplash2) > 20) {
                                    players.setHealth(players.getHealth() + (20 - players.getHealth()));
                                }
                                else {
                                    players.setHealth(players.getHealth() + healSplash2);
                                }
                            }
                    }
                }

                player.getInventory().getItemInMainHand().setAmount(0);
            }

        }
    i did that but it is not working
     
  6. Maybe play around with attributes?
     
  7. I did but nothing is working sadly :/