I have a code that looks like this: Code: @EventHandler public void onCreatureSpawnEvent(CreatureSpawnEvent event) { // Some code that doesn't run at all when a mob spawns } However, the code doesn't even run when a mob spawns. Am I doing anything wrong?
I didn't, sorry, I'm new to Java. Now I registered the listener and then... my system crashed. After testing with /gamerule doMobSpawning, it's making a NPE every time I spawn a mob.
Just giving some boosts to mobs that spawn in by a random chance. It doesn't happen anymore though. Here's my code: Code: public class CreatureSpawnHandler implements Listener { private Main plugin;Random r = new Random();@EventHandlerpublic void onCreatureSpawnEvent (CreatureSpawnEvent event) { if (Main.getInstance().isNight) { LivingEntity entity = event.getEntity();EntityType type = event.getEntityType(); if (type.equals(EntityType.ZOMBIE)) { entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(40);entity.setHealth(40); if (r.nextFloat() <= .35) { entity.getEquipment().setItemInMainHand(new ItemStack(Material.IRON_SWORD));} if (r.nextFloat() <= .1) { entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000000, 0));} } else if (type.equals(EntityType.SKELETON)) { entity.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 10000000, 0));} else if (type.equals(EntityType.SPIDER)) { entity.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 10000000, 1));} } } } Wonder why bukkit breaks indentations and some newlines. + No errors on the editor side. ++ I think the crash was just a coincidence, it doesn't happen anymore whatever I do. Fixed it! Main.getInstance() was returning null and I just needed to correct that.