[SOLVED]How to only spawn skeletons/zombies?

Discussion in 'Plugin Development' started by mollekake, Jul 11, 2012.

Thread Status:
Not open for further replies.
  1. Hello guys!
    I'm quite new to plugin development and just started with my own plugin :D
    It's a lot of fun so far, but i've ran into a problem.

    I want all the mobs on my server to be skeletons, so when a mobs spawn, it doesn't spawn what it's supposed to, but a skeleton. So all natural spawns and all dungeon spawns are skeleton spawns.

    How can i do this?

    Also, is there an easy way to make the skeletons move slower?

    I appreciate all the replies!
    Looking foreward to develop my own plugin :D
     
  2. Offline

    NinjaWAffles

    Code:
    Location pLoc = player.getLocation();
    world.spawnCreature(pLoc, EntityType.SKELETON);
    
    Oops... I know read over it. I'm not sure how to stop all mob spawning except for Skeletons.
     
  3. Listen for the CreatureSpawnEvent, than check if the entity that spawns is a skeleton, if it is let is spawn, if it is not, don't let is spawn.
     
    ferrybig likes this.
  4. Offline

    tabr

    maybe:
    Code:
    public void onCreatureSpawn(CreatureSpawnEvent e)
        {
        if (e.getEntityType() != EntityType.SKELETON)
            {
            e.setCancelled(true);
            e.getLocation().getWorld().spawnCreature(e.getLocation(), EntityType.SKELETON);//this should replace (cancel current, spawn new) NOT SKELETON spawn, if u want to just skip NON-SKELETON spawn, comment this line =)
            return;
            }
        [...]
        }
     
  5. That seems really simple!
    but i get errors. i get this:

    e.getLocation().getWorld().spawnCreature(e.getLocation(), EntityType.SKELETON);

    and error that the EntityType.SKELETON can't be resolved
     
  6. Offline

    gjossep

    Make sure you get the plugin instance, and make sure you import EntityType
     
  7. made sure i import the EntityType, didn't help. and i don't get the plugin instance thing.

    anyone else got tips?
    this is how it looks like now:

    Code:
    package allskeletons;
     
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
    import org.bukkit.entity.*;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.Skeleton;
     
     
    public class test{
     
       
        public void onCreatureSpawn(CreatureSpawnEvent e)
        {
        if (e.getEntityType() != EntityType.SKELETON)
            {
            e.setCancelled(true);
            e.getLocation().getWorld().spawnCreature(e.getLocation(), EntityType.SKELETON);
            return;
            }
        }
     
    }
    well actually it works fine. but only on the hostile mobs. all the cows and the other neutral mobs spawn :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  8. Offline

    bartboy8

    If you want to make then slower... put a potion effect of slowness on them when they spawn.
     
  9. as far as i know the slowness and speed effects dont work on mobs. but that's not really what i'm after primarily.
     
  10. you never imported the bukkit entitytypes
     
  11. You've imported the wrong entity type: import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
    It must be the bukkit one... remove that line and hover your red-underlined code, then see the quickfix list and pick the org.bukkit one !

    EDIT: actually just remove that line, it's already imported by org.bukkit.entity.*; :)
     
  12. ok so this is how it looks like now:
    Code:java
    1.  
    2. @EventHandler (priority = EventPriority.NORMAL)
    3. public void onCreatureSpawn (CreatureSpawnEvent event) {
    4.  
    5. if (plugin.getSettings().getBoolean("allowallmobs")) {
    6. if (override(event.getEntityType())) {
    7. int i = 1;
    8. while (i <= plugin.getSettings().getInt("skellies")) {
    9. if (event.getEntityType() != EntityType.SQUID) {
    10.  
    11.  
    12. LivingEntity spawnCreature = event.getLocation().getWorld().spawnCreature(event.getLocation(), EntityType.SKELETON);
    13.  
    14. }
    15. i++;
    16. }
    17. event.setCancelled(true);
    18. return;
    19. }
    20.  
    21. } else {
    22. event.setCancelled(true);
    23. return;
    24. }
    25. }
    26.  


    these are my imports:

    import java.util.List;
    import java.util.Random;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.CreatureSpawnEvent;
    import org.bukkit.event.entity.EntityCombustByBlockEvent;
    import org.bukkit.event.entity.EntityCombustByEntityEvent;
    import org.bukkit.event.entity.EntityCombustEvent;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
    import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    doing a lot of stuff at once :p


    still don't replace the neutral mobs that spawn. don't get why they are allowed to spawn :(
     
  13. And is there a problem ? Because you didn't say...

    Also, you might want to use Ctrl+i (if using eclipse) to indent the code because it's bearly readable.
     
  14. yea i edited it with the problem :p
    still don't replace the neutral mobs that spawn. don't get why they are allowed to spawn.

    thanks for the tips! will try and make it more readable
     
  15. Offline

    Darksonn

    The neutral mobs are spawned on world generation, so you dont get an event, you have to use a chunk populator or something to do that.
     
  16. ah, that makes sense. cause i could not use spawn eggs.
    I still get an warning though, should i just ignore that?
    i get these:
    - the method spawnCreature(Location, EntityType) from the type World is deprecated. (i have NO idea what this means :S)
    - the local variable spawnCreature is never read

    on this line of code:
    LivingEntity spawnCreature = event.getLocation().getWorld().spawnCreature(event.getLocation(), EntityType.SKELETON);
     
  17. Offline

    EnvisionRed

    It seems that there is a deprecated version of the same method that uses the parameters spawnCreature(Location, CreatureType).

    Yours is fine though.
     
  18. you talking about an constructor, but the methode he is saying belongs to the interface world, interfaces dont have constructors, so you are wrong.
    mollekake Did you imported the right EntityType?
     
  19. ok so my remaining problems is to get it to replace a mobspawn. cause right now when i use a mob egg, nothing spawns, but it should spawn a skeleton.
    and i want no neutral mobs to spawn.

    anyone got hints in the right direction for those 2 things?

    imported these:
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  20. Offline

    EnvisionRed

    I couldn't think of the proper term, I meant it takes the parameters.
     
  21. Offline

    Firefly

    CreatureSpawnEvent is probably not being called when animals spawn (unless I'm mistaken; which is quite possible). As for replacing mob spawns, it should work fine if you cancel the event when a Skeleton doesn't spawn and spawn a creature in its place.
     
  22. anyone know what event is called when animals are spawned? i looked into chunk population but couldn't figure it out.
     
  23. Offline

    gregroberti

    You can turn off animal spawns in the server.properties file:
    spawn-animals=false

    It appears that the CreatureSpawnEvent is not called when neutral mobs spawn. Hope that helps!
     
  24. yea i thought about that, but that way there will not spawn skeletons during the day.
     
  25. You can also force that with a plugin by setting:
    Code:
    for(World world : getServer().getWorlds())
    {
    	world.setAnimalSpawnLimit(0);
    }
    And just to be sure you're covering all worlds, you should also listen to WorldLoadEvent and change that.

    EDIT: Skeletons will burn in the day by default, unless you're preventing that.

    Still, a long time ago the event used to trigger for animals too... is this a bug or what ?
    I remember using a plugin that prevented any mob (neutral or not) from spawning near human-made blocks (cobble, wood planks, etc) and it worked... you should look into that.
     
  26. yea, but still stuck with no hostile mobs during the day :(
     
  27. As far as I know enemies spawn in the day but in dark places where they can be spawned... so spawning them in full light to burn would be pretty ugly, spawning in darkness is better.

    Also, mind that I edited my previous post.
     
  28. i've made them not burn in sunlight. hence why i want them to spawn during the day in bright sunlight
     
Thread Status:
Not open for further replies.

Share This Page