[Help]Need delay

Discussion in 'Plugin Development' started by dajako, Aug 14, 2013.

Thread Status:
Not open for further replies.
  1. Code:
        @EventHandler
        public void spawnerblock(BlockPlaceEvent event){
            Material block = event.getBlock().getType();
            Player player = event.getPlayer();
            World world = player.getWorld();
            Location location = event.getBlock().getLocation();
            for (Material spawnzombie : spawner) {
                if(spawnzombie == block) {
                    do {
                    world.spawnEntity(location, EntityType.ZOMBIE);
                    //need delay here
                    } while(true);
                   
    }
    Tried Thread.sleep(), etc but it doesn't seem to work!

    How can I add delay?
     
  2. Offline

    Chinwe

    Use runnables:
    Code:
        new BukkitRunnable()
            {
                int count = 10;
                public void run()
                {
                    // Spawn zombie
                    count--;
                    if (count == 0)
                        cancel();
                }
            }.runTaskTimer(plugin, delay, interval-between-spawnings);
    Using do/while loops for delays don't work, and Thread.sleep() will sleep the main thread, causing the whole server to freeze up and players to be disconnected :oops:
     
  3. dajako Lol! NEVER use Thread.sleep();!
     
    dajako likes this.
  4. Ok, I think I understand how to use it. I'll give it a try.
    Thanks :)

    Ah, may sounds nooby but I have no idea where I'd but this. Do I have to chance the event or what?

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

Share This Page