Hi guys, i made a restart script: Code:java if (cmd.getName().equalsIgnoreCase("restart2")) { if (sender.hasPermission("tschagg.restarting")) { if (args.length == 0) { countRestart = 10; BukkitTask task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { @Override public void run() { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Say Restart in: " + countRestart + "..."); if (countRestart == 0) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "Say Restart Now!"); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "restart now"); } countRestart--; } }, 20L, 20L); } } } 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!
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 @SuppressWarnings("unused")BukkitTask task =..... 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 plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { .... } But you need it again to cancel your task so: Code:java plugin.getServer().getScheduler().cancelTask(task.getTaskId());