Skip to content

Commit

Permalink
Add AutoSaver task for Challenges Addon.
Browse files Browse the repository at this point in the history
Remove WorldSave event listener.
  • Loading branch information
BONNe committed Jun 12, 2019
1 parent daeaafd commit fc4f3ca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ public void onEnable() {
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);
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/world/bentobox/challenges/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down Expand Up @@ -369,6 +375,27 @@ public int getTitleShowtime()
}


/**
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ public SaveListener(ChallengesAddon addon) {
}


/**
* 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.
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fc4f3ca

Please sign in to comment.