Skip to content

Commit

Permalink
Add Complete Wipe button in AdminGUI that allows to remove all Challe…
Browse files Browse the repository at this point in the history
…nges Addon data from database.

This request comes from Discord.

It also mention to format DiskDrive to avoid ability to restore database, but it is not implemented yet. Will be implemented in future releases.
  • Loading branch information
BONNe committed Jun 5, 2019
1 parent a9abe32 commit 94c3fd9
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,60 @@ private void addPlayerData(@NonNull String uniqueID)
}
}

// ---------------------------------------------------------------------
// Section: Wipe data
// ---------------------------------------------------------------------


/**
* This method removes all challenges addon data from Database.
*/
public void wipeDatabase()
{
this.wipeLevels();
this.wipeChallenges();
this.wipePlayers();
}


/**
* This method collects all data from levels database and removes them.
* Also clears levels cache data.
*/
private void wipeLevels()
{
List<ChallengeLevel> levelList = this.levelDatabase.loadObjects();

levelList.forEach(level -> this.levelDatabase.deleteID(level.getUniqueId()));
this.levelCacheData.clear();
}


/**
* This method collects all data from challenges database and removes them.
* Also clears challenges cache data.
*/
private void wipeChallenges()
{
List<Challenge> challengeList = this.challengeDatabase.loadObjects();

challengeList.forEach(challenge -> this.challengeDatabase.deleteID(challenge.getUniqueId()));
this.challengeCacheData.clear();
}


/**
* This method collects all data from players database and removes them.
* Also clears players cache data.
*/
private void wipePlayers()
{
List<ChallengesPlayerData> playerDataList = this.playersDatabase.loadObjects();

playerDataList.forEach(playerData -> this.playersDatabase.deleteID(playerData.getUniqueId()));
this.playerCacheData.clear();
}


// ---------------------------------------------------------------------
// Section: Saving methods
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/challenges/panel/CommonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected enum CommonButtons

protected static final String DELETE = "delete";

protected static final String WIPE = "wipe";

protected static final String EDIT = "edit";

protected static final String ADD = "add";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ private enum Button
IMPORT_CHALLENGES,
EDIT_SETTINGS,
DEFAULT_IMPORT_CHALLENGES,
DEFAULT_EXPORT_CHALLENGES
DEFAULT_EXPORT_CHALLENGES,
COMPLETE_WIPE
}


Expand Down Expand Up @@ -120,6 +121,9 @@ public void build()
// Edit Addon Settings
panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS));

// Button that deletes everything from challenges addon
panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE));

panelBuilder.item(44, this.returnButton);

panelBuilder.build();
Expand Down Expand Up @@ -439,6 +443,30 @@ private PanelItem createButton(Button button)

break;
}
case COMPLETE_WIPE:
{
permissionSuffix = WIPE;

name = this.user.getTranslation("challenges.gui.buttons.admin.complete-wipe");
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe");
icon = new ItemStack(Material.TNT);
clickHandler = (panel, user, clickType, slot) -> {
new ConfirmationGUI(this.user, value -> {
if (value)
{
this.addon.getChallengesManager().wipeDatabase();
this.user.sendMessage("challenges.messages.admin.complete-wipe");
}

this.build();
});

return true;
};
glow = false;

break;
}
default:
// This should never happen.
return null;
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ challenges:
title-showtime: 'Title Show Time'
default-import: 'Import Default Challenges'
default-export: 'Export Existing Challenges'
complete-wipe: 'Wipe Addon Databases'
next: 'Next'
previous: 'Previous'
return: 'Return'
Expand Down Expand Up @@ -243,6 +244,7 @@ challenges:
title-showtime: 'Allows to modify how long title message will be visible for player.'
default-import: 'Allows to import default challenges.'
default-export: 'Allows to export existing challenges into defaults.json file.'
complete-wipe: 'Allows to completely clear all challenges addon databases. Includes player data!'
current-value: '|&6Current value: [value].'
enabled: 'Active'
disabled: 'Disabled'
Expand Down Expand Up @@ -309,6 +311,7 @@ challenges:
hit-things: 'Hit things to add them to the list of things required. Right click when done.'
you-added: 'You added one [thing] to the challenge'
challenge-created: '[challenge]&r created!'
complete-wipe: '&cHope you have backups, as you just empty all Challenges Addon databases!'
you-completed-challenge: '&2You completed the [value] &r&2challenge!'
you-repeated-challenge: '&2You repeated the [value] &r&2challenge!'
you-repeated-challenge-multiple: '&2You repeated the [value] &r&2challenge [count] times!'
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/locales/lv-LV.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ challenges:
title-showtime: 'Virsrakta rādīšanas ilgums'
default-import: 'Importēt standarta Uzdevumus'
default-export: 'Exportēt esošos Uzdevumus'
complete-wipe: 'Iztīrīt datubāzes'
next: 'Nākošā'
previous: 'Iepriekšējā'
return: 'Atgriezties'
Expand Down Expand Up @@ -243,6 +244,7 @@ challenges:
title-showtime: 'Ļauj mainīt cik ilgi virsraksts spēlētājam būs redzams.'
default-import: 'Ļauj ielādēt sākotnējos uzdevumus.'
default-export: 'Ļauj eksportēt uzdevumus uz defaults.json failu.'
complete-wipe: 'Ļauj pilnībā iztīrīt papildinājuma datubāzes. Ieskaitot spēlētāju datus!'
current-value: '|&6Šī brīža vērtība: [value].'
enabled: 'Aktīvs'
disabled: 'Neaktīvs'
Expand Down Expand Up @@ -307,6 +309,7 @@ challenges:
messages:
admin:
challenge-created: '[challenge]&r izveidots!'
complete-wipe: '&cCerams, ka tev ir saglabātas rezerves kopijas, jo tu tikko iztīrīji visas šī papildinājuma datubāzes!'
you-completed-challenge: '&2Tu izpildīji [value] &r&2uzdevumu!'
you-repeated-challenge: '&2Tu atkārtoji [value] &r&2uzdevumu!'
you-repeated-challenge-multiple: '&2Tu atkārtoji [value] &r&2uzdevumu [count] reizes!'
Expand Down

0 comments on commit 94c3fd9

Please sign in to comment.