Solved Event by a potion thrown with a specific name

Discussion in 'Plugin Development' started by jersogamer, Jul 10, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    jersogamer

    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:
    Code:
    @EventHandler
        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
  2. Offline

    MightyOne

    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

    jersogamer

    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. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    jersogamer

    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
    Code:
    @SuppressWarnings("unlikely-arg-type")
        @EventHandler
        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);
            return;
            }
           
                }
    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

    KarimAKL

    @jersogamer I think something like this should work for getting the name:
    Code:Java
    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

    jersogamer

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

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

    timtower Administrator Administrator Moderator

  9. Offline

    jersogamer

    Thank you so much, It works!
     
Thread Status:
Not open for further replies.

Share This Page