mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2025-03-02 11:31:09 +01:00
Add download button in Challenges Libraries panel.
Disable access to Library panel if github api is disabled.
This commit is contained in:
parent
a0ffacf66f
commit
5f1ea920f5
@ -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;
|
||||
|
@ -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<String> 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.
|
||||
|
@ -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
|
||||
// ---------------------------------------------------------------------
|
||||
|
@ -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'."
|
||||
|
Loading…
Reference in New Issue
Block a user