I cant figure out how to use scheduleSyncDelayedTask, my ide is give me tons of errors. Code: https://pastebin.com/gyqxRxSP
All in your code is good, but, on line with code Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {, there can't be this, there must be instance of class in your project which extends Java Plugin. So, in your class which extends JavaPlugin, add this: Code (Text): public static Plugin instance = null; And in your onEnable() instance = this;, in onDisable() instance = null;, and now replace this by YourClass.instance. You won't now get any error. I hope, that was helpful !
Also, side-note: scheduleSyncDelayedTask() is deprecated in the later versions of spigot, you can use the method runTaskLater() or runTaskLaterAsynchronously() from the same getScheduler() method.
Use this: Spoiler: Main class Code (Text): private static /* Your Main class */ main; public void onEnable(){ main = this; } public static Main getMain(){ return main; } Spoiler: genbucketCobblestone Class Code (Text): package me.splurgies.genbuckets.events; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerBucketEmptyEvent; public class genbucketCobblestone implements Listener { @EventHandler public void onGenbucketPlace(PlayerBucketEmptyEvent e) { Player p = e.getPlayer(); Block b = e.getBlockClicked().getRelative(e.getBlockFace()); Location loc = b.getLocation(); if (p.getInventory().getItemInHand().getType().equals(Material.LAVA_BUCKET)) { e.setCancelled(true); b.setType(Material.COBBLESTONE); loc.subtract(0,1,0); while (loc.getBlock().getType().equals(Material.AIR) && loc.getY() > 0) { Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getMain(), new Runnable() { public void run() { loc.getBlock().setType(Material.COBBLESTONE); loc.subtract(0,1,0); } }, 600L); } } } } /CODE][/SPOILER] Good luck!
I don't get any errors but it still crashes the server. Server Errors: [WARN] Task failed >java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi .internal.Kernel32 at org.fusesource.jansi.internal.WindowsSupport.setConsoleMode(WindowsSu pport.java:60) at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.setConsoleMode(Wind owsTerminal.java:208) [14:08:50 ERROR]: Stack: at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.restore(WindowsTerm inal.java:95) > at org.bukkit.craftbukkit.libs.jline.TerminalSupport$1.run(TerminalSuppo rt.java:52) [14:08:50 ERROR]: java.lang.Thread.sleep(Native Method) at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks.runTasks(Shu tdownHooks.java:66) > at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks.access$000(S hutdownHooks.java:22) at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks$1.run(Shutdo wnHooks.java:47) [14:08:50 ERROR]: net.minecraft.server.v1_8_R3.DedicatedServer$1.r un(DedicatedServer.java:54) [14:08:50 ERROR]: ------------------------------ [14:08:50 ERROR]: Current Thread: Snooper Timer [14:08:50 ERROR]: PID: 12 | Suspended: false | Native: false | State: TIME D_WAITING [14:08:50 ERROR]: Stack: [14:08:50 ERROR]: java.lang.Object.wait(Native Method) [14:08:50 ERROR]: java.util.TimerThread.mainLoop(Unknown Source) [14:08:50 ERROR]: java.util.TimerThread.run(Unknown Source) [14:08:50 ERROR]: ------------------------------ [14:08:50 ERROR]: Current Thread: Attach Listener [14:08:50 ERROR]: PID: 5 | Suspended: false | Native: false | State: RUNNA BLE [14:08:50 ERROR]: Stack: [14:08:50 ERROR]: ------------------------------
you shouldn't use static as an access modifier, let alone have a public mutable field. Instead, use the constructor to pass the Plugin instance to another class. @x7aSv same goes for you. The Location is never modified fast enough, the server would freeze for 3 seconds per Y level. That is, if the timer would even run. It runs on the same thread as the while loop, so it wouldn't even get scheduled. Now, this doesn't mean OP should go to asynchronous tasks. Aside that it's completely overkill and not even a guaranteed fix (since Location isn't thread safe), there are much better solutions, like simply using a repeating task (runTaskTimer). And the jansi error is not related to this all, let alone important.