Search in sources :

Example 56 with Island

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

the class BucketListener method onClick.

@EventHandler(ignoreCancelled = true)
public void onClick(PlayerInteractEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getPlayer().getWorld()))
        return;
    Player player = event.getPlayer();
    ItemStack itemInHand = player.getInventory().getItemInMainHand();
    if (!(IridiumSkyblock.getInstance().getConfiguration().obsidianBucket && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getType().equals(Material.OBSIDIAN) && itemInHand.getType().equals(Material.BUCKET))) {
        return;
    }
    Location location = event.getClickedBlock().getLocation();
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(location);
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    if (island.isPresent()) {
        if (IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BUCKET)) {
            event.getClickedBlock().setType(Material.AIR);
            if (itemInHand.getAmount() > 1) {
                itemInHand.setAmount(itemInHand.getAmount() - 1);
                if (InventoryUtils.hasEmptySlot(player.getInventory())) {
                    event.getPlayer().getInventory().addItem(new ItemStack(Material.LAVA_BUCKET));
                } else {
                    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inventoryFull));
                    player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.LAVA_BUCKET));
                }
            } else {
                itemInHand.setType(Material.LAVA_BUCKET);
            }
        } else {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) ItemStack(org.bukkit.inventory.ItemStack) Island(com.iridium.iridiumskyblock.database.Island) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 57 with Island

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

the class EntityPickupItemListener method onEntityPickupItem.

@EventHandler(ignoreCancelled = true)
@SuppressWarnings("deprecation")
public void onEntityPickupItem(EntityPickupItemEvent event) {
    if (!(event.getEntity() instanceof Player))
        return;
    Player player = (Player) event.getEntity();
    Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getIslandViaLocation(event.getItem().getLocation());
    if (!island.isPresent())
        return;
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.PICKUP_ITEMS)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 58 with Island

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

the class IslandTopGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    List<Island> islands = IridiumSkyblock.getInstance().getIslandManager().getIslands(IslandManager.SortType.VALUE);
    islandSlots.clear();
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().islandTopGUI.background);
    for (int rank : IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.keySet()) {
        int slot = IridiumSkyblock.getInstance().getConfiguration().islandTopSlots.get(rank);
        if (islands.size() >= rank) {
            Island island = islands.get(rank - 1);
            islandSlots.put(slot, island);
            inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()));
        } else {
            inventory.setItem(slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandTopGUI.filler));
        }
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Example 59 with Island

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

the class IslandTopGUI 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) {
    if (!islandSlots.containsKey(event.getSlot()))
        return;
    Island island = islandSlots.get(event.getSlot());
    IridiumSkyblock.getInstance().getCommands().visitCommand.execute(event.getWhoClicked(), new String[] { "", island.getOwner().getName() });
}
Also used : Island(com.iridium.iridiumskyblock.database.Island)

Example 60 with Island

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

the class IslandVisitorsGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
    inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
    final long elementsPerPage = inventory.getSize() - 9;
    AtomicInteger slot = new AtomicInteger(0);
    IridiumSkyblock.getInstance().getIslandManager().getPlayersOnIsland(getIsland()).stream().filter(user -> user.getIsland().map(Island::getId).orElse(0) != getIsland().getId()).skip((page - 1) * elementsPerPage).limit(elementsPerPage).forEachOrdered(user -> {
        visitors.add(user);
        List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(user).applyIslandPlaceholders(getIsland()).build();
        inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().visitorsGUI.item, placeholderList));
    });
}
Also used : ItemStackUtils(com.iridium.iridiumcore.utils.ItemStackUtils) User(com.iridium.iridiumskyblock.database.User) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) NotNull(org.jetbrains.annotations.NotNull) Placeholder(com.iridium.iridiumcore.utils.Placeholder) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Placeholder(com.iridium.iridiumcore.utils.Placeholder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)92 User (com.iridium.iridiumskyblock.database.User)76 Player (org.bukkit.entity.Player)60 EventHandler (org.bukkit.event.EventHandler)18 List (java.util.List)16 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)15 OfflinePlayer (org.bukkit.OfflinePlayer)15 Collectors (java.util.stream.Collectors)14 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)12 Optional (java.util.Optional)11 StringUtils (com.iridium.iridiumcore.utils.StringUtils)10 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)7 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)6 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)6 Bukkit (org.bukkit.Bukkit)6