Executing code asynchronously

We can improve the Warper plugin by writing its data to a file asynchronously. This will help keep the main thread of the server running smoothly with no lag.

Take a look at the current save method. We will add the data to a YamlConfiguration file and then write the configuration to the file. This entire method cannot be run asynchronously. Adding the data to the configuration must be done synchronously to ensure that it is not modified while it is being added. However, the save method call on the configuration can be called asynchronously. We will place the entire try/catch block within a new BukkitRunnable class. We will then run it asynchronously as a task. This task will be stored as a static variable in the

Get Building Minecraft Server Modifications - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.