Solved Pass variable to BukkitTask?

Discussion in 'Plugin Development' started by ZephireNZ, Mar 22, 2013.

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

    ZephireNZ

    So I want a Delayed task to run a method with a player as a passed variable. But annoyingly that variable can't be accessed as it's from within a method itself.
    Code:java
    1. public void startFly(Player player) {
    2. player.setAllowFlight(true);
    3. player.sendMessage(ChatColor.GOLD + "You can now fly for " + time + " seconds!");
    4. BukkitTask id = new BukkitRunnable() { //Wait for 'timeLong' before stopping fly
    5.  
    6. @Override
    7. public void run() {
    8. stopFly(/* GET PLAYER HERE FROM ABOVE */); //Get player assigned to this thread
    9. }
    10. }.runTaskLater(this, (long) timeLong);
    11. }


    How would I be able to pass variable "player" from the method onto the Task?
     
  2. Offline

    newboyhun

    JAVA IS OOP

    Think in class man...

    Create a new class implement runnable (bukkitrunnable, idk how bukkittask works...).

    Example:
    Code:
    TestTask task = new TestTask(playername);
    getServer().getScheduler().scheduleAsyncRepeatingTask(this, task, 0L, 20L)
     
  3. Offline

    ZephireNZ

    So with a bit of your help, and a little ingenuity, I got it working :) Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page