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
What are you trying to save exactly? Also when the server shuts down or crashes all scheduled tasks are shut down.
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
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); }
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.
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)
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
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.
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)
Writing to disk on each block break would lag your server to hell. I would just save when the world saves. There is even an event https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/world/WorldSaveEvent.html If there is a crash the last save is where it will start back up at so any blocks broken since the save before the crash will be back.