Start A Timer From Another Timer

Discussion in 'Plugin Development' started by SuperboyDev, Oct 4, 2015.

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

    SuperboyDev

    Hi. I'm making a UHC plugin where there is a countdown that teleports the players around the area, then disables pvp for ten minutes. (I solved the countdown part in the previous thread) What I want to do is once the countdown has ended, it should start another timer which disables pvp for ten minutes. I don't know how to start another timer once the first timer has ended. This is my code:
    My event handler
    Code:
    @EventHandler
        public void onPlayerInteract(EntityDamageByEntityEvent event) {
            if (event.getDamager() instanceof Player) {
                if(ticks==0) {
                task2 = new BukkitRunnable() {
                    @Override
                    public void run() {
                        ticks2--;
                        Bukkit.broadcastMessage("Test: " + ticks2);;
                        if(ticks2==0) {
                            task2.cancel();
                            }
                        }
                    };
                    task2.runTaskTimer(this, 0L, 20L);
                }
               
            }
        }
    My countdown.
    Code:
    ticks = 10;
            task = new BukkitRunnable() {
               
                @Override
                public void run() {
                    if (Bukkit.getServer().getOnlinePlayers().size() == getConfig().getInt("playerstillgamestarts")) {
                        ticks--;
                        if (ticks == 0) {
                            Random random = new Random();
                            int x = random.nextInt(2000) - 1000;
                            int z = random.nextInt(2000) - 1000;
    
                            Location teleportLocation = new Location(player
                                    .getWorld(), x, (player.getWorld()
                                    .getHighestBlockYAt(0, 0) + 1), z);
                            player.teleport(teleportLocation);
                            player.getInventory().addItem(is);
                            task.cancel();
                        }
                        Bukkit.broadcastMessage(ChatColor.GREEN + "Time Left: "
                                + ChatColor.WHITE + ticks);
                    }
                }
            };
            task.runTaskTimer(this, 0L, 20L);
    I can't figure out how to start the 2nd timer once the first ends.
     
  2. Code:
    new BukkitRunnable() {
    int countDown = 10;
    
    public void run() {
    //Do your countdown stuff.
    
    if (countDown <= 0) {
    cancel();
    //Set pvp to false
    
    new Bukkit Runnable() {
    public void run() {
    //Set pvp to true
    }
    }.runTaskLater(this, 0, 20 * 60 * 10);
    }
    
    }
    }.runTaskTimer(this, 0, 20);
     
    DoggyCodeâ„¢ likes this.
Thread Status:
Not open for further replies.

Share This Page