mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-22 18:46:39 +01:00
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:
parent
a9abe32dbe
commit
94c3fd9fa4
@ -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
|
||||
|
@ -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";
|
||||
|
@ -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;
|
||||
|
@ -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!'
|
||||
|
@ -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!'
|
||||
|
Loading…
Reference in New Issue
Block a user