Solved Event by a potion thrown with a specific name

Discussion in 'Plugin Development' started by jersogamer, Jul 10, 2018 at 7:41 PM.

  1. Offline


    sorry if my english is not good, well, I want to do this: when you throw a potion of poison with a duration of 1 second and with the name "Bomb" , I want to do an explosion where the potion hits the floor.
    Or maybe not using the name "Bomb", I would like to use a Lore or a Enchantment to identify the potion

    I got this to make the explosion:
        public void bomb1(PotionSplashEvent eventoos) {
                eventoos.getEntity().getWorld().createExplosion(eventoos.getEntity().getLocation(), 4F);
    But it works with every potion, so I don't know if someone could help me.

    and I don't know if it is possible to do the potion without an effect.

    also I don't know how to set the name to the potion.
    Last edited: Jul 13, 2018 at 5:18 PM
  2. Offline


    I think you can set the custom name of the projectile (the ThrownPotion) when it's launched. When any projectile hits a block you can check for that custom name again
  3. Offline


    Sorry but, that's another problem I don't know how to set the name and how to check if the potion has that name.
  4. Online

    timtower Ninja on the waves Moderator

  5. Offline


    I'm not good at coding so those links didn't help me, I know that is bad to ask for a code, but I don't know If there's a person who could help me sending a part of the code or a better explanation, 'cause I neither know what event to use nor how to use it, that's my big problem. I'm new at these things of coding.

    Also I tried to do this but it didn't work
        public void bomb1(PotionSplashEvent eventoos) {
            Potion pot1 = (Potion) eventoos.getPotion().getEffects();
            if(pot1 != null && pot1.equals(PotionType.FIRE_RESISTANCE) ) {
            eventoos.getEntity().getWorld().createExplosion(eventoos.getEntity().getLocation(), 3F);
    Pd: Sorry moderator if I made a reply wrong, I still don't understand in wich cases I can reply without making a double post or answer.

    Pd2: Sorry, if my english is not good.
  6. Offline


    @jersogamer I think something like this should work for getting the name:
    1. if (e.getPotion().getItem().getItemMeta().getDisplayName().equals("Bomb")) {
    2. //Code here
    3. }

    If you do this then remember to check for null etc.
  7. Offline


    Thank you, but it didn't work, I get an error in console:

    Here is the code:
    if(eventoos.getEntity().getItem().getItemMeta().getDisplayName().equals("Bomb") && eventoos.getEntity().getItem().getItemMeta().getDisplayName() != null)
  8. Online

    timtower Ninja on the waves Moderator

  9. Offline


    Thank you so much, It works!

Share This Page