Implemented basic SettingsPanel + MAJOR changes in Panel/Flag API

It currently just displays a panel with all the flags in it. And throws exception when clicking on an item :P

Flag no longer have a PanelItem but Material instead as the icon.
Added a toPanelItem() method in Flag
Made the Panel(Builder) not using the Optional as fields anymore
This commit is contained in:
Florian CUNY 2018-02-25 17:09:46 +01:00
parent 6edc9555ad
commit a885247c85
10 changed files with 132 additions and 92 deletions

View File

@ -2,9 +2,13 @@ package us.tastybento.bskyblock.api.flags;
import java.util.Optional;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
public class Flag {
@ -14,15 +18,16 @@ public class Flag {
}
private final String id;
private final PanelItem icon;
private final Material icon;
private final Listener listener;
private final Type type;
private boolean defaultSetting;
public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, Type type) {
id = id2;
Flag(String id, Material icon, Listener listener, boolean defaultSetting, Type type) {
this.id = id;
this.icon = icon;
this.listener = listener;
this.defaultSetting = defaultSetting;
this.type = type;
}
@ -30,7 +35,7 @@ public class Flag {
return id;
}
public PanelItem getIcon() {
public Material getIcon() {
return icon;
}
@ -100,4 +105,14 @@ public class Flag {
return true;
}
public PanelItem toPanelItem(User user) {
return new PanelItemBuilder()
.icon(new ItemStack(icon))
.name(user.getTranslation("protection.flags." + id))
.clickHandler((clicker, click) -> {
clicker.sendRawMessage("You clicked on : " + id);
return true;
})
.build();
}
}

View File

@ -11,7 +11,7 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
public class FlagBuilder {
private String id;
private PanelItem icon;
private Material icon;
private Listener listener;
private boolean defaultSetting;
private Type type = Type.PROTECTION;
@ -22,15 +22,7 @@ public class FlagBuilder {
}
public FlagBuilder icon(Material icon) {
icon(new PanelItemBuilder().icon(new ItemStack(icon)).build());
return this;
}
public FlagBuilder icon(PanelItem icon) {
this.icon = icon;
//TODO: if icon don't have a clickhandler, add the default one
//TODO: if icon don't have a display name, set it to the default reference
//TODO: if icon don't have a lore, set it to the default one
return this;
}

View File

@ -14,10 +14,10 @@ public class Panel {
private Inventory inventory;
private Map<Integer, PanelItem> items;
private Optional<PanelListener> listener;
private Optional<User> user;
private PanelListener listener;
private User user;
public Panel(String name, Map<Integer, PanelItem> items, int size, Optional<User> user, Optional<PanelListener> listener) {
public Panel(String name, Map<Integer, PanelItem> items, int size, User user, PanelListener listener) {
this.items = items;
// If size is undefined (0) then use the number of items
if (size == 0) {
@ -38,14 +38,11 @@ public class Panel {
}
this.listener = listener;
// If the listener is defined, then run setup
listener.ifPresent(l -> l.setup());
/*
if (listener.isPresent()) {
listener.get().setup();
}*/
if (listener != null) listener.setup();
// If the user is defined, then open panel immediately
this.user = user;
user.ifPresent(this::open);
if (user != null) this.open(user);
}
public Inventory getInventory() {
@ -60,11 +57,11 @@ public class Panel {
* @return the listener
*/
public Optional<PanelListener> getListener() {
return listener;
return Optional.of(listener);
}
public Optional<User> getUser() {
return user;
return Optional.of(user);
}
public void open(Player... players) {
@ -102,14 +99,14 @@ public class Panel {
/**
* @param listener the listener to set
*/
public void setListener(Optional<PanelListener> listener) {
public void setListener(PanelListener listener) {
this.listener = listener;
}
/**
* @param user - the User the user to set
*/
public void setUser(Optional<User> user) {
public void setUser(User user) {
this.user = user;
}
}

View File

@ -3,6 +3,7 @@ package us.tastybento.bskyblock.api.panels;
import java.util.List;
import java.util.Optional;
import org.bukkit.ChatColor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -64,7 +65,7 @@ public class PanelItem {
public void setName(String name) {
this.name = name;
meta.setDisplayName(name);
meta.setLocalizedName(name); //Localized name cannot be overridden by the player using an anvils
icon.setItemMeta(meta);
}

View File

@ -12,8 +12,8 @@ public class PanelBuilder {
private String name;
private TreeMap<Integer, PanelItem> items = new TreeMap<>();
private int size;
private Optional<User> user = Optional.empty();
private Optional<PanelListener> listener = Optional.empty();
private User user;
private PanelListener listener;
public PanelBuilder setName(String name) {
this.name = name;
@ -86,7 +86,7 @@ public class PanelBuilder {
* @return PanelBuilder
*/
public PanelBuilder setUser(User user) {
this.user = Optional.of(user);
this.user = user;
return this;
}
@ -96,7 +96,7 @@ public class PanelBuilder {
* @return PanelBuilder
*/
public PanelBuilder setListener(PanelListener listener) {
this.listener = Optional.of(listener);
this.listener = listener;
return this;
}
}

View File

@ -6,6 +6,7 @@ import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.panels.SettingsPanel;
/**
* @author Poslovitch
@ -31,6 +32,7 @@ public class IslandSettingsCommand extends CompositeCommand {
*/
@Override
public boolean execute(User user, List<String> args) {
SettingsPanel.openPanel(user);
return true;
}
}

View File

@ -30,49 +30,49 @@ import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
public class Flags {
public static final us.tastybento.bskyblock.api.flags.Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
// Block interactions - all use BlockInteractionListener()
public static final us.tastybento.bskyblock.api.flags.Flag ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build();
public static final us.tastybento.bskyblock.api.flags.Flag BED = new FlagBuilder().id("BED").icon(Material.BED).build();
public static final us.tastybento.bskyblock.api.flags.Flag BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build();
public static final us.tastybento.bskyblock.api.flags.Flag CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build();
public static final us.tastybento.bskyblock.api.flags.Flag DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOODEN_DOOR).build();
public static final us.tastybento.bskyblock.api.flags.Flag CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build();
public static final us.tastybento.bskyblock.api.flags.Flag ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build();
public static final us.tastybento.bskyblock.api.flags.Flag FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build();
public static final us.tastybento.bskyblock.api.flags.Flag GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build();
public static final us.tastybento.bskyblock.api.flags.Flag MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build();
public static final us.tastybento.bskyblock.api.flags.Flag LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build();
public static final us.tastybento.bskyblock.api.flags.Flag REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build();
public static final us.tastybento.bskyblock.api.flags.Flag SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build();
public static final Flag ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener()).build();
public static final Flag BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build();
public static final Flag BED = new FlagBuilder().id("BED").icon(Material.BED).build();
public static final Flag BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build();
public static final Flag CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build();
public static final Flag DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOOD_DOOR).build();
public static final Flag CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build();
public static final Flag ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build();
public static final Flag FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build();
public static final Flag GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build();
public static final Flag MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build();
public static final Flag LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build();
public static final Flag REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build();
public static final Flag SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build();
// Entity interactions
public static final us.tastybento.bskyblock.api.flags.Flag ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build();
public static final us.tastybento.bskyblock.api.flags.Flag TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build();
public static final Flag ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener()).build();
public static final Flag RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build();
public static final Flag TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build();
// Breeding
public static final us.tastybento.bskyblock.api.flags.Flag BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener()).build();
public static final Flag BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT_ITEM).listener(new BreedingListener()).build();
// Buckets. All bucket use is covered by one listener
public static final us.tastybento.bskyblock.api.flags.Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
public static final us.tastybento.bskyblock.api.flags.Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
public static final us.tastybento.bskyblock.api.flags.Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
// Chorus Fruit and Enderpearls
public static final us.tastybento.bskyblock.api.flags.Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build();
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
public static final Flag ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build();
// Physical interactions
public static final us.tastybento.bskyblock.api.flags.Flag CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build();
public static final Flag CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener()).build();
public static final Flag PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build();
// Egg throwing
public static final us.tastybento.bskyblock.api.flags.Flag EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener()).build();
public static final Flag EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener()).build();
/*
* Fire
@ -84,49 +84,49 @@ public class Flags {
* I'll take you to burn
* - The Crazy World of Arthur Brown
*/
public static final us.tastybento.bskyblock.api.flags.Flag FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build();
public static final us.tastybento.bskyblock.api.flags.Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build();
public static final Flag FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener()).build();
public static final Flag FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build();
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build();
// Inventories
public static final us.tastybento.bskyblock.api.flags.Flag MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener()).build();
public static final Flag MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener()).build();
// Hurting things
public static final us.tastybento.bskyblock.api.flags.Flag HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build();
public static final Flag HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener()).build();
public static final Flag HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build();
// Leashes
public static final us.tastybento.bskyblock.api.flags.Flag LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener()).build();
public static final Flag LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener()).build();
// Portal use protection
public static final us.tastybento.bskyblock.api.flags.Flag PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener()).build();
public static final Flag PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener()).build();
// Shearing
public static final us.tastybento.bskyblock.api.flags.Flag SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener()).build();
public static final Flag SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener()).build();
// Item pickup or drop
public static final us.tastybento.bskyblock.api.flags.Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build();
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build();
/*
* Settings flags (not protection flags)
*/
// PVP
public static final us.tastybento.bskyblock.api.flags.Flag PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).type(Type.SETTING).listener(new PVPListener()).build();
public static final us.tastybento.bskyblock.api.flags.Flag PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).type(Type.SETTING).build();
public static final us.tastybento.bskyblock.api.flags.Flag PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).type(Type.SETTING).build();
public static final Flag PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).type(Type.SETTING).listener(new PVPListener()).build();
public static final Flag PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).type(Type.SETTING).build();
public static final Flag PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).type(Type.SETTING).build();
// Others
public static final us.tastybento.bskyblock.api.flags.Flag ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).type(Type.SETTING).build();
public static final us.tastybento.bskyblock.api.flags.Flag MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(Type.SETTING).build();
public static final us.tastybento.bskyblock.api.flags.Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
public static final Flag ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).type(Type.SETTING).build();
public static final Flag MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(Type.SETTING).build();
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
/**
* @return List of all the flags in this class
*/
public static List<us.tastybento.bskyblock.api.flags.Flag> values() {
return Arrays.asList(Flag.class.getFields()).stream().map(field -> {
public static List<Flag> values() {
return Arrays.asList(Flags.class.getFields()).stream().map(field -> {
try {
return (us.tastybento.bskyblock.api.flags.Flag)field.get(null);
return (Flag)field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().severe("Could not get Flag values " + e.getMessage());
}

View File

@ -2,13 +2,16 @@ package us.tastybento.bskyblock.managers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.lists.Flags;
/**
* @author Poslovitch
@ -17,7 +20,7 @@ import us.tastybento.bskyblock.api.panels.PanelItem;
public class FlagsManager {
private BSkyBlock plugin;
private HashMap<String, Flag> flags = new HashMap<>();
private List<Flag> flags = new ArrayList<>();
/**
* Stores the flag listeners that have already been registered into Bukkit's API to avoid duplicates.
@ -28,7 +31,7 @@ public class FlagsManager {
this.plugin = plugin;
// Register default flags
for (Flag flag : us.tastybento.bskyblock.lists.Flags.values()) {
for (Flag flag : Flags.values()) {
registerFlag(flag);
}
}
@ -38,8 +41,8 @@ public class FlagsManager {
* @param flag
*/
public void registerFlag(Flag flag) {
//Bukkit.getLogger().info("DEBUG: registering flag " + flag.getID());
flags.put(flag.getID(), flag);
//TODO throw an exception in case someone registers a flag with an existing id?
flags.add(flag);
// If there is a listener which is not already registered, register it into Bukkit.
flag.getListener().ifPresent(l -> {
if (!registeredListeners.contains(l)) {
@ -47,9 +50,11 @@ public class FlagsManager {
registeredListeners.add(l);
}
});
// Sorts the list
}
public HashMap<String, Flag> getFlags() {
public List<Flag> getFlags() {
return flags;
}
@ -59,13 +64,17 @@ public class FlagsManager {
* @return Flag or null if not known
*/
public Flag getFlagByID(String id) {
//Bukkit.getLogger().info("DEBUG: requesting " + id + " flags size = " + flags.size());
return flags.get(id);
for (Flag flag : flags) {
if (flag.getID().equals(id)) {
return flag;
}
}
return null;
}
public Flag getFlagByIcon(PanelItem item) {
for (Flag flag : flags.values()) {
if (flag.getIcon().equals(item)) {
public Flag getFlagByIcon(Material icon) {
for (Flag flag : flags) {
if (flag.getIcon().equals(icon)) {
return flag;
}
}

View File

@ -1,7 +1,31 @@
package us.tastybento.bskyblock.panels;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
/**
* @author Poslovitch
*/
public class SettingsPanel {
/**
* Dynamically creates the panel.
* @param user the User to show the panel to
*/
public static void openPanel(User user) {
PanelBuilder panelBuilder = new PanelBuilder()
.setName(user.getTranslation("panels.settings.title"));
for (Flag flag : BSkyBlock.getInstance().getFlagsManager().getFlags()) {
PanelItem flagIcon = flag.toPanelItem(user);
panelBuilder.addItem(flagIcon);
}
panelBuilder.build().open(user);
}
}

View File

@ -500,7 +500,7 @@ public class TestBSkyBlock {
// Check all the default flags
FlagsManager fm = new FlagsManager(plugin);
Collection<Flag> defaultFlags = Flags.values();
Collection<Flag> f = fm.getFlags().values();
Collection<Flag> f = fm.getFlags();
for (Flag flag : defaultFlags) {
assertTrue(flag.getID(), f.contains(flag));
}
@ -515,7 +515,7 @@ public class TestBSkyBlock {
FlagListener fl = new FlagListener(plugin);
Flag customFlag = new FlagBuilder().id("CUSTOM_FLAG").icon(Material.DIAMOND).listener(fl).build();
assertEquals("CUSTOM_FLAG", customFlag.getID());
assertEquals(Material.DIAMOND, customFlag.getIcon().getItem().getType());
assertEquals(Material.DIAMOND, customFlag.getIcon());
assertEquals(fl, customFlag.getListener().get());
// Add it to the Flag Manager
flagsManager.registerFlag(customFlag);