@EventHandler
public void onEntitySpawn (EntitySpawnEvent e) {
if (e.getEntity () instanceof Player) {
e.setCancelled (true);
Bukkit.broadcastMessage ("Can't BE PAWN");
}
}
I tried it without instanceof, but then it spams the console and doesn't do anything anymore. CreatureSpawnEvent doesn't work either.
I don't think the player will spawn through the EntitySpawnEvent. Try the PlayerRespawnEvent
I want to block the player from spawning other entities using spawneggs.
With
@EventHandler
public void onEntitySpawn (EntitySpawnEvent e) {
if (e.getEntity () instanceof Entity) {
e.setCancelled (true);
Bukkit.broadcastMessage ("Can't BE PAWN");
}
}
it works, but the whole console is spamming me.
For this you need the CreatureSpawnEvent. GetEntity () gives you back the entity that is spawned. What you are looking for is the SpawnReason. This is an enum and contains the constant SPAWNER_EGG. This is the event you want to cancel…
With EntitySpawnEvent you do not test whether someone is spawning something, but whether an entity spawns on its own
You would have to do it with the PlayerInteractEvent and then cancel it when the player is holding a spawn egg