Improve Wipe Button behaviour.

Add 2 new buttons:
- User wipe - deletes all challenges addon player data.
- challenges wipe - deletes only challenges and levels.

By clicking on challenges wipe with right click, it will switch to compelte wipe, and via versa.
This commit is contained in:
BONNe 2019-09-05 12:19:05 +03:00 committed by BONNe1704
parent ecbb8ef1f2
commit a5022bea7a
3 changed files with 103 additions and 6 deletions

View File

@ -488,12 +488,17 @@ public class ChallengesManager
/**
* This method removes all challenges addon data from Database.
* @param complete Remove also user data.
*/
public void wipeDatabase()
public void wipeDatabase(boolean complete)
{
this.wipeLevels();
this.wipeChallenges();
this.wipePlayers();
if (complete)
{
this.wipePlayers();
}
}
@ -527,7 +532,7 @@ public class ChallengesManager
* This method collects all data from players database and removes them.
* Also clears players cache data.
*/
private void wipePlayers()
public void wipePlayers()
{
List<ChallengesPlayerData> playerDataList = this.playersDatabase.loadObjects();

View File

@ -68,7 +68,21 @@ public class AdminGUI extends CommonGUI
EDIT_SETTINGS,
DEFAULT_IMPORT_CHALLENGES,
DEFAULT_EXPORT_CHALLENGES,
/**
* Allows to remove whole database
*/
COMPLETE_WIPE,
/**
* Allows to remove only challenges and levels
*/
CHALLENGE_WIPE,
/**
* Allows to remove only players data
*/
USER_WIPE,
/**
* Allows to access Web Library
*/
LIBRARY
}
@ -113,6 +127,9 @@ public class AdminGUI extends CommonGUI
panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES));
panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES));
// Add All Player Data removal.
panelBuilder.item(28, this.createButton(Button.USER_WIPE));
// Add Challenges
panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE));
panelBuilder.item(13, this.createButton(Button.ADD_LEVEL));
@ -137,7 +154,7 @@ public class AdminGUI extends CommonGUI
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(34, this.createButton(Button.CHALLENGE_WIPE));
panelBuilder.item(44, this.returnButton);
@ -431,11 +448,77 @@ public class AdminGUI extends CommonGUI
description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe");
icon = new ItemStack(Material.TNT);
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
{
panel.getInventory().setItem(slot, this.createButton(Button.CHALLENGE_WIPE).getItem());
}
else
{
new ConfirmationGUI(this.user, value -> {
if (value)
{
this.addon.getChallengesManager().wipeDatabase(false);
this.user.sendMessage("challenges.messages.admin.complete-wipe");
}
this.build();
});
}
return true;
};
glow = true;
break;
}
case CHALLENGE_WIPE:
{
permissionSuffix = WIPE;
name = this.user.getTranslation("challenges.gui.buttons.admin.challenge-wipe");
description = this.user.getTranslation("challenges.gui.descriptions.admin.challenge-wipe");
icon = new ItemStack(Material.TNT);
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
{
panel.getInventory().setItem(slot, this.createButton(Button.COMPLETE_WIPE).getItem());
}
else
{
new ConfirmationGUI(this.user, value -> {
if (value)
{
this.addon.getChallengesManager().wipeDatabase(false);
this.user.sendMessage("challenges.messages.admin.challenge-wipe");
}
this.build();
});
}
return true;
};
glow = false;
break;
}
case USER_WIPE:
{
permissionSuffix = WIPE;
name = this.user.getTranslation("challenges.gui.buttons.admin.players-wipe");
description = this.user.getTranslation("challenges.gui.descriptions.admin.players-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.addon.getChallengesManager().wipePlayers();
this.user.sendMessage("challenges.messages.admin.players-wipe");
}
this.build();

View File

@ -167,6 +167,8 @@ challenges:
default-import: 'Import Default Challenges'
default-export: 'Export Existing Challenges'
complete-wipe: 'Wipe Addon Databases'
challenge-wipe: 'Wipe Challenges Database'
players-wipe: 'Wipe User Database'
library: 'Web Library'
download: 'Download Libraries'
@ -271,6 +273,9 @@ 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!'
challenge-wipe: 'Allows to completely clear challenges and their level databases!'
players-wipe: 'Allows to completely clear player database!'
library: 'Opens GUI that shows all available public Challenges Libraries.'
library-author: 'by &e[author]'
@ -401,6 +406,10 @@ challenges:
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!'
challenge-wipe: '&cHope you have backups, as you just empty Challenges and their levels from databases!'
players-wipe: '&cHope you have backups, as you just empty player completed challenges from databases!'
completed: '&2You completed challenge [name] for [player]!'
already-completed: '&2This challenge was already completed!'
reset: '&2You reset challenge [name] for [player]!'