diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 75b98ae..9a7c54f 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -431,6 +431,60 @@ public class ChallengesManager } } + // --------------------------------------------------------------------- + // 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 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 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 playerDataList = this.playersDatabase.loadObjects(); + + playerDataList.forEach(playerData -> this.playersDatabase.deleteID(playerData.getUniqueId())); + this.playerCacheData.clear(); + } + // --------------------------------------------------------------------- // Section: Saving methods diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 31ccae9..484640a 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -110,6 +110,8 @@ public abstract class CommonGUI protected static final String DELETE = "delete"; + protected static final String WIPE = "wipe"; + protected static final String EDIT = "edit"; protected static final String ADD = "add"; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index dc9e410..d8b504e 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -58,7 +58,8 @@ public class AdminGUI extends CommonGUI IMPORT_CHALLENGES, EDIT_SETTINGS, DEFAULT_IMPORT_CHALLENGES, - DEFAULT_EXPORT_CHALLENGES + DEFAULT_EXPORT_CHALLENGES, + COMPLETE_WIPE } @@ -120,6 +121,9 @@ public class AdminGUI extends CommonGUI // 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(); @@ -439,6 +443,30 @@ public class AdminGUI extends CommonGUI 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; diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index ca2748c..f03991c 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -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' @@ -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' @@ -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!' diff --git a/src/main/resources/locales/lv-LV.yml b/src/main/resources/locales/lv-LV.yml index 8c0faaf..3415b39 100755 --- a/src/main/resources/locales/lv-LV.yml +++ b/src/main/resources/locales/lv-LV.yml @@ -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' @@ -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' @@ -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!'