From 02f57644879163d53be294f76db6787c69945fbf Mon Sep 17 00:00:00 2001 From: BONNe Date: Tue, 3 Sep 2019 21:43:59 +0300 Subject: [PATCH 1/6] Add translation part --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 3303a9d..8f7b42c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,12 @@ Be aware that 0.8.0-SNAPSHOT stores data differently than it is in 0.7.5 and bel If you like this addon but something is missing or is not working as you want, you can always submit an [Issue request](https://github.com/BentoBoxWorld/Challenges/issues) or get a support in Discord [BentoBox ![icon](https://avatars2.githubusercontent.com/u/41555324?s=15&v=4)](https://discord.bentobox.world) +## Translations + +As most of BentoBox projects, Challenges Addon is translatable in any language. Everyone can contribute, and translate some parts of the addon in their language via [GitLocalize](https://gitlocalize.com/repo/2896). +If your language is not in the list, please contact to developers via Discord and it will be added there. +Unfortunately, default challenges come only in English translation. But with version 0.8.0 there will be access to different challenges libraries, where everyone could share their challenges with their translations. More information will come soon. + ## How to use 1. Place the addon jar in the addons folder of the BentoBox plugin From 40e34e799991d534f2892f65ef454b5dd2d5bbd7 Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 4 Sep 2019 09:30:11 +0300 Subject: [PATCH 2/6] Add better challenge sorting in AdminGUI's Now challenges will be sorted by their level order number, their order number, their unique id. All free challenges will always be at the start. --- .../challenges/ChallengesManager.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index f2b65e0..2ad14ba 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -94,6 +94,45 @@ public class ChallengesManager public static final String FREE = ""; + // --------------------------------------------------------------------- + // Section: Comparators + // --------------------------------------------------------------------- + + + /** + * This comparator orders challenges by their level, order and name. + */ + private final Comparator challengeComparator = (o1, o2) -> { + if (o1.getLevel().equals(o2.getLevel())) + { + if (o1.getOrder() == o2.getOrder()) + { + // If orders are equal, sort by unique Id + return o1.getUniqueId().compareToIgnoreCase(o2.getUniqueId()); + } + else + { + // If levels are equal, sort them by order numbers. + return Integer.compare(o1.getOrder(), o2.getOrder()); + } + } + else + { + if (o1.getLevel().isEmpty() || o2.getLevel().isEmpty()) + { + // If exist free level challenge, then it should be at the start. + return Boolean.compare(o2.getLevel().isEmpty(), o1.getLevel().isEmpty()); + } + else + { + // Sort by challenges level order numbers + return Integer.compare(this.getLevel(o1.getLevel()).getOrder(), + this.getLevel(o2.getLevel()).getOrder()); + } + } + }; + + // --------------------------------------------------------------------- // Section: Constructor // --------------------------------------------------------------------- @@ -1385,7 +1424,7 @@ public class ChallengesManager { return this.islandWorldManager.getAddon(world).map(gameMode -> this.challengeCacheData.values().stream(). - sorted(Comparator.comparing(Challenge::getOrder)). + sorted(this.challengeComparator). filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())). map(Challenge::getUniqueId). collect(Collectors.toList())). @@ -1403,7 +1442,7 @@ public class ChallengesManager { return this.islandWorldManager.getAddon(world).map(gameMode -> this.challengeCacheData.values().stream(). - sorted(Comparator.comparing(Challenge::getOrder)). + sorted(this.challengeComparator). filter(challenge -> challenge.matchGameMode(gameMode.getDescription().getName())). collect(Collectors.toList())). orElse(Collections.emptyList()); From fd4a19bcb1fcef76ac58c8d2f3051ad43993d473 Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 4 Sep 2019 09:49:58 +0300 Subject: [PATCH 3/6] Add 1.14 mob types to HeadLib. --- .../java/world/bentobox/challenges/utils/HeadLib.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/utils/HeadLib.java b/src/main/java/world/bentobox/challenges/utils/HeadLib.java index 0e27d48..3dcae81 100644 --- a/src/main/java/world/bentobox/challenges/utils/HeadLib.java +++ b/src/main/java/world/bentobox/challenges/utils/HeadLib.java @@ -96,7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ybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWNiOWYxMzlmOTQ4OWQ4NmU0MTBhMDZkOGNiYzY3MGM4MDI4MTM3NTA4ZTNlNGJlZjYxMmZlMzJlZGQ2MDE5MyJ9fX0="), + TRADER_LLAMA("47dbdab5-105f-42bc-9580-c61cee9231f3", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzA4N2E1NTZkNGZmYTk1ZWNkMjg0NGYzNTBkYzQzZTI1NGU1ZDUzNWZhNTk2ZjU0MGQ3ZTc3ZmE2N2RmNDY5NiJ9fX0="), + WANDERING_TRADER("943947ea-3e1a-4fdc-85e5-f538379f05e9", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWYxMzc5YTgyMjkwZDdhYmUxZWZhYWJiYzcwNzEwZmYyZWMwMmRkMzRhZGUzODZiYzAwYzkzMGM0NjFjZjkzMiJ9fX0="); + // --------------------------------------------------------------------- // Section: Variables From 68e09d69465e9d0b6f955d12a1c45a60b41b18de Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Wed, 4 Sep 2019 17:21:39 +0200 Subject: [PATCH 4/6] Fix typos and make challenge descriptions looking a bit nicer (#177) --- README.md | 2 +- .../challenges/ChallengesImportManager.java | 2 +- .../bentobox/challenges/web/WebManager.java | 2 +- src/main/resources/default.json | 64 +++++++++---------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 8f7b42c..55846d4 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Admins can create their own challenges or import some default challenges, which ## Config.yml -As most of BenotBox addons, config can be edited only when server is stopped. Otherwise all changes will be overwritten by server. +As most of BentoBox addons, config can be edited only when server is stopped. Otherwise all changes will be overwritten by server. The config.yml has the following sections: * **Commands** - ability to enable */challenges* command. This option change is possible only via configuration and requires server restart. diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 11f71a4..1fabf61 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -331,7 +331,7 @@ public class ChallengesImportManager private final class DefaultJSONHandler { /** - * This constructor inits JSON builder that will be used to parese challenges. + * This constructor inits JSON builder that will be used to parse challenges. * @param addon Challenges Adddon */ DefaultJSONHandler(ChallengesAddon addon) diff --git a/src/main/java/world/bentobox/challenges/web/WebManager.java b/src/main/java/world/bentobox/challenges/web/WebManager.java index 4c0b0e9..52059d2 100644 --- a/src/main/java/world/bentobox/challenges/web/WebManager.java +++ b/src/main/java/world/bentobox/challenges/web/WebManager.java @@ -182,7 +182,7 @@ public class WebManager /** - * This method returns all library entries that are downlaoded. + * This method returns all library entries that are downloaded. * @return existing Library entries. */ public List getLibraryEntries() diff --git a/src/main/resources/default.json b/src/main/resources/default.json index 0601c33..93f8b1a 100644 --- a/src/main/resources/default.json +++ b/src/main/resources/default.json @@ -5,7 +5,7 @@ "friendlyName": "Potato farm", "deployed": true, "description": [ - "Create simple potato farm" + "Create a simple potato farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: POTATO\n", "order": 1, @@ -94,7 +94,7 @@ "friendlyName": "Villager Breeder", "deployed": true, "description": [ - "Start to create slave army." + "Start to create a slave army." ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: EMERALD_BLOCK\n", "order": 1, @@ -138,7 +138,7 @@ "friendlyName": "Beetroot farm", "deployed": true, "description": [ - "Create simple beetroot farm" + "Create a simple beetroot farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: BEETROOT\n", "order": 1, @@ -181,7 +181,7 @@ "friendlyName": "Slime farm", "deployed": true, "description": [ - "Create slime farm to get some slime blocks" + "Create a slime farm to get some slime blocks" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: SLIME_BLOCK\n", "order": 1, @@ -204,7 +204,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "Get some nether quartz ore and extra mending book", + "rewardText": "Get some nether quartz ore and an extra mending book", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: ENCHANTED_BOOK\n meta:\n ==: ItemMeta\n meta-type: ENCHANTED\n stored-enchants:\n MENDING: 1\n", "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: NETHER_QUARTZ_ORE\n amount: 16\n" @@ -362,7 +362,7 @@ "friendlyName": "Carrot farm", "deployed": true, "description": [ - "Create simple Carrot farm" + "Create a simple carrot farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: CARROT\n", "order": 1, @@ -441,7 +441,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "There are never too much diamonds", + "rewardText": "There are never too many diamonds", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: DIAMOND_ORE\n amount: 4\n" ], @@ -463,7 +463,7 @@ "friendlyName": "Pumpkin farm", "deployed": true, "description": [ - "Create simple Pumpkin farm" + "Create a simple Pumpkin farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: PUMPKIN\n", "order": 2, @@ -506,7 +506,7 @@ "friendlyName": "Cactus farm", "deployed": true, "description": [ - "Create simple Cactus farm" + "Create a simple cactus farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: CACTUS\n", "order": 2, @@ -549,7 +549,7 @@ "friendlyName": "Egg Collector", "deployed": true, "description": [ - "Create Chicken farm and collect their eggs." + "Create a chicken farm and collect their eggs." ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: EGG\n", "order": 2, @@ -594,7 +594,7 @@ "friendlyName": "Tree farm", "deployed": true, "description": [ - "Create simple tree farm" + "Create a simple tree farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: OAK_SAPLING\n", "order": 2, @@ -682,7 +682,7 @@ "rewardMoney": 0, "rewardCommands": [], "repeatable": true, - "repeatRewardText": "Diamond and some emeralds for your disks", + "repeatRewardText": "A diamond and some emeralds for your disks", "maxTimes": 100, "repeatExperienceReward": 5, "repeatItemReward": [ @@ -698,7 +698,7 @@ "friendlyName": "Sugarcane farm", "deployed": true, "description": [ - "Create simple sugarcane farm" + "Create a simple sugarcane farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: SUGAR_CANE\n", "order": 2, @@ -721,7 +721,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "This sand will allow to increase your farm size.", + "rewardText": "This sand will help you to increase your farm size.", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: SAND\n amount: 16\n" ], @@ -741,7 +741,7 @@ "friendlyName": "Animal farm", "deployed": true, "description": [ - "Create grass field and wait for animals to spawn." + "Create a grass field and wait for animals to spawn." ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: GRASS_BLOCK\n", "order": 2, @@ -790,7 +790,7 @@ "friendlyName": "Mushroom farm", "deployed": true, "description": [ - "Create simple mushroom farm" + "Create a simple mushroom farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: BROWN_MUSHROOM\n", "order": 2, @@ -1002,7 +1002,7 @@ "friendlyName": "Melon farm", "deployed": true, "description": [ - "Create simple Melon farm" + "Create a simple Melon farm" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: MELON\n", "order": 2, @@ -1045,7 +1045,7 @@ "friendlyName": "Mob farm", "deployed": true, "description": [ - "Create dark place and spawn some hostile mobs." + "Create a dark place and spawn some hostile mobs." ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: STONE\n", "order": 2, @@ -1398,7 +1398,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 20, - "rewardText": "Some diamonds and elytra for your efforts.", + "rewardText": "Some diamonds and an elytra for your efforts.", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: DIAMOND_ORE\n amount: 16\n", "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: ELYTRA\n" @@ -1692,7 +1692,7 @@ "friendlyName": "Diamond Age", "deployed": true, "description": [ - "Craft Diamond Tools and Armor" + "Craft diamond tools and armor" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: DIAMOND\n", "order": 4, @@ -1745,7 +1745,7 @@ "friendlyName": "Gold Age", "deployed": true, "description": [ - "Craft Gold Tools and Armor" + "Craft gold tools and armor" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: GOLD_INGOT\n", "order": 4, @@ -1881,7 +1881,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "Exchange your terracotta to shulker box", + "rewardText": "Exchange your terracotta to a shulker box", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: SHULKER_BOX\n" ], @@ -1889,7 +1889,7 @@ "rewardMoney": 0, "rewardCommands": [], "repeatable": true, - "repeatRewardText": "Exchange your terracotta to shulker shell", + "repeatRewardText": "Exchange your terracotta to a shulker shell", "maxTimes": 100, "repeatExperienceReward": 5, "repeatItemReward": [ @@ -1903,7 +1903,7 @@ "friendlyName": "Iron Age", "deployed": true, "description": [ - "Craft Iron Tools and Armor" + "Craft iron tools and armor" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: IRON_INGOT\n", "order": 4, @@ -1956,7 +1956,7 @@ "friendlyName": "Cracked stone bricks", "deployed": true, "description": [ - "Smelt some bricks to get cracked briks." + "Smelt some bricks to get cracked stone bricks." ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: CRACKED_STONE_BRICKS\n", "order": 4, @@ -2001,7 +2001,7 @@ "friendlyName": "Logs Exchange", "deployed": true, "description": [ - "Cut trees and collect some logs" + "Fell trees and collect some logs" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: OAK_LOG\n", "order": 4, @@ -2074,7 +2074,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "Exchaning drops will provide some useful materials.", + "rewardText": "Exchanging drops will provide some useful materials.", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: REDSTONE\n amount: 16\n", "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: IRON_ORE\n amount: 5\n", @@ -2136,7 +2136,7 @@ "takeMoney": false, "requiredIslandLevel": 0, "searchRadius": 10, - "rewardText": "Exchange your glass to shulker box", + "rewardText": "Exchange your glass to a shulker box", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: SHULKER_BOX\n" ], @@ -2144,7 +2144,7 @@ "rewardMoney": 0, "rewardCommands": [], "repeatable": true, - "repeatRewardText": "Exchange your glass to shulker shell", + "repeatRewardText": "Exchange your glass to a shulker shell", "maxTimes": 100, "repeatExperienceReward": 5, "repeatItemReward": [ @@ -2269,7 +2269,7 @@ "takeMoney": false, "requiredIslandLevel": 20, "searchRadius": 10, - "rewardText": "Now you can create nether portal", + "rewardText": "Now you can create a nether portal", "rewardItems": [ "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: OBSIDIAN\n amount: 10\n" ], @@ -2289,7 +2289,7 @@ "friendlyName": "Beaconator", "deployed": true, "description": [ - "Create beacon with iron base" + "Create a beacon with iron base" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: BEACON\n", "order": 6, @@ -2611,7 +2611,7 @@ "friendlyName": "Water Zoo", "deployed": true, "description": [ - "Create water animal zoo" + "Create a water animal zoo" ], "icon": "is:\n ==: org.bukkit.inventory.ItemStack\n v: 1631\n type: BLUE_STAINED_GLASS_PANE\n", "order": 7, From a0ffacf66f137f03f74d2df0a38c0d5a3dda56f3 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 5 Sep 2019 09:09:20 +0300 Subject: [PATCH 5/6] Add GitHubWebAPI4Java shaded pattern. --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 03d6896..87f9045 100644 --- a/pom.xml +++ b/pom.xml @@ -259,6 +259,12 @@ 3.2.1 true + + + io.github.TheBusyBiscuit.GitHubWebAPI4Java + world.bentobox.bentobox.api.github + + From 5f1ea920f5efd5a3d1c4f373a39ef1dc7c988349 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 5 Sep 2019 09:36:53 +0300 Subject: [PATCH 6/6] Add download button in Challenges Libraries panel. Disable access to Library panel if github api is disabled. --- .../challenges/panel/admin/AdminGUI.java | 25 +++++++-- .../panel/admin/ListLibraryGUI.java | 51 +++++++++++++++++++ .../bentobox/challenges/web/WebManager.java | 10 ++++ src/main/resources/locales/en-US.yml | 4 ++ 4 files changed, 87 insertions(+), 3 deletions(-) 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'."