diff --git a/com/gaetan/staffpin/config/ConfigManager.java b/com/gaetan/staffpin/config/ConfigManager.java index fbe2437..66308b2 100644 --- a/com/gaetan/staffpin/config/ConfigManager.java +++ b/com/gaetan/staffpin/config/ConfigManager.java @@ -19,7 +19,7 @@ public final class ConfigManager { /** * Cache for the config */ - private boolean cacheEnabled; + private boolean cacheEnabled, asyncLoad, asyncSave, asyncMove; /** * Constructor for the ConfigManager class. @@ -49,6 +49,10 @@ private void load() { this.cacheEnabled = config.getBoolean("cache.enabled"); + this.asyncLoad = config.getBoolean("async.load_pin"); + this.asyncSave = config.getBoolean("async.save_pin"); + this.asyncMove = config.getBoolean("async.move"); + this.pinPermission = config.getString("permission.pin"); this.pinUsage = Message.tl(config.getString("lang.pin.usage")); } @@ -135,11 +139,41 @@ public String getCacheLogin() { } /** - * Getter to get the cache statut. + * Getter to get the cache status. * - * @return The the cache statut. + * @return The the cache status. */ public boolean isCacheEnabled() { return this.cacheEnabled; } + + + /** + * Getter to get the async load status. + * + * @return The the async load status. + */ + public boolean isAsyncLoad() { + return this.asyncLoad; + } + + + /** + * Getter to get the async save status. + * + * @return The the async save status. + */ + public boolean isAsyncSave() { + return this.asyncSave; + } + + + /** + * Getter to get the async move status. + * + * @return The the async move status. + */ + public boolean isAsyncMove() { + return this.asyncMove; + } } \ No newline at end of file diff --git a/com/gaetan/staffpin/data/PlayerData.java b/com/gaetan/staffpin/data/PlayerData.java index 37d0437..7acf50b 100644 --- a/com/gaetan/staffpin/data/PlayerData.java +++ b/com/gaetan/staffpin/data/PlayerData.java @@ -74,7 +74,10 @@ public PlayerData(final Player player, final StaffPlugin staffPlugin, final Conf * Note: This is executed in async */ private void save() { - this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new SavePlayerConfig(this.staffPlugin, this)); + if (this.configManager.isAsyncSave()) + this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new SavePlayerConfig(this.staffPlugin, this)); + else + this.staffPlugin.getServer().getScheduler().runTask(this.staffPlugin, new SavePlayerConfig(this.staffPlugin, this)); } /** @@ -82,7 +85,10 @@ private void save() { * Note: This is executed in async */ public void load() { - this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new LoadPlayerConfig(this.staffPlugin, this, this.configManager)); + if (this.configManager.isAsyncLoad()) + this.staffPlugin.getServer().getScheduler().runTaskAsynchronously(this.staffPlugin, new LoadPlayerConfig(this.staffPlugin, this, this.configManager)); + else + this.staffPlugin.getServer().getScheduler().runTask(this.staffPlugin, new LoadPlayerConfig(this.staffPlugin, this, this.configManager)); } /** diff --git a/com/gaetan/staffpin/runnable/MoveRunnable.java b/com/gaetan/staffpin/runnable/MoveRunnable.java index 0c19e4a..c45a2c1 100644 --- a/com/gaetan/staffpin/runnable/MoveRunnable.java +++ b/com/gaetan/staffpin/runnable/MoveRunnable.java @@ -28,7 +28,11 @@ public final class MoveRunnable extends BukkitRunnable { public MoveRunnable(final StaffPlugin staffPlugin, final ConfigManager configManager) { this.staffPlugin = staffPlugin; this.configManager = configManager; - this.runTaskTimerAsynchronously(this.staffPlugin, 0L, 40L); + + if (configManager.isAsyncMove()) + this.runTaskTimerAsynchronously(this.staffPlugin, 0L, 40L); + else + this.runTaskTimer(this.staffPlugin, 0L, 40L); } /** diff --git a/config.yml b/config.yml index d6ac85f..2c16f08 100644 --- a/config.yml +++ b/config.yml @@ -17,6 +17,13 @@ lang: cache: enabled: true +#Activates the following operations asynchronously +#This can really optimize the server +async: + load_pin: true + save_pin: true + move: true + #The permission to have access to the pin permission: pin: "pin.use" diff --git a/plugin.yml b/plugin.yml index 74a10cb..4d6708c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,4 +1,4 @@ name: StaffPin author: Gaetan_Off -version: 0.8-SNAPSHOT +version: 0.9-SNAPSHOT main: com.gaetan.staffpin.StaffPlugin