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

    hellobrad100

    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:
    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()
                        {
                            @Override
                            public void run()
                            {
                                Block b = e.getBlock();
                                b.setType(Material.SUGAR_CANE_BLOCK);
                            }
                        }, time);
                    }
                }
    Thanks,
    Brad
     
  2. Offline

    Skionz

    @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

    wesley27

    @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

    hellobrad100

    @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?

    Thanks
    - Brad
     
  5. Offline

    Skionz

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

    hellobrad100

    @Skionz Aha, that worked.

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

Share This Page