Why is "MONSTER" not = Every CreatureType?

Discussion in 'Plugin Development' started by Smex, Oct 2, 2011.

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

    Smex

    I'm making a little testplugin which prevents only monsters
    from spawning, sounds extremly simple actually.

    The only thing I can't pass trough is,
    how do I set, let's say:

    Code:
    this.getServer().getPluginManager().registerEvent(Event.Type.CREATURE_SPAWN, new EntityListener(){
                public void onCreatureSpawn(CreatureSpawnEvent event){
                    CreatureType a = event.getCreatureType();
                            if(a == CreatureType.MONSTER){
                                event.setCancelled(true);
                            }
    
                }
            },Event.Priority.Normal, this);
    But as the Creature.Type.MONSTER doesn't stand for every Monster, which
    is not logic to me, I can't prevent them from spawning.

    I know that the event get's only things like "CREEPER,SPIDER etc."
    but how would I put all those into 1 Type?
     
  2. Offline

    Orcem12

    @Smex
    Monster spawning was disabled for 1.8.1 builds and up.
     
  3. Offline

    Smex

    Well, so now there is no way to handle this?
    mh.
     
  4. Offline

    Fishrock123

  5. Offline

    Smex

    @Fishrock123
    well look what I've done to still let it work:
    Code:
    this.getServer().getPluginManager().registerEvent(Event.Type.CREATURE_SPAWN, new EntityListener(){
                public void onCreatureSpawn(CreatureSpawnEvent event){
                    CreatureType a = event.getCreatureType();
                    if(a == CreatureType.CAVE_SPIDER){
                        event.setCancelled(true);
                    }
    
                    CreatureType b = event.getCreatureType();
                    if(b == CreatureType.CREEPER){
                        event.setCancelled(true);
                    }
    
                    CreatureType c = event.getCreatureType();
                    if(c == CreatureType.ENDERMAN){
                        event.setCancelled(true);
                    }
    
                    CreatureType d = event.getCreatureType();
                    if(d == CreatureType.GHAST){
                        event.setCancelled(true);
                    }
    
                    CreatureType e = event.getCreatureType();
                    if(e == CreatureType.GIANT){
                        event.setCancelled(true);
                    }
    
                    CreatureType f = event.getCreatureType();
                    if(f == CreatureType.PIG_ZOMBIE){
                        event.setCancelled(true);
                    }
    
                    CreatureType g = event.getCreatureType();
                    if(g == CreatureType.SILVERFISH){
                        event.setCancelled(true);
                    }
    
                    CreatureType h = event.getCreatureType();
                    if(h == CreatureType.SKELETON){
                        event.setCancelled(true);
                    }
    
                    CreatureType i = event.getCreatureType();
                    if(i == CreatureType.SLIME){
                        event.setCancelled(true);
                    }
    
                    CreatureType j = event.getCreatureType();
                    if(j == CreatureType.SPIDER){
                        event.setCancelled(true);
                    }
    
                    CreatureType p = event.getCreatureType();
                    if(p == CreatureType.ZOMBIE){
                        event.setCancelled(true);
                    }
    
                    CreatureType q = event.getCreatureType();
                    if(q == CreatureType.WOLF){
                        event.setCancelled(true);
                    }
                }
            },Event.Priority.Normal, this);
    This must be the worst way to handle this, right? :p
     
  6. Offline

    Fishrock123

    Certainly not the best way. :p

    public void onCreatureSpawn(CreatureSpawnEvent event) {

    if (event.getEntity() instanceof Monster) {
    event.setCancelled(true);
    }
    }
    Just check if the event is an instanceof monster. :p

    (Undocumented, but it does also cover ghast.)
     
    Smex likes this.
  7. Offline

    Jogy34

    a monster is a creature that looks like the default person but they will attack you
     
  8. Offline

    Smex

    Ok, I will use this. :p

    Ye and what the f"""?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
Thread Status:
Not open for further replies.

Share This Page