Solved Complete a task on shutdown

Discussion in 'Plugin Development' started by hellobrad100, Dec 19, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Hello everyone,

    I have made a plugin that replaces crops on a timer, Eg: I destroy sugar cane, and then after 200 ticks it will return.

    However, during the period of that 200 ticks, if the server restarts / closes down, the sugar cane will not return.

    I am just wondering if there is a way to complete the task when the server disables and so it skips the 200 tick delay?

    Here is my code:
                if(e.getBlock().getType() == Material.SUGAR_CANE_BLOCK)
                    int time = pl.getConfig().getInt("SugarTime");
                    if(underb == Material.SAND)
                        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable()
                            public void run()
                                Block b = e.getBlock();
                        }, time);
  2. Offline


    @hellobrad100 Create a List which saves the blocks that need to be recreated. Then onDisable iterate through them and recreate the sugar cane.
    VG.Developments likes this.
  3. Offline


    @hellobrad100 You could try putting the code to cancel the timer and reset the block in your onDisable().

    Edit: @Skionz beat me :p
  4. Offline


    @Skionz @wesley27
    Hi again, I've been giving this a go for a couple of days now, and can't seem to get it. I've created the array list, added it when the event happens, removed it when the timer ends, I just have no clue how to implement it onDisable().

    Could you give me some guidance please? Or just something to get me started?

    - Brad
  5. Offline


    @hellobrad100 Iterate through it in the onDisable method and rebuild the sugar cane.
  6. Offline


    @Skionz Aha, that worked.

    Thanks again dude. :)
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page