crash server cancel regen

Discussion in 'Spigot Plugin Development' started by Marshmalah, Jan 7, 2020.

  1. Hello I would like to know if there is a solution to save this when the server shuts down or crashes
    Code (Java):
    Bukkit.getScheduler().runTaskLater(plugin, () -> e.getBlock().setType(Material.YELLOW_GLAZED_TERRACOTTA), 20 * 2);
    Thanks for watching ;)
     
  2. What are you trying to save exactly?

    Also when the server shuts down or crashes all scheduled tasks are shut down.
     
  3. I would like to know how to continue to execute this action when the server is off and when it reopens continue to perform the task
     
  4. Hello / Salut l'ami,

    Store the Blocks into a List and update them into the onDisable method:
    Code (Java):
    // Add your blocks in the list
    private final List<Block> blocks = new ArrayList<>();

    @Override
    public void onDisable() {
        blocks.forEach(b -> b.setType(Material.YELLOW_GLAZED_TERRACOTTA);
    }
     
  5. SteelPhoenix

    Moderator

    Nothing gets called after a server crash - the next tick never happens.
     
  6. Code (Text):
    Bukkit.getScheduler().runTaskLater(plugin, () -> e.getBlock().setType(Material.YELLOW_GLAZED_TERRACOTTA), 20 * 2);
    This code returns BukkitTask so you could keep track of your tasks save a list of some sort onDisable and start them up again. In the event of a crash onDisable will not be called though.
     
  7. If the server shuts down you can save whatever you have to in the onDisable method.

    If the server crashes there is no guarantee whatsoever that anything can be executed, so you'll need to store stuff on disk before the crash (Probably when you begin the task)
     
  8. How I can put
    Code (Java):
    Bukkit.getScheduler().runTaskLater(plugin, () -> e.getBlock().setType(Material.YELLOW_GLAZED_TERRACOTTA), 20 * 30);
    in a list and then save it and relaunch it once the server reopen I don't quite understand
     
  9. I think the easiest way would be to create a class implementing ConfigurationSerializable which includes information about the block coordinates and the Material you want to change. Then you would create such objects simultaneously with your line of code you posted and save them into a list.

    If the server shuts down (please remember: crashes are NOT covered) you would then save the list into a yml file and on server start you load the file and proceed from there.
     
    • Like Like x 1
  10. Your answer gave me an idea that would work even if the server crashes,
    how i can get the position and the id of a block when it is broken in a yml file (it writes in this file when a player breaks a block)
     
    • Winner Winner x 1