Search in sources :

Example 1 with IslandWarp

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

the class IslandWarpsGUI 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<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(getIsland());
    Collections.reverse(islandWarps);
    AtomicInteger atomicInteger = new AtomicInteger(1);
    for (IslandWarp islandWarp : islandWarps) {
        if (IridiumSkyblock.getInstance().getConfiguration().islandWarpSlots.get(atomicInteger.getAndIncrement()) == event.getSlot()) {
            switch(event.getClick()) {
                case LEFT:
                    IridiumSkyblock.getInstance().getCommands().warpsCommand.execute(event.getWhoClicked(), new String[] { "", islandWarp.getName() });
                    break;
                case RIGHT:
                    IridiumSkyblock.getInstance().getCommands().deleteWarpCommand.execute(event.getWhoClicked(), new String[] { "", islandWarp.getName() });
                    break;
            }
            addContent(event.getInventory());
            return;
        }
    }
}
Also used : IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with IslandWarp

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

the class WarpsCommand method onTabComplete.

/**
 * Handles tab-completion for this command.
 *
 * @param commandSender The CommandSender which tries to tab-complete
 * @param command       The command
 * @param label         The label of the command
 * @param args          The arguments already provided by the sender
 * @return The list of tab completions for this command
 */
@Override
public List<String> onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) {
    Player player = (Player) commandSender;
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<Island> island = user.getIsland();
    if (island.isPresent()) {
        List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get());
        return islandWarps.stream().map(IslandWarp::getName).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) Island(com.iridium.iridiumskyblock.database.Island)

Example 3 with IslandWarp

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

the class WarpsCommand 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) {
    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 (args.length != 2 && args.length != 3) {
        player.openInventory(new IslandWarpsGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
        return true;
    }
    List<IslandWarp> islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get());
    Optional<IslandWarp> islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!islandWarp.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (islandWarp.get().getPassword() != null) {
        if (args.length != 3) {
            sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%warp%", args[1])));
            return false;
        }
        if (!islandWarp.get().getPassword().equals(args[2])) {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().incorrectPassword.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
    }
    IridiumSkyblock.getInstance().getIslandManager().teleportWarp(player, islandWarp.get(), IridiumSkyblock.getInstance().getConfiguration().teleportDelay);
    return true;
}
Also used : CommandSender(org.bukkit.command.CommandSender) Arrays(java.util.Arrays) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) IslandWarpsGUI(com.iridium.iridiumskyblock.gui.IslandWarpsGUI) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) List(java.util.List) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) Island(com.iridium.iridiumskyblock.database.Island) IslandWarpsGUI(com.iridium.iridiumskyblock.gui.IslandWarpsGUI)

Example 4 with IslandWarp

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

the class EditWarpCommand 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 < 3) {
        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());
    Optional<IslandWarp> islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!islandWarp.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    // TODO: Use subcommand system
    switch(args[2]) {
        case "icon":
            if (args.length != 4) {
                sender.sendMessage("/is editwarp <name> icon <icon>");
            }
            Optional<XMaterial> xMaterial = XMaterial.matchXMaterial(args[3]);
            if (xMaterial.isPresent()) {
                islandWarp.get().setIcon(xMaterial.get());
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpIconSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                return true;
            } else {
                player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchMaterial.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                return false;
            }
        case "description":
            if (args.length < 4) {
                sender.sendMessage("/is editwarp <name> description <description>");
                return false;
            }
            String description = String.join(" ", Arrays.copyOfRange(args, 3, args.length));
            islandWarp.get().setDescription(description);
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpDescriptionSet.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return true;
    }
    return false;
}
Also used : Arrays(java.util.Arrays) CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) List(java.util.List) PermissionType(com.iridium.iridiumskyblock.PermissionType) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) XMaterial(com.iridium.iridiumcore.dependencies.xseries.XMaterial) Island(com.iridium.iridiumskyblock.database.Island)

Example 5 with IslandWarp

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

the class DeleteWarpCommand 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());
    Optional<IslandWarp> islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!islandWarp.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().deletingWarp.replace("%name%", islandWarp.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().delete(islandWarp.get());
    return true;
}
Also used : CommandSender(org.bukkit.command.CommandSender) Arrays(java.util.Arrays) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) List(java.util.List) PermissionType(com.iridium.iridiumskyblock.PermissionType) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) 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