Skip to content

Commit

Permalink
Improve Wipe Button behaviour.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BONNe committed Sep 5, 2019
1 parent ecbb8ef commit a5022be
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,17 @@ private void addPlayerData(@NonNull String uniqueID)

/**
* 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();
}
}


Expand Down Expand Up @@ -527,7 +532,7 @@ private void wipeChallenges()
* 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();

Expand Down
89 changes: 86 additions & 3 deletions src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ private enum Button
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
}

Expand Down Expand Up @@ -113,6 +127,9 @@ public void build()
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));
Expand All @@ -137,7 +154,7 @@ public void build()
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);

Expand Down Expand Up @@ -431,11 +448,77 @@ private PanelItem createButton(Button button)
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();
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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]'
Expand Down Expand Up @@ -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]!'
Expand Down

0 comments on commit a5022be

Please sign in to comment.