Tasks...

Discussion in 'Plugin Development' started by tschagg, Jan 12, 2013.

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

    tschagg

    Hi guys, i made a restart script:

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("restart2")) {
    2. if (sender.hasPermission("tschagg.restarting")) {
    3. if (args.length == 0) {
    4. countRestart = 10;
    5. BukkitTask task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
    6. @Override
    7. public void run() {
    8. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Say Restart in: " + countRestart + "...");
    9.  
    10. if (countRestart == 0) {
    11. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Say Restart Now!");
    12. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "restart now");
    13. }
    14. countRestart--;
    15. }
    16. }, 20L, 20L);
    17. }
    18. }
    19. }


    2 Questions to it:
    Eclipse say me that the task named "task" is unused, how i fix that?
    how i cancel this task? i tried task.cancel() but this give me an eclipse error too.

    thanks!
     
  2. Offline

    camyono

    If there is a message in eclipse saying xyz variable is unused it means that you never use this variable again in your source code.

    If you have unused variables, check your code whether you really need them. Otherwise you can use the Annotation: SuppressWarnings

    Code:java
    1.  
    2. @SuppressWarnings("unused")
    3. BukkitTask task =.....
    4.  


    See also: http://docs.oracle.com/javase/7/docs/api/java/lang/SuppressWarnings.html

    If you would not use the variable "task" anymore you also can write it like this:

    Code:java
    1.  
    2. plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { .... }
    3.  


    But you need it again to cancel your task so:

    Code:java
    1.  
    2. plugin.getServer().getScheduler().cancelTask(task.getTaskId());
    3.  
     
  3. Offline

    fireblast709

    what is the eclipse 'error' when you try to invoke the cancel() method
     
Thread Status:
Not open for further replies.

Share This Page