Skip to content

Commit

Permalink
Implement ability to Fix player Data from GUI.
Browse files Browse the repository at this point in the history
Fix issue when accept and decline buttons were with wrong names.
  • Loading branch information
BONNe committed Feb 13, 2019
1 parent 7f399b2 commit 78fa459
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1077,4 +1077,39 @@ public void deleteChallengeLevel(ChallengeLevel challengeLevel)
this.levelDatabase.deleteObject(challengeLevel);
}
}


// ---------------------------------------------------------------------
// Section: Fix world duplication issue.
// ---------------------------------------------------------------------


/**
* This allows to fix player data issue when world name is duplicated.
* @deprecated Will be removed in 0.7.0 release.
*/
@Deprecated
public void fixCorruptedPlayerData()
{
this.playersDatabase.loadObjects().forEach(playerData -> {
Map<String, Integer> completed = playerData.getChallengeStatus();
Map<String, Long> timeStamps = playerData.getChallengesTimestamp();

new ArrayList<>(completed.keySet()).forEach(challenge -> {
String correctName = challenge.replaceFirst("(\\w+)(?=(\\1))", "");
if (!correctName.isEmpty() && !correctName.equals(challenge))
{
completed.put(correctName, completed.get(challenge));
timeStamps.put(correctName, timeStamps.get(challenge));

completed.remove(challenge);
timeStamps.remove(challenge);
this.addon.log("ChallengeString was modified " + challenge + " was changed to " + correctName);
}
});

this.playerCacheData.put(UUID.fromString(playerData.getUniqueId()), playerData);
this.savePlayer(UUID.fromString(playerData.getUniqueId()));
});
}
}
27 changes: 27 additions & 0 deletions src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.CommonGUI;
import world.bentobox.challenges.panel.util.ConfirmationGUI;
import world.bentobox.challenges.utils.GuiUtils;


Expand Down Expand Up @@ -55,6 +56,7 @@ private enum Button
DELETE_LEVEL,
IMPORT_CHALLENGES,
BACKWARD_CHALLENGES,
BACKWARD_PLAYER_DATA,
EDIT_SETTINGS
}

Expand Down Expand Up @@ -111,6 +113,7 @@ public void build()
// Import Challenges
panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES));
panelBuilder.item(24, this.createButton(Button.BACKWARD_CHALLENGES));
panelBuilder.item(33, this.createButton(Button.BACKWARD_PLAYER_DATA));

// Edit Addon Settings
panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS));
Expand Down Expand Up @@ -388,6 +391,30 @@ private PanelItem createButton(Button button)

break;
}
case BACKWARD_PLAYER_DATA:
{
permissionSuffix = IMPORT;

name = this.user.getTranslation("challenges.gui.buttons.admin.backward-player");
description = this.user.getTranslation("challenges.gui.descriptions.admin.backward-player");
icon = new ItemStack(Material.HOPPER);
clickHandler = (panel, user, clickType, slot) -> {

new ConfirmationGUI(this.user, status -> {
if (status)
{
this.addon.getChallengesManager().fixCorruptedPlayerData();
}

this.build();
});

return true;
};
glow = false;

break;
}
case EDIT_SETTINGS:
{
permissionSuffix = SETTINGS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void build()
private PanelItem getButton(boolean returnValue)
{
return new PanelItemBuilder().
name(this.user.getTranslation("challenges.gui.admin.buttons." + (returnValue ? "accept" : "cancel"))).
icon(returnValue ? Material.GRAY_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE).
name(this.user.getTranslation("challenges.gui.buttons.admin." + (returnValue ? "accept" : "cancel"))).
icon(returnValue ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE).
clickHandler((panel, user1, clickType, i) -> {
this.consumer.accept(returnValue);
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ challenges:
delete-level: 'Remove level'
import: 'Import ASkyblock Challenges'
backward: 'Import 0.3.0 Challenges'
backward-player: 'Fix 0.3.0 PlayerData'
settings: 'Edit Settings'
properties: 'Properties'
requirements: 'Requirements'
Expand Down Expand Up @@ -157,6 +158,7 @@ challenges:
delete-challenge: 'Allows remove any Challenge.'
delete-level: 'Allows remove any Level.'
backward: 'Allows to import challenges from 0.3.0 and below addon version.'
backward-player: 'Allows to fix corrupted PlayerData from 0.3.0 version.|&2USE ONLY IF NECESSARY|&2MAY NOT WORK IN ALL SITUATIONS'
settings: 'Allows to change addon settings.'
properties: 'Allows to change general properties'
requirements: 'Allows to manage requirements'
Expand Down Expand Up @@ -305,4 +307,4 @@ challenges:
import-no-file: '&cCould not find challenges.yml file to import!'
no-load: '&cError: Could not load challenges.yml. [message]'
load-error: '&cError: Cannot load [value].'
version: 5
version: 6

0 comments on commit 78fa459

Please sign in to comment.