Skip to content

Commit

Permalink
Improve addon reload method.
Browse files Browse the repository at this point in the history
Now it will call also manager.reload() that clears cache and resets database links.
Improve ReloadCommand. Now it will be able to reload both ways (soft way that clears only cache, and hard way that reassigns database connection) with reload command.
  • Loading branch information
BONNe committed May 1, 2019
1 parent 93da0c7 commit f0b156d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 97 deletions.
6 changes: 4 additions & 2 deletions src/main/java/world/bentobox/challenges/ChallengesAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ public void onEnable() {
@Override
public void onReload()
{
if (this.hooked) {
this.challengesManager.save();
super.onReload();

if (this.hooked)
{
this.loadSettings();
this.challengesManager.reload();
this.getLogger().info("Challenges addon reloaded.");
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public void load()
{
this.challengeCacheData.clear();
this.levelCacheData.clear();

if (!this.playerCacheData.isEmpty())
{
// store player data before cleaning.
this.savePlayersData();
}

this.playerCacheData.clear();

this.addon.getLogger().info("Loading challenges...");
Expand All @@ -143,6 +150,12 @@ public void load()
*/
public void reload()
{
if (!this.playerCacheData.isEmpty())
{
// store player data before cleaning.
this.savePlayersData();
}

this.addon.getLogger().info("Reloading challenges...");

this.challengeDatabase = new Database<>(addon, Challenge.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,65 @@
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;

public class ReloadChallenges extends CompositeCommand {

private ChallengesManager manager;

/**
* This class allows to reload challenges addon.
*/
public class ReloadChallenges extends CompositeCommand
{
/**
* Admin command to complete user challenges
* Admin command to reloads challenges addon.
* @param parent
*/
public ReloadChallenges(Addon addon, CompositeCommand parent) {
public ReloadChallenges(Addon addon, CompositeCommand parent)
{
super(addon, parent, "reload");
this.manager = ((ChallengesAddon) getAddon()).getChallengesManager();
}


/**
* {@inheritDoc}
*/
@Override
public void setup() {
public void setup()
{
this.setPermission("admin.challenges");
this.setParametersHelp("challenges.commands.admin.reload.parameters");
this.setDescription("challenges.commands.admin.reload.description");
manager = ((ChallengesAddon)getAddon()).getChallengesManager();
}


/**
* {@inheritDoc}
*/
@Override
public boolean execute(User user, String label, List<String> args) {
if (!args.isEmpty()) {
// Show help
showHelp(this, user);
public boolean execute(User user, String label, List<String> args)
{
if (args.isEmpty())
{
this.manager.load();
user.sendMessage("general.success");
return true;
}
else if (args.get(0).equalsIgnoreCase("hard"))
{
this.manager.reload();
user.sendMessage("general.success");
return true;
}
else
{
this.showHelp(this, user);
return false;
}
manager.load();
user.sendMessage("general.success");
return true;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------


private ChallengesManager manager;
}

This file was deleted.

0 comments on commit f0b156d

Please sign in to comment.