How to run a command after a certain amount of time.

Discussion in 'Plugin Development' started by WindedDragon, Feb 23, 2012.

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

    WindedDragon

    I'm new to Java/Bukkit plugin making. I was wondering how you could have the server issue a command after a certain amount of time. Basically what I want to do is be able to give a user Creative Mode for the amount of time that I set in-game, and after that amount of time has run it's course it will put the user back in Survival.
     
  2. Take my plugin InTime :)

    HomerBond005
     
  3. Offline

    WindedDragon

    That's kind of what I would like, but not exactly. What I want to be able to do is be able to issue a command that put's the specified player in creative mode for the set amount of time.
     
  4. Offline

    stelar7

    Code:
    public void onCommand(CommandSender cs, Command c, String label, Strig[] args) {
        if (cs instanceof Player && args.lenght > 1) {
            final Player p = (Player)cs;
            p.setGameMode(GameMode.CREATIVE); // unsure about this line...
            int timedelay = Integer.parseInt(args[0]);
            Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                public void run() {
                    p.setGameMode(GameMode.SURVIVAL); // unsure about this line...
                }
            }, timedelay*20L);
        return true;
        }
    return false;
    }
    use it with
    Code:
    /thecommanduwant thetimedelay
     
  5. Offline

    WindedDragon

    Oh wow, thanks a lot.
     
Thread Status:
Not open for further replies.

Share This Page