bentobox/src/main/java/us/tastybento/bskyblock/managers/FlagsManager.java
Tastybento fa1ccd0c99 Fixed bugs with MySQL saving and loading.
Added the adapter annotation to MySQL and fixed issues with empty
hashmaps causing null errors.

Added a flag serializer adapter for the protection flags so that flags
are saved and loaded correctly.

Renamed the Adapter notation class to be clearer about what it is doing.
2018-02-04 12:53:17 -08:00

46 lines
1.2 KiB
Java

package us.tastybento.bskyblock.managers;
import java.util.ArrayList;
import java.util.List;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.panels.PanelItem;
public class FlagsManager {
private BSkyBlock plugin;
public FlagsManager(BSkyBlock plugin) {
this.plugin = plugin;
}
private List<Flag> flags = new ArrayList<>();
public void registerFlag(Flag flag) {
//TODO all the security checks
//plugin.getLogger().info("DEBUG: registering flag " + flag.getID());
flags.add(flag);
// If there is a listener, register it into Bukkit.
flag.getListener().ifPresent(l -> plugin.getServer().getPluginManager().registerEvents(l, plugin));
}
public List<Flag> getFlags() {
return flags;
}
public Flag getFlagByID(String id) {
for (Flag flag : flags) {
if (flag.getID().equals(id.toUpperCase())) return flag;
}
return null;
}
public Flag getFlagByIcon(PanelItem item) {
for (Flag flag : flags) {
if (flag.getIcon().equals(item)) return flag;
}
return null;
}
}