mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-18 21:32:04 +01:00
Paginates geo limited mob settings.
This commit is contained in:
parent
e8d5e66514
commit
c2375e7f50
@ -1,23 +1,14 @@
|
|||||||
package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
package world.bentobox.bentobox.listeners.flags.clicklisteners;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.clicklisteners.GeoMobLimitTab.EntityLimitTabType;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@ -28,15 +19,6 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*/
|
*/
|
||||||
public class GeoLimitClickListener implements ClickHandler {
|
public class GeoLimitClickListener implements ClickHandler {
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of all living entity types, minus some
|
|
||||||
*/
|
|
||||||
private final List<EntityType> livingEntityTypes = Arrays.stream(EntityType.values())
|
|
||||||
.filter(EntityType::isAlive)
|
|
||||||
.filter(t -> !(t.equals(EntityType.PLAYER) || t.equals(EntityType.GIANT) || t.equals(EntityType.ARMOR_STAND)))
|
|
||||||
.sorted(Comparator.comparing(EntityType::name))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||||
// Get the world
|
// Get the world
|
||||||
@ -52,51 +34,22 @@ public class GeoLimitClickListener implements ClickHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String panelName = user.getTranslation("protection.flags.GEO_LIMIT_MOBS.name");
|
|
||||||
if (panel.getName().equals(panelName)) {
|
|
||||||
// This is a click on the geo limit panel
|
|
||||||
// Slot relates to the enum
|
|
||||||
EntityType c = livingEntityTypes.get(slot);
|
|
||||||
if (iwm.getGeoLimitSettings(user.getWorld()).contains(c.name())) {
|
|
||||||
iwm.getGeoLimitSettings(user.getWorld()).remove(c.name());
|
|
||||||
} else {
|
|
||||||
iwm.getGeoLimitSettings(user.getWorld()).add(c.name());
|
|
||||||
}
|
|
||||||
// Apply change to panel
|
|
||||||
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
|
|
||||||
// Save settings
|
|
||||||
iwm.getAddon(Util.getWorld(user.getWorld())).ifPresent(GameModeAddon::saveWorldSettings);
|
|
||||||
} else {
|
|
||||||
// Open the Sub Settings panel
|
// Open the Sub Settings panel
|
||||||
openPanel(user, panelName);
|
openPanel(user);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openPanel(User user, String panelName) {
|
private void openPanel(User user) {
|
||||||
// Close the current panel
|
// Close the current panel
|
||||||
user.closeInventory();
|
user.closeInventory();
|
||||||
// Open a new panel
|
// Open a new panel
|
||||||
PanelBuilder pb = new PanelBuilder();
|
new TabbedPanelBuilder()
|
||||||
pb.user(user).name(panelName);
|
.user(user)
|
||||||
// Make panel items
|
.world(user.getWorld())
|
||||||
livingEntityTypes.forEach(c -> pb.item(getPanelItem(c, user)));
|
.tab(1, new GeoMobLimitTab(user, EntityLimitTabType.GEO_LIMIT))
|
||||||
pb.build();
|
.startingSlot(1)
|
||||||
|
.size(54)
|
||||||
|
.build().openPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PanelItem getPanelItem(EntityType c, User user) {
|
|
||||||
PanelItemBuilder pib = new PanelItemBuilder();
|
|
||||||
pib.name(Util.prettifyText(c.toString()));
|
|
||||||
pib.clickHandler(this);
|
|
||||||
if (BentoBox.getInstance().getIWM().getGeoLimitSettings(user.getWorld()).contains(c.name())) {
|
|
||||||
pib.icon(Material.GREEN_SHULKER_BOX);
|
|
||||||
pib.description(user.getTranslation("protection.panel.flag-item.setting-active"));
|
|
||||||
} else {
|
|
||||||
pib.icon(Material.RED_SHULKER_BOX);
|
|
||||||
pib.description(user.getTranslation("protection.panel.flag-item.setting-disabled"));
|
|
||||||
}
|
|
||||||
return pib.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,18 +29,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MobLimitTab implements Tab, ClickHandler {
|
public class GeoMobLimitTab implements Tab, ClickHandler {
|
||||||
|
|
||||||
private BentoBox plugin = BentoBox.getInstance();
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param user
|
|
||||||
*/
|
|
||||||
public MobLimitTab(User user) {
|
|
||||||
super();
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of all living entity types, minus some
|
* A list of all living entity types, minus some
|
||||||
@ -51,19 +40,46 @@ public class MobLimitTab implements Tab, ClickHandler {
|
|||||||
.sorted(Comparator.comparing(EntityType::name))
|
.sorted(Comparator.comparing(EntityType::name))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
public enum EntityLimitTabType {
|
||||||
|
GEO_LIMIT,
|
||||||
|
MOB_LIMIT
|
||||||
|
}
|
||||||
|
|
||||||
|
private final BentoBox plugin = BentoBox.getInstance();
|
||||||
|
private final User user;
|
||||||
|
private final EntityLimitTabType type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
public GeoMobLimitTab(User user, EntityLimitTabType type) {
|
||||||
|
super();
|
||||||
|
this.user = user;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||||
// This is a click on the mob limit panel
|
// This is a click on the mob limit panel
|
||||||
// Case panel to Tabbed Panel to get the active page
|
// Case panel to Tabbed Panel to get the active page
|
||||||
TabbedPanel tp = (TabbedPanel)panel;
|
TabbedPanel tp = (TabbedPanel)panel;
|
||||||
// Conver the slot and active page to an index
|
// Convert the slot and active page to an index
|
||||||
int index = tp.getActivePage() * 36 + slot - 9;
|
int index = tp.getActivePage() * 36 + slot - 9;
|
||||||
EntityType c = LIVING_ENTITY_TYPES.get(index);
|
EntityType c = LIVING_ENTITY_TYPES.get(index);
|
||||||
|
if (type == EntityLimitTabType.MOB_LIMIT) {
|
||||||
if (plugin.getIWM().getMobLimitSettings(user.getWorld()).contains(c.name())) {
|
if (plugin.getIWM().getMobLimitSettings(user.getWorld()).contains(c.name())) {
|
||||||
plugin.getIWM().getMobLimitSettings(user.getWorld()).remove(c.name());
|
plugin.getIWM().getMobLimitSettings(user.getWorld()).remove(c.name());
|
||||||
} else {
|
} else {
|
||||||
plugin.getIWM().getMobLimitSettings(user.getWorld()).add(c.name());
|
plugin.getIWM().getMobLimitSettings(user.getWorld()).add(c.name());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (plugin.getIWM().getGeoLimitSettings(user.getWorld()).contains(c.name())) {
|
||||||
|
plugin.getIWM().getGeoLimitSettings(user.getWorld()).remove(c.name());
|
||||||
|
} else {
|
||||||
|
plugin.getIWM().getGeoLimitSettings(user.getWorld()).add(c.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
|
panel.getInventory().setItem(slot, getPanelItem(c, user).getItem());
|
||||||
// Save settings
|
// Save settings
|
||||||
@ -73,13 +89,18 @@ public class MobLimitTab implements Tab, ClickHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PanelItem getIcon() {
|
public PanelItem getIcon() {
|
||||||
|
if (type == EntityLimitTabType.MOB_LIMIT) {
|
||||||
return new PanelItemBuilder().icon(Material.IRON_BOOTS).name(user.getTranslation("protection.flags.LIMIT_MOBS.name")).build();
|
return new PanelItemBuilder().icon(Material.IRON_BOOTS).name(user.getTranslation("protection.flags.LIMIT_MOBS.name")).build();
|
||||||
|
} else {
|
||||||
|
return new PanelItemBuilder().icon(Material.CHAINMAIL_CHESTPLATE).name(user.getTranslation("protection.flags.GEO_LIMIT_MOBS.name")).build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return user.getTranslation("protection.flags.LIMIT_MOBS.name");
|
return type == EntityLimitTabType.MOB_LIMIT ? user.getTranslation("protection.flags.LIMIT_MOBS.name")
|
||||||
|
: user.getTranslation("protection.flags.GEO_LIMIT_MOBS.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,6 +118,7 @@ public class MobLimitTab implements Tab, ClickHandler {
|
|||||||
PanelItemBuilder pib = new PanelItemBuilder();
|
PanelItemBuilder pib = new PanelItemBuilder();
|
||||||
pib.name(Util.prettifyText(c.toString()));
|
pib.name(Util.prettifyText(c.toString()));
|
||||||
pib.clickHandler(this);
|
pib.clickHandler(this);
|
||||||
|
if (type == EntityLimitTabType.MOB_LIMIT) {
|
||||||
if (!BentoBox.getInstance().getIWM().getMobLimitSettings(user.getWorld()).contains(c.name())) {
|
if (!BentoBox.getInstance().getIWM().getMobLimitSettings(user.getWorld()).contains(c.name())) {
|
||||||
pib.icon(Material.GREEN_SHULKER_BOX);
|
pib.icon(Material.GREEN_SHULKER_BOX);
|
||||||
pib.description(user.getTranslation("protection.flags.LIMIT_MOBS.can"));
|
pib.description(user.getTranslation("protection.flags.LIMIT_MOBS.can"));
|
||||||
@ -104,6 +126,15 @@ public class MobLimitTab implements Tab, ClickHandler {
|
|||||||
pib.icon(Material.RED_SHULKER_BOX);
|
pib.icon(Material.RED_SHULKER_BOX);
|
||||||
pib.description(user.getTranslation("protection.flags.LIMIT_MOBS.cannot"));
|
pib.description(user.getTranslation("protection.flags.LIMIT_MOBS.cannot"));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (BentoBox.getInstance().getIWM().getGeoLimitSettings(user.getWorld()).contains(c.name())) {
|
||||||
|
pib.icon(Material.GREEN_SHULKER_BOX);
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.setting-active"));
|
||||||
|
} else {
|
||||||
|
pib.icon(Material.RED_SHULKER_BOX);
|
||||||
|
pib.description(user.getTranslation("protection.panel.flag-item.setting-disabled"));
|
||||||
|
}
|
||||||
|
}
|
||||||
return pib.build();
|
return pib.build();
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import world.bentobox.bentobox.api.panels.Panel;
|
|||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
import world.bentobox.bentobox.listeners.flags.clicklisteners.GeoMobLimitTab.EntityLimitTabType;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ public class MobLimitClickListener implements ClickHandler {
|
|||||||
new TabbedPanelBuilder()
|
new TabbedPanelBuilder()
|
||||||
.user(user)
|
.user(user)
|
||||||
.world(user.getWorld())
|
.world(user.getWorld())
|
||||||
.tab(1, new MobLimitTab(user))
|
.tab(1, new GeoMobLimitTab(user, EntityLimitTabType.MOB_LIMIT))
|
||||||
.startingSlot(1)
|
.startingSlot(1)
|
||||||
.size(54)
|
.size(54)
|
||||||
.build().openPanel();
|
.build().openPanel();
|
||||||
|
Loading…
Reference in New Issue
Block a user