Add AutoSaver task for Challenges Addon.

Remove WorldSave event listener.
This commit is contained in:
BONNe 2019-06-12 22:56:52 +03:00
parent daeaafd0b2
commit fc4f3ca0b6
4 changed files with 41 additions and 15 deletions

View File

@ -220,6 +220,16 @@ public class ChallengesAddon extends Addon {
this.registerRequestHandler(new LevelDataRequestHandler(this));
this.registerRequestHandler(new CompletedChallengesRequestHandler(this));
if (this.settings.getAutoSaveTimer() > 0)
{
this.getPlugin().getServer().getScheduler().runTaskTimerAsynchronously(
this.getPlugin(),
bukkitTask -> ChallengesAddon.this.challengesManager.save(),
this.settings.getAutoSaveTimer() * 60 * 20,
this.settings.getAutoSaveTimer() * 60 * 20
);
}
} else {
this.logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!");
this.setState(State.DISABLED);

View File

@ -155,6 +155,12 @@ public class Settings implements ConfigObject
@ConfigEntry(path = "title.title-showtime")
private int titleShowtime = 70;
@ConfigComment("")
@ConfigComment("Long that represents how frequently (in minutes) challenges addon will save data to database.")
@ConfigComment("If this is set to 0, saving will not happen.")
@ConfigEntry(path = "auto-saver")
private long autoSaveTimer = 30;
@ConfigComment("")
@ConfigComment("This list stores GameModes in which Challenges addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
@ -369,6 +375,27 @@ public class Settings implements ConfigObject
}
/**
* This method returns the autoSaveTimer object.
* @return the autoSaveTimer object.
*/
public long getAutoSaveTimer()
{
return autoSaveTimer;
}
/**
* This method sets the autoSaveTimer object value.
* @param autoSaveTimer the autoSaveTimer object new value.
*
*/
public void setAutoSaveTimer(long autoSaveTimer)
{
this.autoSaveTimer = autoSaveTimer;
}
/**
* This method sets the titleShowtime object value.
* @param titleShowtime the titleShowtime object new value.

View File

@ -22,21 +22,6 @@ public class SaveListener implements Listener
}
/**
* This event listener handles world save event.
* @param e World Save event.
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onWorldSave(WorldSaveEvent e)
{
// Save only for worlds where exist any challenge addon data.
if (this.addon.getChallengesManager().hasAnyChallengeData(e.getWorld()))
{
this.addon.getChallengesManager().save();
}
}
/**
* This event listener handles player kick event.
* If player is kicked, then remove it from player cache data.

View File

@ -109,6 +109,10 @@ title:
# Integer that represents how long title will be visible for player.
title-showtime: 70
#
# Long that represents how frequently (in minutes) challenges addon will save data to database.
# If this is set to 0, saving will not happen.
auto-saver: 30
#
# This list stores GameModes in which Challenges addon should not work.
# To disable addon it is necessary to write its name in new line that starts with -. Example:
# disabled-gamemodes: