From ca5cfcc8417ca4b7384d4b76a010383810527d6f Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 1 May 2019 23:14:41 +0300 Subject: [PATCH] Add button in Challenges admin GUI that allows to import default challenges. --- .../bentobox/challenges/panel/CommonGUI.java | 4 ++ .../challenges/panel/admin/AdminGUI.java | 56 ++++++++++++++++++- src/main/resources/locales/en-US.yml | 4 ++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 3b534f8..2f2a2ae 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -102,6 +102,10 @@ public abstract class CommonGUI 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"; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 5558652..08d43d8 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -56,7 +56,9 @@ public class AdminGUI extends CommonGUI DELETE_CHALLENGE, DELETE_LEVEL, IMPORT_CHALLENGES, - EDIT_SETTINGS + EDIT_SETTINGS, + DEFAULT_IMPORT_CHALLENGES, + DEFAULT_EXPORT_CHALLENGES } @@ -111,6 +113,9 @@ public class AdminGUI extends CommonGUI // 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)); @@ -371,6 +376,55 @@ public class AdminGUI extends CommonGUI 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; diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 215568c..337f452 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -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' @@ -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'