Add Complete Wipe button in AdminGUI that allows to remove all Challenges 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.
This commit is contained in:
BONNe1704 2019-06-05 12:30:48 +03:00
parent a9abe32dbe
commit 94c3fd9fa4
5 changed files with 91 additions and 1 deletions

View File

@ -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<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 // Section: Saving methods

View File

@ -110,6 +110,8 @@ public abstract class CommonGUI
protected static final String DELETE = "delete"; protected static final String DELETE = "delete";
protected static final String WIPE = "wipe";
protected static final String EDIT = "edit"; protected static final String EDIT = "edit";
protected static final String ADD = "add"; protected static final String ADD = "add";

View File

@ -58,7 +58,8 @@ public class AdminGUI extends CommonGUI
IMPORT_CHALLENGES, IMPORT_CHALLENGES,
EDIT_SETTINGS, EDIT_SETTINGS,
DEFAULT_IMPORT_CHALLENGES, DEFAULT_IMPORT_CHALLENGES,
DEFAULT_EXPORT_CHALLENGES DEFAULT_EXPORT_CHALLENGES,
COMPLETE_WIPE
} }
@ -120,6 +121,9 @@ public class AdminGUI extends CommonGUI
// Edit Addon Settings // Edit Addon Settings
panelBuilder.item(16, this.createButton(Button.EDIT_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.item(44, this.returnButton);
panelBuilder.build(); panelBuilder.build();
@ -439,6 +443,30 @@ public class AdminGUI extends CommonGUI
break; 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: default:
// This should never happen. // This should never happen.
return null; return null;

View File

@ -148,6 +148,7 @@ challenges:
title-showtime: 'Title Show Time' title-showtime: 'Title Show Time'
default-import: 'Import Default Challenges' default-import: 'Import Default Challenges'
default-export: 'Export Existing Challenges' default-export: 'Export Existing Challenges'
complete-wipe: 'Wipe Addon Databases'
next: 'Next' next: 'Next'
previous: 'Previous' previous: 'Previous'
return: 'Return' return: 'Return'
@ -243,6 +244,7 @@ challenges:
title-showtime: 'Allows to modify how long title message will be visible for player.' title-showtime: 'Allows to modify how long title message will be visible for player.'
default-import: 'Allows to import default challenges.' default-import: 'Allows to import default challenges.'
default-export: 'Allows to export existing challenges into defaults.json file.' 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].' current-value: '|&6Current value: [value].'
enabled: 'Active' enabled: 'Active'
disabled: 'Disabled' disabled: 'Disabled'
@ -309,6 +311,7 @@ challenges:
hit-things: 'Hit things to add them to the list of things required. Right click when done.' 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' you-added: 'You added one [thing] to the challenge'
challenge-created: '[challenge]&r created!' 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-completed-challenge: '&2You completed the [value] &r&2challenge!'
you-repeated-challenge: '&2You repeated 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!' you-repeated-challenge-multiple: '&2You repeated the [value] &r&2challenge [count] times!'

View File

@ -148,6 +148,7 @@ challenges:
title-showtime: 'Virsrakta rādīšanas ilgums' title-showtime: 'Virsrakta rādīšanas ilgums'
default-import: 'Importēt standarta Uzdevumus' default-import: 'Importēt standarta Uzdevumus'
default-export: 'Exportēt esošos Uzdevumus' default-export: 'Exportēt esošos Uzdevumus'
complete-wipe: 'Iztīrīt datubāzes'
next: 'Nākošā' next: 'Nākošā'
previous: 'Iepriekšējā' previous: 'Iepriekšējā'
return: 'Atgriezties' return: 'Atgriezties'
@ -243,6 +244,7 @@ challenges:
title-showtime: 'Ļauj mainīt cik ilgi virsraksts spēlētājam būs redzams.' 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-import: 'Ļauj ielādēt sākotnējos uzdevumus.'
default-export: 'Ļauj eksportēt uzdevumus uz defaults.json failu.' 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].' current-value: '|&6Šī brīža vērtība: [value].'
enabled: 'Aktīvs' enabled: 'Aktīvs'
disabled: 'Neaktīvs' disabled: 'Neaktīvs'
@ -307,6 +309,7 @@ challenges:
messages: messages:
admin: admin:
challenge-created: '[challenge]&r izveidots!' 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-completed-challenge: '&2Tu izpildīji [value] &r&2uzdevumu!'
you-repeated-challenge: '&2Tu atkārtoji [value] &r&2uzdevumu!' you-repeated-challenge: '&2Tu atkārtoji [value] &r&2uzdevumu!'
you-repeated-challenge-multiple: '&2Tu atkārtoji [value] &r&2uzdevumu [count] reizes!' you-repeated-challenge-multiple: '&2Tu atkārtoji [value] &r&2uzdevumu [count] reizes!'