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 4447657..64d665b 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -3,7 +3,11 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.conversations.*; +import org.bukkit.conversations.Conversation; +import org.bukkit.conversations.ConversationContext; +import org.bukkit.conversations.ConversationFactory; +import org.bukkit.conversations.Prompt; +import org.bukkit.conversations.ValidatingPrompt; import org.bukkit.inventory.ItemStack; import org.eclipse.jdt.annotation.NonNull; @@ -20,6 +24,7 @@ import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; import world.bentobox.challenges.utils.GuiUtils; import world.bentobox.challenges.utils.Utils; +import world.bentobox.challenges.web.WebManager; /** @@ -448,9 +453,23 @@ public class AdminGUI extends CommonGUI name = this.user.getTranslation("challenges.gui.buttons.admin.library"); description = this.user.getTranslation("challenges.gui.descriptions.admin.library"); - icon = new ItemStack(Material.COBWEB); + + if (WebManager.isEnabled()) + { + icon = new ItemStack(Material.COBWEB); + } + else + { + description += "|" + this.user.getTranslation("challenges.gui.descriptions.admin.download-disabled"); + icon = new ItemStack(Material.STRUCTURE_VOID); + } + clickHandler = (panel, user, clickType, slot) -> { - ListLibraryGUI.open(this); + if (WebManager.isEnabled()) + { + ListLibraryGUI.open(this); + } + return true; }; glow = false; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLibraryGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLibraryGUI.java index 77f4867..4ee9d11 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLibraryGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLibraryGUI.java @@ -2,6 +2,7 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.World; import java.util.ArrayList; import java.util.List; @@ -115,12 +116,58 @@ public class ListLibraryGUI extends CommonGUI panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); } + panelBuilder.item(4, this.createDownloadNow()); panelBuilder.item(44, this.returnButton); panelBuilder.build(); } + /** + * This creates download now button, that can skip waiting for automatic request. + * @return PanelItem button that allows to manually download libraries. + */ + private PanelItem createDownloadNow() + { + List description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.download")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.clearCache ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + PanelItemBuilder itemBuilder = new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.buttons.admin.download")). + description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). + icon(Material.HOPPER). + glow(this.clearCache); + + itemBuilder.clickHandler((panel, user1, clickType, slot) -> + { + if (clickType.isRightClick()) + { + this.clearCache = !this.clearCache; + panel.getInventory().setItem(slot, this.createDownloadNow().getItem()); + } + else + { + this.addon.getWebManager().requestCatalogGitHubData(false); + + // add some delay to rebuilding gui. + this.addon.getPlugin().getServer().getScheduler().runTaskLaterAsynchronously( + this.addon.getPlugin(), + this::build, + 100L); + } + + return true; + }); + + return itemBuilder.build(); + } + + /** * This method creates button for given library entry. * @param libraryEntry LibraryEntry which button must be created. @@ -199,6 +246,10 @@ public class ListLibraryGUI extends CommonGUI // Section: Instance Variables // --------------------------------------------------------------------- + /** + * Indicates if download now button should trigger cache clearing. + */ + private boolean clearCache; /** * This variable will protect against spam-click. diff --git a/src/main/java/world/bentobox/challenges/web/WebManager.java b/src/main/java/world/bentobox/challenges/web/WebManager.java index 4c0b0e9..7ff6e74 100644 --- a/src/main/java/world/bentobox/challenges/web/WebManager.java +++ b/src/main/java/world/bentobox/challenges/web/WebManager.java @@ -194,6 +194,16 @@ public class WebManager } + /** + * This static method returns if GitHub data downloader is enabled or not. + * @return {@code true} if data downloader is enabled, {@code false} - otherwise. + */ + public static boolean isEnabled() + { + return BentoBox.getInstance().getWebManager().getGitHub().isPresent(); + } + + // --------------------------------------------------------------------- // Section: Variables // --------------------------------------------------------------------- diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 095be9e..7be7962 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -169,6 +169,7 @@ challenges: complete-wipe: 'Wipe Addon Databases' library: 'Web Library' + download: 'Download Libraries' next: 'Next' previous: 'Previous' return: 'Return' @@ -277,6 +278,9 @@ challenges: library-lang: '&aLanguage: [lang]' library-gamemode: '&aPrimary for [gamemode]' + download: 'Allows manually update available challenges libraries. |Right click to enable cache clearing.' + download-disabled: 'GitHub data downloader is disabled in BentoBox. Without it, you cannot use Libraries!' + lore: level: "Level string. | Represents translation 'challenges.gui.challenge-description.level'." status: "Status string. | Represents translation 'challenges.gui.challenge-description.completed'."