Search in sources :

Example 6 with IslandWarp

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

the class IslandWarpsGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    inventory.clear();
    InventoryUtils.fillInventory(inventory, IridiumSkyblock.getInstance().getInventories().warpsGUI.background);
    AtomicInteger atomicInteger = new AtomicInteger(1);
    List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(getIsland());
    Collections.reverse(islandWarps);
    for (IslandWarp islandWarp : islandWarps) {
        int slot = IridiumSkyblock.getInstance().getConfiguration().islandWarpSlots.get(atomicInteger.getAndIncrement());
        ItemStack itemStack = ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().warpsGUI.item, Arrays.asList(new Placeholder("island_name", getIsland().getName()), new Placeholder("warp_name", islandWarp.getName()), new Placeholder("description", islandWarp.getDescription() != null ? islandWarp.getDescription() : "")));
        Material material = islandWarp.getIcon().parseMaterial();
        if (material != null)
            itemStack.setType(material);
        inventory.setItem(slot, itemStack);
    }
    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) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with IslandWarp

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

the class SetWarpCommand 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).
 * Shows an overview over the members of the Island and allows quick rank management.
 *
 * @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 < 2) {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Player player = (Player) sender;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.MANAGE_WARPS)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageWarps.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get());
    if (islandWarps.stream().anyMatch(islandWarp -> islandWarp.getName().equalsIgnoreCase(args[1]))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpAlreadyExists.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "warp");
    if (islandWarps.size() >= IridiumSkyblock.getInstance().getUpgrades().warpsUpgrade.upgrades.get(islandUpgrade.getLevel()).amount) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!island.get().isInIsland(player.getLocation())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().onlySetWarpOnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!LocationUtils.isSafe(player.getLocation())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notSafe.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandWarp islandWarp = new IslandWarp(island.get(), player.getLocation(), args[1]);
    if (args.length == 3) {
        islandWarp.setPassword(args[2]);
    }
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().addEntry(islandWarp);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().createdWarp.replace("%name%", args[1]).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)7 Island (com.iridium.iridiumskyblock.database.Island)5 User (com.iridium.iridiumskyblock.database.User)5 Player (org.bukkit.entity.Player)5 StringUtils (com.iridium.iridiumcore.utils.StringUtils)3 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)3 Duration (java.time.Duration)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 CommandSender (org.bukkit.command.CommandSender)3 PermissionType (com.iridium.iridiumskyblock.PermissionType)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)1 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 IslandUpgrade (com.iridium.iridiumskyblock.database.IslandUpgrade)1 IslandWarpsGUI (com.iridium.iridiumskyblock.gui.IslandWarpsGUI)1