-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2531 command button panel #2535
Changes from 2 commits
58690f2
e0a3f48
4c396a1
f9c34e5
13756cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,7 +346,7 @@ private CompositeCommand getCommandFromArgs(String[] args) { | |
* | ||
* @return IslandsManager | ||
*/ | ||
protected IslandsManager getIslands() { | ||
public IslandsManager getIslands() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More useful |
||
return plugin.getIslands(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,9 +362,8 @@ ItemSlot nextItemSlot() { | |
* this button is present. | ||
* | ||
* @return Map that links button type to amount in the gui. | ||
* @deprecated Use {@link #amount(String)} instead. | ||
* Use {@link #amount(String)} instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be deprecated, and is used a lot. |
||
*/ | ||
@Deprecated | ||
public Map<String, Integer> amountMap() { | ||
return this.parentPanel.typeSlotMap; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,15 +90,29 @@ public static PanelTemplateRecord readTemplatePanel(@NonNull String panelName, @ | |
} | ||
|
||
File file = new File(panelLocation, templateName.endsWith(YML) ? templateName : templateName + YML); | ||
|
||
String absolutePath = file.getAbsolutePath(); | ||
if (!file.exists()) | ||
{ | ||
BentoBox.getInstance().logError(file.getAbsolutePath() + " does not exist for panel template"); | ||
// Return as file does not exist. | ||
return null; | ||
// Try to get it from the JAR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's not there, then try and get it from the Jar. |
||
|
||
String keyword = "panels/"; | ||
|
||
// Find the index of the keyword "panels/" | ||
int index = absolutePath.indexOf(keyword); | ||
|
||
// If the keyword is found, extract the substring starting from that index | ||
if (index != -1) { | ||
BentoBox.getInstance().saveResource(absolutePath.substring(index), false); | ||
file = new File(panelLocation, templateName.endsWith(YML) ? templateName : templateName + YML); | ||
} else { | ||
BentoBox.getInstance().logError(file.getAbsolutePath() + " does not exist for panel template"); | ||
// Return as file does not exist. | ||
return null; | ||
} | ||
|
||
} | ||
|
||
final String panelKey = file.getAbsolutePath() + ":" + panelName; | ||
final String panelKey = absolutePath + ":" + panelName; | ||
|
||
// Check if panel is already crafted. | ||
if (TemplateReader.loadedPanels.containsKey(panelKey)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package world.bentobox.bentobox.panels.customizable; | ||
|
||
import java.io.File; | ||
|
||
import org.bukkit.event.inventory.ClickType; | ||
|
||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.addons.GameModeAddon; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.panels.PanelItem; | ||
import world.bentobox.bentobox.api.panels.TemplatedPanel; | ||
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord; | ||
import world.bentobox.bentobox.api.user.User; | ||
|
||
/** | ||
* @author tastybento | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for use by all customizable panels. |
||
*/ | ||
public abstract class AbstractPanel { | ||
|
||
// --------------------------------------------------------------------- | ||
// Section: Constants | ||
// --------------------------------------------------------------------- | ||
|
||
/** | ||
* This constant is used for button to indicate that it is Language type. | ||
*/ | ||
public static final String LOCALE = "LOCALE"; | ||
|
||
/** | ||
* This constant is used for button to indicate that it is previous page type. | ||
*/ | ||
public static final String PREVIOUS = "PREVIOUS"; | ||
|
||
/** | ||
* This constant is used for button to indicate that it is next page type. | ||
*/ | ||
public static final String NEXT = "NEXT"; | ||
|
||
/** | ||
* This constant is used for indicating that pages should contain numbering. | ||
*/ | ||
public static final String INDEXING = "indexing"; | ||
|
||
/** | ||
* This constant stores value for SELECT action that is used in panels. | ||
*/ | ||
public static final String SELECT_ACTION = "SELECT"; | ||
|
||
/** | ||
* This constant stores value for COMMANDS action that is used in panels. | ||
*/ | ||
public static final String COMMANDS_ACTION = "COMMANDS"; | ||
|
||
/** | ||
* This constant stores value for AUTHORS label that is used in panels. | ||
*/ | ||
public static final String AUTHORS = "[authors]"; | ||
|
||
/** | ||
* This constant stores value for SELECTED label that is used in panels. | ||
*/ | ||
public static final String SELECTED = "[selected]"; | ||
|
||
/** | ||
* This variable allows to access plugin object. | ||
*/ | ||
final BentoBox plugin; | ||
|
||
/** | ||
* This variable stores main command that was triggered. | ||
*/ | ||
final CompositeCommand command; | ||
|
||
/** | ||
* This variable holds user who opens panel. Without it panel cannot be opened. | ||
*/ | ||
final User user; | ||
|
||
/** | ||
* This variable holds world where panel is opened. Without it panel cannot be opened. | ||
*/ | ||
String mainLabel; | ||
|
||
/** | ||
* This variable holds current pageIndex for multi-page island choosing. | ||
*/ | ||
int pageIndex; | ||
|
||
public AbstractPanel(CompositeCommand command, User user) { | ||
plugin = command.getPlugin(); | ||
this.command = command; | ||
this.user = user; | ||
this.pageIndex = 0; // Start with the first page by default | ||
} | ||
|
||
// Abstract methods for creating next and previous buttons | ||
protected abstract PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot); | ||
|
||
protected abstract PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot); | ||
|
||
// Abstract build method to allow each panel to define its own layout | ||
protected abstract void build(); | ||
|
||
// Default method for pagination, can be overridden by subclasses if needed | ||
protected boolean hasNextPage(int elementListSize, int itemsPerPage) { | ||
return (pageIndex + 1) * itemsPerPage < elementListSize; | ||
} | ||
|
||
protected boolean hasPreviousPage() { | ||
return pageIndex > 0; | ||
} | ||
|
||
// Method to handle the click event on next/previous buttons | ||
protected boolean handlePageChange(ItemTemplateRecord.ActionRecords action, ClickType clickType, | ||
String actionType) { | ||
if ((clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN) | ||
&& actionType.equalsIgnoreCase(action.actionType())) { | ||
if (actionType.equalsIgnoreCase("NEXT")) { | ||
this.pageIndex++; | ||
} else if (actionType.equalsIgnoreCase("PREVIOUS")) { | ||
this.pageIndex--; | ||
} | ||
build(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* This method returns if panel with the requested name is located in GameModeAddon folder. | ||
* @param addon GameModeAddon that need to be checked. | ||
* @param name Name of the panel. | ||
* @return {@code true} if panel exists, {@code false} otherwise. | ||
*/ | ||
protected boolean doesCustomPanelExists(GameModeAddon addon, String name) { | ||
return addon.getDataFolder().exists() && new File(addon.getDataFolder(), "panels").exists() | ||
&& new File(addon.getDataFolder(), "panels" + File.separator + name + ".yml").exists(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer required because they are loaded from Jar if not found