Code (Java): public void onMobSpawn(CreatureSpawnEvent e) { if (mobPot) { LivingEntity mob = e.getEntity(); Random rand = new Random(); mob.addPotionEffect(new PotionEffect(potions[rand.nextInt(potions.length + 1)], Integer.MAX_VALUE, 5)); System.out.println("Mob is potioned"); Bukkit.getConsoleSender().sendMessage("A mob is potioned"); } else { System.out.println("Mob not potioned"); Bukkit.getConsoleSender().sendMessage("Mobs didn't get potioned"); } } This is not working can anyone pls help.... To be clear nothing is happening.... Also Code (Java): Boolean mobPot = true; PotionEffectType[] potions = PotionEffectType.values(); Thnx in advance
Did you add @EventHandler before the event? It would look like this: Code (Text): @EventHandler public void onMobSpawn(CreatureSpawnEvent e) { if (mobPot) { LivingEntity mob = e.getEntity(); Random rand = new Random(); mob.addPotionEffect(new PotionEffect(potions[rand.nextInt(potions.length + 1)], Integer.MAX_VALUE, 5)); System.out.println("Mob is potioned"); Bukkit.getConsoleSender().sendMessage("A mob is potioned"); } else { System.out.println("Mob not potioned"); Bukkit.getConsoleSender().sendMessage("Mobs didn't get potioned"); } } Also, you need to register the event.
Hello, You probably forgot the @EventHandler annotation. Also, make sure you registered your listener. A complete tutorial about the Event API is available here: https://www.spigotmc.org/wiki/using-the-event-api/
Lol... Noo i didnt it was a very small mistake was trying to figure out whats happening from so long... Thnx so much
Also one doubt is can i get the potion effect a mob has when i hit it with a blaze rod using a onDamageEvent or something like that?
You can get a list of potion effects using LivingEntity#getActivePotionEffects(). You might need to iterate over them using a foreach loop.