Schedular Teleportation

Discussion in 'Plugin Development' started by thatdubstepgamer, Aug 16, 2013.

Thread Status:
Not open for further replies.
  1. I need it when the server starts up it starts a 1min clock then teleports players to coordinates this is what i have to far.
    Code:java
    1. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    2. {
    3. @Override
    4. public void run()
    5. {
    6. int timeuntiltele = 10;
    7. if (timeuntiltele >=1)
    8. {
    9. player.sendMessage(timeuntiltele + " until Teleportation");
    10. timeuntiltele=timeuntiltele-1;
    11. }
    12. else
    13. {
    14. player.sendMessage("TELEPORT!");
    15. player.teleport....
    16. timeuntiltele = 10;
    17. }
    18. }
    19. },timeuntiltele*20L);
     
  2. thatdubstepgamer The timeuntiltele var should be outside the task because everytime the task repeats you are setting it back to 10.
     
  3. Offline

    KevoSoftworks

    thatdubstepgamer

    Code:java
    1. public class Main extends JavaPlugin{
    2. int tpTime = 10;
    3.  
    4. public void onEnable(){
    5. //do stuffs
    6. }
    7.  
    8. public void onDisable(){
    9. //do stuffs
    10. }
    11.  
    12. public void teleport(Player player){
    13. int id = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    14. public void run(){
    15. if (tpTime % 1 == 0 && tpTime != 0){
    16. player.sendMessage(tpTime + " seconds until Teleportation");
    17. tpTime--;
    18. } else if(tpTime == 0){
    19. player.sendMessage("TELEPORT!");
    20. //teleport player
    21. tpTime = 10;
    22. this.getServer().getScheduler().cancelTask(id);
    23. }
    24. }
    25. },0,20L);
    26. }
    27. }
     
  4. Whats the id
     
  5. Offline

    KevoSoftworks

    thatdubstepgamer

    The id is the scheduler task, so we have the ability to cancel the task again
     
Thread Status:
Not open for further replies.

Share This Page