CreatureSpawnEvent

Discussion in 'Plugin Development' started by ColaCraft, Aug 10, 2013.

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

    ColaCraft

    What I am trying to do is deny spawning of any mob, unless they were spawned by a spawner or by my plugin.

    Here is my code:

    Code:java
    1. @EventHandler
    2. public void onCreatureSpawn(CreatureSpawnEvent event) {
    3. if(event.getLocation().getWorld().getName() != "world_nether") {
    4. if(event.getSpawnReason() != SpawnReason.SPAWNER || event.getSpawnReason() != SpawnReason.CUSTOM) {
    5. event.setCancelled(true);
    6.  
    7. }
    8. }
    9. }


    It seems to be doing something, because when I remove it mobs spawn as they would normally.

    Thanks for the help!
     
  2. Offline

    ColaCraft


    Oops, forgot to mention. With this code, nothing spawns at all.
    Assist
     
  3. ColaCraft
    Try
    Code:java
    1. if(!event.getLocation().getWorld().getName().equals("world_nether")) {

    instead.

    Have you registered your events? Any errors in console? Also debug your code.
     
  4. Offline

    ColaCraft


    Yes, the events are registered. No mobs are spawning at all with this code- I am going to try to call the main world & see what that does, instead of calling all of the worlds EXCEPT the main world.
     
Thread Status:
Not open for further replies.

Share This Page