So, the past couple days I've been trying to fix this, but nothing has come out of it. It gets to "PASSED," but then stops there. There's no error showing up either, so I'm not sure what the problem is. Code: Code: public void ingame() { attemptCancel(); Bukkit.getServer().broadcastMessage("PASSED"); task = new BukkitRunnable() { int time = sbT.gameTime; public void run() { Bukkit.getServer().broadcastMessage("RUNNABLE"); time--; for(Player online : PO.getOnlinePlayers()) sbTasks.gameScoreboard(online); Bukkit.getServer().broadcastMessage("SET SCOREBOARD"); ; if(time == 60) { Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.YELLOW + "Only " + ChatColor.WHITE + "1 minute" + ChatColor.YELLOW + " left in the game!"); } else if(time == 0) { Bukkit.getServer().broadcastMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + ">> " + ChatColor.YELLOW + "Time is up! Boom!"); if(OffenseState.isState(OffenseState.BLUE)) { ScoreboardTasks.blueLives = ScoreboardTasks.blueLives -1; if(ScoreboardTasks.blueLives == -1) { end(); } else { next(); } } else if(OffenseState.isState(OffenseState.RED)) { ScoreboardTasks.redLives = ScoreboardTasks.redLives -1; if(ScoreboardTasks.redLives == -1) { end(); } else { next(); } } attemptCancel(); ScoreboardTasks.gameTime = 120; } } }.runTaskTimer(Main.getInstance(),20L,20L); } By the way, task is equal to BukkitTask & attemptCancel just cancels the current task if there is one. Thanks in advance.
My guess is Main.getInstance() returns null. But I cannot be sure since you haven't posted enough context. It's just a wild guess, as you can imagine.
I would say the same. Or the attemptCancel class who, somehow, fires right after the runnable is lauched....
@Rocoty This is fired after the game has started, which is also a runnable. With that, Main.getInstance() wouldn't return null as the previous runnable used it. @Webbeh That would probably be my last guess...
@WesJD -> a runnable requires a static Plugin instance. If you're getting something else than the Plugin instance itself, no wonder it doesn't work.
http://jd.bukkit.org/rb/apidocs/org...lugin.Plugin, java.lang.Runnable, long, long) I don't see anything in the documentation about it needing a static instance. It just needs an instance, which would be best by using OOP style programming which Java is an OOP language. http://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html @WesJD Comment out your attemptCancel() method and see if it changes the output of the code.
Sorry, wrong term. It uses the reference to the actual plugin. It isn't static, but has to represent the class extending JavaPlugin. And updating that over time is useless in all the cases I could imagine.
@WesJD Not sure if you got my hint. This is not enough context for us to be able to properly help you. Please post more of your code.
@Rocoty Code: private static Main plugin; public void onEnable() { plugin = this; //snip } public void onDisable() { plugin = null; //snip } public static Plugin getInstance() { return plugin; }
@WesJD I'll try to be specific then. Post the part that calls ingame() (preferably the entire class). Post the entire class that contains ingame(). Do not leave out potentially significant pieces of code without telling us why you so desperately don't want to show it to us.
On line 46 you call next(), which calls ingame(), which starts the task. On line 47, right after the call to next(), you cancel the task before it has had a chance to start running.
@WesJD See if you can remember to post all relevant code next time . Just the method in question is rarely enough.