Search in sources :

Example 1 with Permission

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

the class IslandPermissionsGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandPermissionsGUI.background);
    inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
    inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
    for (Map.Entry<String, Permission> permission : IridiumSkyblock.getInstance().getPermissionList().entrySet()) {
        if (permission.getValue().getPage() != page)
            continue;
        if (!permission.getValue().isModifiable())
            continue;
        boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey());
        inventory.setItem(permission.getValue().getItem().slot, ItemStackUtils.makeItem(permission.getValue().getItem(), Collections.singletonList(new Placeholder("permission", allowed ? IridiumSkyblock.getInstance().getPermissions().allowed : IridiumSkyblock.getInstance().getPermissions().denied))));
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Placeholder(com.iridium.iridiumcore.utils.Placeholder) Permission(com.iridium.iridiumskyblock.Permission) Map(java.util.Map)

Example 2 with Permission

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

the class IslandPermissionsGUI 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) {
    for (Map.Entry<String, Permission> permission : IridiumSkyblock.getInstance().getPermissionList().entrySet()) {
        if (permission.getValue().getItem().slot != event.getSlot())
            continue;
        if (permission.getValue().getPage() != page)
            continue;
        if (!permission.getValue().isModifiable())
            continue;
        User user = IridiumSkyblock.getInstance().getUserManager().getUser((Player) event.getWhoClicked());
        if (user.getIslandRank().getLevel() <= islandRank.getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), user, PermissionType.CHANGE_PERMISSIONS)) {
            event.getWhoClicked().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotChangePermissions.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        } else {
            boolean allowed = IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(getIsland(), islandRank, permission.getValue(), permission.getKey());
            IridiumSkyblock.getInstance().getIslandManager().setIslandPermission(getIsland(), islandRank, permission.getKey(), !allowed);
            event.getWhoClicked().openInventory(getInventory());
        }
        return;
    }
    if (event.getSlot() == getNoItemGUI().size - 7 && hasPage(page - 1)) {
        page--;
        event.getWhoClicked().openInventory(getInventory());
        return;
    }
    if (event.getSlot() == getNoItemGUI().size - 3 && hasPage(page + 1)) {
        page++;
        event.getWhoClicked().openInventory(getInventory());
    }
}
Also used : User(com.iridium.iridiumskyblock.database.User) Permission(com.iridium.iridiumskyblock.Permission) Map(java.util.Map)

Aggregations

Permission (com.iridium.iridiumskyblock.Permission)2 Map (java.util.Map)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 User (com.iridium.iridiumskyblock.database.User)1