mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-29 15:17:29 +02:00
Adds tabbed panel method to hide tab if it is empty.
https://github.com/BentoBoxWorld/BentoBox/issues/896
This commit is contained in:
parent
612683f728
commit
33b4c70f25
@ -47,6 +47,7 @@ public class IslandSettingsCommand extends CompositeCommand {
|
|||||||
.tab(2, new SettingsTab(getWorld(), user, island, Flag.Type.SETTING))
|
.tab(2, new SettingsTab(getWorld(), user, island, Flag.Type.SETTING))
|
||||||
.startingSlot(1)
|
.startingSlot(1)
|
||||||
.size(54)
|
.size(54)
|
||||||
|
.hideIfEmpty()
|
||||||
.build().openPanel();
|
.build().openPanel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,11 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||||||
// Get the tab
|
// Get the tab
|
||||||
Tab tab = tpb.getTabs().get(activeTab);
|
Tab tab = tpb.getTabs().get(activeTab);
|
||||||
|
|
||||||
|
// Remove any tabs that have no items, if required
|
||||||
|
if (tpb.isHideIfEmpty()) {
|
||||||
|
tpb.getTabs().values().removeIf(t -> !t.equals(tab) && !t.getPanelItems().stream().anyMatch(Objects::nonNull));
|
||||||
|
}
|
||||||
|
|
||||||
// Set up the tabbed header
|
// Set up the tabbed header
|
||||||
setupHeader(tab, items);
|
setupHeader(tab, items);
|
||||||
|
|
||||||
@ -127,7 +132,9 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||||||
// Add icons
|
// Add icons
|
||||||
for (Entry<Integer, Tab> tabPanel : tpb.getTabs().entrySet()) {
|
for (Entry<Integer, Tab> tabPanel : tpb.getTabs().entrySet()) {
|
||||||
// Add the icon to the top row
|
// Add the icon to the top row
|
||||||
if (tabPanel.getValue().getPermission().isEmpty() || tpb.getUser().hasPermission(tabPanel.getValue().getPermission()) || tpb.getUser().isOp()) {
|
if (tabPanel.getValue().getPermission().isEmpty()
|
||||||
|
|| tpb.getUser().hasPermission(tabPanel.getValue().getPermission())
|
||||||
|
|| tpb.getUser().isOp()) {
|
||||||
PanelItem activeIcon = tabPanel.getValue().getIcon();
|
PanelItem activeIcon = tabPanel.getValue().getIcon();
|
||||||
// Set the glow of the active tab
|
// Set the glow of the active tab
|
||||||
activeIcon.setGlow(tabPanel.getValue().equals(tab));
|
activeIcon.setGlow(tabPanel.getValue().equals(tab));
|
||||||
|
@ -22,6 +22,7 @@ public class TabbedPanelBuilder {
|
|||||||
private int startingSlot;
|
private int startingSlot;
|
||||||
private World world;
|
private World world;
|
||||||
private User user;
|
private User user;
|
||||||
|
private boolean hideIfEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces panel to be a specific number of slots.
|
* Forces panel to be a specific number of slots.
|
||||||
@ -79,6 +80,14 @@ public class TabbedPanelBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hides the panel from view if there are no panel items in it
|
||||||
|
* @return TabbedPanelBuilder
|
||||||
|
*/
|
||||||
|
public TabbedPanelBuilder hideIfEmpty() {
|
||||||
|
this.hideIfEmpty = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Build the panel
|
* Build the panel
|
||||||
* @return Panel
|
* @return Panel
|
||||||
@ -126,6 +135,13 @@ public class TabbedPanelBuilder {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the hideIfEmpty
|
||||||
|
*/
|
||||||
|
public boolean isHideIfEmpty() {
|
||||||
|
return hideIfEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package world.bentobox.bentobox.api.panels;
|
package world.bentobox.bentobox.api.panels;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
Loading…
Reference in New Issue
Block a user