Disable Mob Spawning Naturally In A World

Discussion in 'Plugin Development' started by FluffyNarwhals, May 25, 2013.

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

    FluffyNarwhals

    I'm making a quest plugin, and I have mob spawners and low lighting, but I want to make it so that mobs won't spawn naturally in a certain world (in the quest world). Creepers and other mobs spawn because they're supposed to in the game when it's dark, but I don't want that to happen (again, for the specific world). I don't want a plugin to do it, I want to know how to code it into my plugin. Thanks!
     
  2. Offline

    BroTotal

    If i'm not mistaken you can actually go ahead and type in this exact order

    /difficulty peaceful
    /gamerule doMobSpawning False
    /difficulty easy/normal/hard

    Doing this should prevent any natural spawns but any forced spawns will still go through
     
  3. Offline

    skipperguy12

    FluffyNarwhals
    You can use dispatchCommand() and execute the commands BroTotal gave you if you want to make it coded.
     
  4. Offline

    FluffyNarwhals


    But that makes the whole server like that. I need only the 1 world
     
  5. Offline

    Zach_1919

    FluffyNarwhals Actually, if you've ever used NBTEdit, you'd know that gamerules apply per world. The setting the difficulty thing would change it for the whole server, but you eould change it back to whatever difficulty you want after you've set the gamerule for the world. Long story short, BroTotal 's method would work.
     
  6. Offline

    Wingzzz

    FluffyNarwhals
    Hey there!

    So, you would like it so that the world will only allow for spawning of mobs in certain cases eh?
    Well do we have just the thing for you!

    Code:java
    1. package com.github.pixelwingz;
    2.  
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.EventPriority;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.entity.CreatureSpawnEvent;
    7.  
    8. public class CreatureSpawnListener implements Listener {
    9.  
    10. @EventHandler(priority = EventPriority.NORMAL)
    11. public void onCreatureSpawn(CreatureSpawnEvent event) {
    12. /*
    13. * This will check to see if the world the event is being fired on is
    14. * one of the specified worlds you allow (can use a list/map etc... for
    15. * multiple)
    16. */
    17. if(event.getLocation().getWorld().getName() != "allowed-world") {
    18. if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.CUSTOM) {
    19. event.setCancelled(true);
    20. }
    21. }
    22. }
    23.  
    24. }

    Make sure to play around with this, customize what reason you want / don't want. Try to make a list of locations perhaps like this:
    Code:java
    1. String[] worlds;

    Could have them grab from a config, or something of the sort...

    Anyways... Hopefully this helped a bit, let me know if you need anymore help I'd be more than happy to!
     
  7. Offline

    Garris0n

    I believe cancelling that event can currently cause memory leaks..
     
  8. Offline

    Wingzzz

    Oh no! That's unfortunate, never gone down that road of cancelling it, but hopefully someone has an alternative... Perhaps another event is out there for us to tamper with... Do you know how/why it causes mem leaks still or if it's a planned fix?
     
  9. Offline

    SoThatsIt

    maybe instead of cancelling just get the mob and kill it and remove drops
     
  10. Offline

    Wingzzz

    That's always viable I guess, just not as clean eh.
     
  11. Offline

    Garris0n

    Last edited by a moderator: Jun 1, 2016
    WiredWingzzz likes this.
  12. Offline

    twinightcreep0

    I had the same problem but Thanks FluffyNarwhals you solved it :D
     
  13. Offline

    Tidilywinkes

    okay what if i want it to do it just in one world but not a plugin just want to make it so mobs dont spawn in a world like a creative world for my server
     
  14. Offline

    MrAwellstein


    /gamerule doMobSpawning false

    This is kinda off topic though, because you asked about a nonplugin question, despite it being about bukkit/minecraft. Also you asked a question on a very old post.
     
  15. Offline

    MinerMovies

    Narwhals, Narwhals, swimming in the ocean, causing a commotion, coz they are so awesome.

    Wait what?
     
  16. Offline

    Puntherline

    Hi! I hope you use Multiverse-Core and Multiverse-Portals.
    1. Multiverse-Core>Worlds.yml
    2. Go to your world and set the mob spawning to true and/or false. ^_^
     
Thread Status:
Not open for further replies.

Share This Page