Search in sources :

Example 1 with IslandVisitorsGUI

use of com.iridium.iridiumskyblock.gui.IslandVisitorsGUI in project IridiumSkyblock by Iridium-Development.

the class ExpelCommand 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).
 * Kicks a visitor from an Island.
 *
 * @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 (args.length == 1) {
        player.openInventory(new IslandVisitorsGUI(1, island.get()).getInventory());
        return true;
    }
    Player targetPlayer = Bukkit.getPlayer(args[1]);
    if (targetPlayer == null) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (island.get().equals(targetUser.getIsland().orElse(null)) || IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inYourTeam.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!island.get().isInIsland(targetPlayer.getLocation())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotVisitingYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (targetUser.isBypassing() || targetPlayer.hasPermission("iridiumskyblock.visitbypass")) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotExpelPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.EXPEL)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenExpelled.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().expelledVisitor.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    PlayerUtils.teleportSpawn(targetPlayer);
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandVisitorsGUI(com.iridium.iridiumskyblock.gui.IslandVisitorsGUI) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)1 User (com.iridium.iridiumskyblock.database.User)1 IslandVisitorsGUI (com.iridium.iridiumskyblock.gui.IslandVisitorsGUI)1 Player (org.bukkit.entity.Player)1