Hi, I seem to be having an error getting my AsyncRepeatingTask to work. The goal of the task to to be a countdown 10... 9.... 8.... etc.... and when it reaches 0 its teleports the two players in the game to the arena. Code: Code: getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){ int count = 10; Player p; @Override public void run(){ if(!player1.isEmpty() && !player2.isEmpty()){ for(Player online: Bukkit.getOnlinePlayers()){ String pName = online.getName(); if(player1.contains(pName) || player2.contains(pName)){ p.sendMessage(ChatColor.GREEN + "Game Starting in "+count+ " Seconds"); } count--; if(count == 0){ for(String player : plugin.player1){ p = Bukkit.getPlayer(player); p.teleport(plugin.spawn1); } for(String player2 : plugin.player2){ p = Bukkit.getPlayer(player2); p.teleport(plugin.spawn2); } } } } } }, 0L, 20L); Error: Code: 2013-01-21 12:22:51 [SEVERE] Exception in thread "pool-1-thread-20" 2013-01-21 12:22:51 [SEVERE] org.apache.commons.lang.UnhandledException: Plugin Boxing v0.1 generated an exception while executing task 3 at org.bukkit.craftbukkit.v1_4_6.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at me.crushh87.boxing.boxing$2.run(boxing.java:91) at org.bukkit.craftbukkit.v1_4_6.scheduler.CraftTask.run(CraftTask.java:53) at org.bukkit.craftbukkit.v1_4_6.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53) ... 3 more Line 91 is p.sendMessage(ChatColor.GREEN + "Game Starting in "+count+ " Seconds"); I'm not sure how to fix this error any help would be greatly appreciated.
dont use a depreced methode without knowing what it did before it was depreted and what it can create
scheduleAsyncRepeatingTask is depraced because most people thinks it schedules a sync task, instead of a async task, a asynctask is runn on another thread, so it may get in throuble if you access variables from your other class that are not designt for this, a main rule is to keep using single threaded things until you know how to properly handle it
Fixed New code for anyone who also has this problem: Code: int task1 = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ int count = 10; Player p; @Override public void run(){ if(!player1.isEmpty() && !player2.isEmpty()){ for(String player : player1){ p = Bukkit.getPlayer(player); p.sendMessage(ChatColor.GREEN + "Game Starting in " + ChatColor.GOLD +count+ ChatColor.GREEN + " seconds"); } for(String player3 : player2){ p = Bukkit.getPlayer(player3); p.sendMessage(ChatColor.GREEN + "Game Starting in " + ChatColor.GOLD +count+ ChatColor.GREEN + " seconds"); } count--; if(count == 0){ for(String player : player1){ p = Bukkit.getPlayer(player); p.teleport(spawn1); } for(String player3 : player2){ p = Bukkit.getPlayer(player3); p.teleport(spawn2); } } } } }, 0L, 20L); Bukkit.getScheduler().cancelTask(task1);