2018-01-01 01:41:19 +01:00
|
|
|
package us.tastybento.bskyblock.managers;
|
|
|
|
|
2018-02-05 23:30:35 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
2018-02-06 02:39:04 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2018-01-07 00:23:01 +01:00
|
|
|
|
2018-01-01 01:41:19 +01:00
|
|
|
import us.tastybento.bskyblock.BSkyBlock;
|
|
|
|
import us.tastybento.bskyblock.api.flags.Flag;
|
|
|
|
import us.tastybento.bskyblock.api.panels.PanelItem;
|
2018-02-05 23:51:03 +01:00
|
|
|
import us.tastybento.bskyblock.lists.Flags;
|
2018-01-01 01:41:19 +01:00
|
|
|
|
2018-01-29 05:44:57 +01:00
|
|
|
public class FlagsManager {
|
|
|
|
|
2018-02-06 02:39:04 +01:00
|
|
|
private BSkyBlock plugin;
|
2018-02-06 08:53:07 +01:00
|
|
|
private HashMap<String, Flag> flags = new HashMap<>();
|
2018-02-06 02:39:04 +01:00
|
|
|
|
2018-01-29 05:44:57 +01:00
|
|
|
|
|
|
|
public FlagsManager(BSkyBlock plugin) {
|
2018-02-06 02:39:04 +01:00
|
|
|
this.plugin = plugin;
|
2018-02-05 23:30:35 +01:00
|
|
|
|
2018-02-06 08:53:07 +01:00
|
|
|
// Register default flags
|
|
|
|
for (Flag flag : Flags.values()) {
|
|
|
|
registerFlag(flag);
|
|
|
|
}
|
2018-01-29 05:44:57 +01:00
|
|
|
}
|
2018-01-01 01:41:19 +01:00
|
|
|
|
2018-02-06 08:53:07 +01:00
|
|
|
/**
|
|
|
|
* Register a new flag with BSkyBlock
|
|
|
|
* @param flag
|
|
|
|
*/
|
2018-01-01 01:41:19 +01:00
|
|
|
public void registerFlag(Flag flag) {
|
2018-02-06 02:39:04 +01:00
|
|
|
//Bukkit.getLogger().info("DEBUG: registering flag " + flag.getID());
|
2018-02-05 23:30:35 +01:00
|
|
|
flags.put(flag.getID(), flag);
|
2018-01-01 01:41:19 +01:00
|
|
|
// If there is a listener, register it into Bukkit.
|
2018-02-06 02:39:04 +01:00
|
|
|
flag.getListener().ifPresent(l -> Bukkit.getServer().getPluginManager().registerEvents(l, plugin));
|
2018-01-01 01:41:19 +01:00
|
|
|
}
|
|
|
|
|
2018-02-06 08:53:07 +01:00
|
|
|
public HashMap<String, Flag> getFlags() {
|
2018-01-01 01:41:19 +01:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-02-06 08:53:07 +01:00
|
|
|
/**
|
|
|
|
* Get flag by string
|
|
|
|
* @param key - string name same as the enum
|
|
|
|
* @return Flag or null if not known
|
|
|
|
*/
|
|
|
|
public Flag getFlagByID(String id) {
|
2018-02-06 02:39:04 +01:00
|
|
|
//Bukkit.getLogger().info("DEBUG: requesting " + id + " flags size = " + flags.size());
|
2018-02-05 23:30:35 +01:00
|
|
|
return flags.get(id);
|
2018-01-01 01:41:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Flag getFlagByIcon(PanelItem item) {
|
2018-02-05 23:30:35 +01:00
|
|
|
for (Flag flag : flags.values()) {
|
2018-01-01 01:41:19 +01:00
|
|
|
if (flag.getIcon().equals(item)) return flag;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-02-05 23:51:03 +01:00
|
|
|
|
2018-01-01 01:41:19 +01:00
|
|
|
}
|