Help with scheduleSyncDelayedTask

Discussion in 'Spigot Plugin Development' started by AppleMonJeans, Jan 14, 2018.

  1. What errors are you getting?
  2. 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 ! :D
    • Agree Agree x 1
  3. 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.
    • Agree Agree x 1
  4. Now when i place a lavabucket it just crashes the server.
    • Optimistic Optimistic x 1
  5. Use this:
    Code (Text):
    private static /* Your Main class */ main;

    public void onEnable(){
    main = this;

    public static Main getMain(){
    return main;

    Code (Text):

    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 {
        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)) {
                while (loc.getBlock().getType().equals(Material.AIR) && loc.getY() > 0) {
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.getMain(), new Runnable() {
                        public void run() {
                    }, 600L);

    Good luck!
  6. Probably due to the infinite while loop
  7. I don't think the while is infinite. He decreases the y and changes the block type
  8. 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
    at org.fusesource.jansi.internal.WindowsSupport.setConsoleMode(WindowsSu
    at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.setConsoleMode(Wind
    [14:08:50 ERROR]: Stack:
    at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.restore(WindowsTerm
    > at org.bukkit.craftbukkit.libs.jline.TerminalSupport$
    [14:08:50 ERROR]: java.lang.Thread.sleep(Native Method)
    at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks.runTasks(Shu
    > at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks.access$000(S
    at org.bukkit.craftbukkit.libs.jline.internal.ShutdownHooks$
    [14:08:50 ERROR]: net.minecraft.server.v1_8_R3.DedicatedServer$1.r

    [14:08:50 ERROR]: ------------------------------
    [14:08:50 ERROR]: Current Thread: Snooper Timer
    [14:08:50 ERROR]: PID: 12 | Suspended: false | Native: false | State: TIME
    [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]: 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
    [14:08:50 ERROR]: Stack:
    [14:08:50 ERROR]: ------------------------------
  9. Did you call Thread.sleep or Thread.join anywhere?
  10. No, i do not think so.
  11. This server stopped from by tasks
    Why do not you prevent lava
  12. It cannot find the .class file for org.fusesource.jansi.internal.Kernel32
  13. 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.
  14. So how would you recommend fixing this then?
  15. like I said, use a repeating task rather than a while loop :p
    • Agree Agree x 1