Search in sources :

Example 1 with IslandSettingChangeEvent

use of com.iridium.iridiumskyblock.api.IslandSettingChangeEvent in project IridiumSkyblock by Iridium-Development.

the class IslandSettingsGUI method onInventoryClick.

/**
 * Called when there is a click in this GUI.
 * Cancelled automatically.
 *
 * @param event The InventoryClickEvent provided by Bukkit
 */
@Override
public void onInventoryClick(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), user, PermissionType.ISLAND_SETTINGS)) {
        event.getWhoClicked().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotChangeSettings.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return;
    }
    for (Map.Entry<String, Setting> setting : IridiumSkyblock.getInstance().getSettingsList().entrySet()) {
        if (event.getSlot() != setting.getValue().getItem().slot)
            continue;
        if (!setting.getValue().isModifiable())
            continue;
        SettingType settingType = SettingType.getByName(setting.getKey());
        IslandSetting islandSetting = IridiumSkyblock.getInstance().getIslandManager().getIslandSetting(getIsland(), settingType);
        String newValue = (event.getClick() == ClickType.RIGHT ? settingType.getNext() : settingType.getPrevious()).getNew(islandSetting.getValue());
        IslandSettingChangeEvent islandSettingChangeEvent = new IslandSettingChangeEvent(player, getIsland(), settingType, newValue);
        Bukkit.getPluginManager().callEvent(islandSettingChangeEvent);
        if (islandSettingChangeEvent.isCancelled())
            return;
        newValue = islandSettingChangeEvent.getNewValue();
        islandSetting.setValue(newValue);
        settingType.getOnChange().run(getIsland(), newValue);
        addContent(event.getInventory());
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) IslandSetting(com.iridium.iridiumskyblock.database.IslandSetting) Setting(com.iridium.iridiumskyblock.Setting) SettingType(com.iridium.iridiumskyblock.SettingType) IslandSettingChangeEvent(com.iridium.iridiumskyblock.api.IslandSettingChangeEvent) Map(java.util.Map)

Aggregations

Setting (com.iridium.iridiumskyblock.Setting)1 SettingType (com.iridium.iridiumskyblock.SettingType)1 IslandSettingChangeEvent (com.iridium.iridiumskyblock.api.IslandSettingChangeEvent)1 IslandSetting (com.iridium.iridiumskyblock.database.IslandSetting)1 User (com.iridium.iridiumskyblock.database.User)1 Map (java.util.Map)1 Player (org.bukkit.entity.Player)1