#Event for naturally spawned villagers?
1 messages · Page 1 of 1 (latest)
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
LivingEntity entity = event.getEntity();
if (entity instanceof AbstractVillager) {
entity.setCustomName("George");
System.out.println("Named a villager creature George");
}
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
Entity entity = event.getEntity();
if (entity instanceof AbstractVillager) {
entity.setCustomName("Carol");
System.out.println("Named a villager entity Carol");
}
}
just check the spawn reason and see if that fixes the issue?
Also try not to use System.out.println, just use your plugins logger
Little something like
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
if(event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && event.getEntity() instanceof AbstractVillager) {
event.getEntity().setCustomName("George");
MAINCLASS.getPlugin(MAINCLASS.class).getLogger().info("Renamed a villager to George");
}
}```
Shouldn't the entity get named regardless of spawn reason? I'll try it, though.
And thanks, I'm aware about logger. Just not passing the plugin class atm.
Did not work
Seems recent versions do not trigger CreatureSpawnEvent when chunks are generated https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html#CHUNK_GEN