Skip to content

Commit

Permalink
Add button in Challenges admin GUI that allows to import default chal…
Browse files Browse the repository at this point in the history
…lenges.
  • Loading branch information
BONNe committed May 1, 2019
1 parent b24f7eb commit ca5cfcc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/world/bentobox/challenges/panel/CommonGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ protected enum CommonButtons

protected static final String IMPORT = "import";

protected static final String DEFAULT = "default";

protected static final String GENERATE = "generate";

protected static final String SETTINGS = "settings";

protected static final String DELETE = "delete";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private enum Button
DELETE_CHALLENGE,
DELETE_LEVEL,
IMPORT_CHALLENGES,
EDIT_SETTINGS
EDIT_SETTINGS,
DEFAULT_IMPORT_CHALLENGES,
DEFAULT_EXPORT_CHALLENGES
}


Expand Down Expand Up @@ -111,6 +113,9 @@ public void build()

// Import Challenges
panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES));
panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES));
// Not added as I do not think admins should use it. It still will be able via command.
// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES));

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

break;
}
case DEFAULT_IMPORT_CHALLENGES:
{
permissionSuffix = DEFAULT;

name = this.user.getTranslation("challenges.gui.buttons.admin.default-import");
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-import");
icon = new ItemStack(Material.HOPPER);
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
{
this.overwriteMode = !this.overwriteMode;
this.build();
}
else
{
// Run import command.
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + IMPORT);
}
return true;
};
glow = false;

break;
}
case DEFAULT_EXPORT_CHALLENGES:
{
permissionSuffix = DEFAULT;

name = this.user.getTranslation("challenges.gui.buttons.admin.default-export");
description = this.user.getTranslation("challenges.gui.descriptions.admin.default-export");
icon = new ItemStack(Material.HOPPER);
clickHandler = (panel, user, clickType, slot) -> {
if (clickType.isRightClick())
{
this.overwriteMode = !this.overwriteMode;
this.build();
}
else
{
// Run import command.
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + GENERATE +
(this.overwriteMode ? " overwrite" : ""));
}
return true;
};
glow = this.overwriteMode;

break;
}
case EDIT_SETTINGS:
{
permissionSuffix = SETTINGS;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ challenges:
input-mode: 'Switch input mode'
title-enable: 'Completion title'
title-showtime: 'Title Show Time'
default-import: 'Import Default Challenges'
default-export: 'Export Existing Challenges'
next: 'Next'
previous: 'Previous'
return: 'Return'
Expand Down Expand Up @@ -246,6 +248,8 @@ challenges:
input-mode: 'Switch between chat and anvil input modes.'
title-enable: 'Allows to enable/disable title message that will be showed when player complete challenge.'
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.'
current-value: '|&6Current value: [value].'
enabled: 'Active'
disabled: 'Disabled'
Expand Down

0 comments on commit ca5cfcc

Please sign in to comment.