Search in sources :

Example 1 with IslandWarpsGUI

use of com.iridium.iridiumskyblock.gui.IslandWarpsGUI 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)

Aggregations

StringUtils (com.iridium.iridiumcore.utils.StringUtils)1 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)1 Island (com.iridium.iridiumskyblock.database.Island)1 IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)1 User (com.iridium.iridiumskyblock.database.User)1 IslandWarpsGUI (com.iridium.iridiumskyblock.gui.IslandWarpsGUI)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1