Help with Scheduler

Discussion in 'Plugin Development' started by Windwaker, Jun 8, 2011.

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

    Windwaker

    Heya,
    So I have recently discovered that it is not possible with Bukkit at the moment to teleport something onPlayerRespawn, unfortunately I need to do this to teleport a player to the Nether onPlayerRespawn event. So I came to the conclusion that I need a scheduler, unfortunately, I don't know how to use one...

    So basically I ask you how might I set a delayed task of say... 60 ticks onPlayerRespawn and then run this logic:

    Code:
        public void onPlayerRespawn(PlayerRespawnEvent event){
            Player player = event.getPlayer();
            if(plugin.playerBanish.containsKey(player)){
                player.teleport(plugin.getServer().getWorld("world_nether").getSpawnLocation());
     
  2. Offline

    DrBowe

    I second this notion. I, too, am clueless about the scheduler, and would like to learn how to use it.
    :)
     
  3. @DrBoweNur
    @Walker Crouse
    Alright you guys, I've dug up some code for you :D I'll add this to the tutorial soon.

    First you need to create 2 variables, one for your taskID and one for the class which the Scheduler will run on, in this case my scheduler will run inside the class 'RegiosScheduler'
    PHP:
    private RegiosScheduler schedule null;
    private 
    int taskId 0;
    Then you will need to start the scheduler thread, you do this inside of the on enable function:
    PHP:
    this.schedule = new RegiosScheduler(this);
    taskId this.getServer().getScheduler().scheduleAsyncDelayedTask(thisthis.schedule21L 1);
    //This will schedule an event every second I believe so you can change the 21L * 1 to increase the time.
            
    Then finally you will will need to make your class implement runnable and add the function the scheduler will run, it'll always be run();
    PHP:
    public class RegiosScheduler implements Runnable{

        @
    Override
        
    public void run(){

        }

    }
     
  4. Offline

    Windwaker

    @Adamki11s

    Sorry, I already figured this out and I should have marked it my bad :( And if you wanted to know I did it this way...

    PHP:
        }
        public 
    void onPlayerRespawn(PlayerRespawnEvent event){
            final 
    Player player event.getPlayer();
            final 
    Plugin thrPlugin plugin;
            if(
    plugin.playerBanish.containsKey(player)){
                
    plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            public 
    void run() {
                
    player.teleport(thrPlugin.getServer().getWorld("world_nether").getSpawnLocation());
            }
        }, 
    40L);


            }
        }
    }
    Without creating a new class
     
  5. Offline

    DrBowe

    He may have figured it out, but me being the lazy person that I am, still appreciate it :)
     
Thread Status:
Not open for further replies.

Share This Page