Skip to content

Commit

Permalink
Async & Config updated
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanOff committed Feb 16, 2021
1 parent eb51427 commit 0d0c4b6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
40 changes: 37 additions & 3 deletions com/gaetan/staffpin/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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;
}
}
10 changes: 8 additions & 2 deletions com/gaetan/staffpin/data/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ 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));
}

/**
* Method to load the pin from the config and cache-it
* 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));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion com/gaetan/staffpin/runnable/MoveRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: StaffPin
author: Gaetan_Off
version: 0.8-SNAPSHOT
version: 0.9-SNAPSHOT
main: com.gaetan.staffpin.StaffPlugin

0 comments on commit 0d0c4b6

Please sign in to comment.