Search in sources :

Example 61 with Island

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

the class VisitGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().visitGUI.background);
    inventory.setItem(inventory.getSize() - 3, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().nextPage));
    inventory.setItem(inventory.getSize() - 7, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().previousPage));
    int elementsPerPage = inventory.getSize() - 9;
    List<Island> islands = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries().stream().filter(island -> viewer.isBypassing() || island.isVisitable()).skip((long) (page - 1) * elementsPerPage).limit(elementsPerPage).collect(Collectors.toList());
    AtomicInteger slot = new AtomicInteger(0);
    for (Island island : islands) {
        inventory.setItem(slot.getAndIncrement(), ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().visitGUI.item, new PlaceholderBuilder().applyIslandPlaceholders(island).build()));
    }
}
Also used : List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) 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) Collectors(java.util.stream.Collectors) Inventory(org.bukkit.inventory.Inventory) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Example 62 with Island

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

the class VisitGUI 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) {
    List<Island> islands = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries().stream().filter(island -> viewer.isBypassing() || island.isVisitable()).collect(Collectors.toList());
    if (event.getSlot() == getInventory().getSize() - 7) {
        if (page > 1) {
            event.getWhoClicked().openInventory(new VisitGUI(page - 1, viewer).getInventory());
        }
    } else if (event.getSlot() == getInventory().getSize() - 3) {
        if ((event.getInventory().getSize() - 9) * page < islands.size()) {
            event.getWhoClicked().openInventory(new VisitGUI(page + 1, viewer).getInventory());
        }
    } else if (event.getSlot() + 1 <= islands.size()) {
        int index = ((event.getInventory().getSize() - 9) * (page - 1)) + event.getSlot();
        if (islands.size() > index) {
            Island island = islands.get(index);
            IridiumSkyblock.getInstance().getCommands().visitCommand.execute(event.getWhoClicked(), new String[] { "", island.getOwner().getName() });
            event.getWhoClicked().closeInventory();
        }
    }
}
Also used : List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InventoryUtils(com.iridium.iridiumcore.utils.InventoryUtils) 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) Collectors(java.util.stream.Collectors) Inventory(org.bukkit.inventory.Inventory) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Island(com.iridium.iridiumskyblock.database.Island)

Example 63 with Island

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

the class ItemCraftListener method monitorItemCraft.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorItemCraft(CraftItemEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getWhoClicked().getWorld()))
        return;
    int amount = event.isShiftClick() ? Arrays.stream(event.getInventory().getMatrix()).filter(Objects::nonNull).map(ItemStack::getAmount).sorted().findFirst().orElse(1) * event.getRecipe().getResult().getAmount() : event.getRecipe().getResult().getAmount();
    Player player = (Player) event.getWhoClicked();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    XMaterial material = XMaterial.matchXMaterial(event.getRecipe().getResult().getType());
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "CRAFT", material.name(), amount));
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 64 with Island

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

the class PlayerFishListener method monitorPlayerFish.

@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void monitorPlayerFish(PlayerFishEvent event) {
    if (!IridiumSkyblockAPI.getInstance().isIslandWorld(event.getPlayer().getWorld()))
        return;
    Entity caughtEntity = event.getCaught();
    if (caughtEntity == null || event.getState() != PlayerFishEvent.State.CAUGHT_FISH)
        return;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(event.getPlayer());
    Optional<Island> island = user.getIsland();
    island.ifPresent(value -> IridiumSkyblock.getInstance().getMissionManager().handleMissionUpdates(value, "FISH", ((Item) caughtEntity).getItemStack().getType().name(), 1));
}
Also used : Entity(org.bukkit.entity.Entity) Item(org.bukkit.entity.Item) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) EventHandler(org.bukkit.event.EventHandler)

Example 65 with Island

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

the class RemoveCommand method execute.

/**
 * Executes the command for the specified {@link CommandSender} with the provided arguments.
 * Not called when the command execution was invalid (no permission, no player or command disabled).
 *
 * @param sender    The CommandSender which executes this command
 * @param args      The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length < 4) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> optionalIsland = user.getIsland();
    if (!optionalIsland.isPresent()) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    double amount;
    try {
        amount = Double.parseDouble(args[3]);
    } catch (NumberFormatException exception) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Island island = optionalIsland.get();
    island.setExtraValue(island.getExtraValue() - amount);
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%amount%", String.valueOf(island.getExtraValue()))));
    return true;
}
Also used : User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) 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