Schedulers in a custom method give an error "this.(..)"

Discussion in 'Plugin Development' started by megasaad44, Jun 5, 2014.

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

    megasaad44

    I'm making my custom method that has a bunch of consecutive schedulers that run a delayed task each. The problem is I'm using the "this" at the begging of each scheduler, and so, the method is showing red lines under "this" for some reason. Why and how can i solve this?

    Code:java
    1. public static void muffin(Player player) {
    2. player.getInventory().clear();
    3. player.teleport(
    4. new Location(Bukkit.getWorld("diverge"), 0, 72, 0));
    5.  
    6. player.getInventory().setHeldItemSlot(4);
    7.  
    8. this.getServer().getScheduler()
    9. .scheduleSyncDelayedTask(this, new Runnable() {
    10. @Override
    11. public void run() {
    12.  
    13. -massive snip-
    14.  
    15. }
    16. }, 20L);
    17. this.getServer().getScheduler()
    18. .scheduleSyncDelayedTask(this, new Runnable() {
    19. @Override
    20. public void run() {
    21.  
    22. -snip-
    23.  
    24. }
    25. }, 25L);
    26. this.getServer().getScheduler()
    27. .scheduleSyncDelayedTask(this, new Runnable() {
    28. @Override
    29. public void run() {
    30.  
    31. -snip-
    32.  
    33. }
    34. }, 30L);
    35.  
    36. }
     
  2. Offline

    Arkel

    You're referring to the instance of an object from within a static method. You should consider whether the method really needs to be static (probably not), if it does, you should use Bukkit.getServer(), if it doesn't remove the static keyword from the function declaration.
     
Thread Status:
Not open for further replies.

Share This Page