Search in sources :

Example 31 with User

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

the class DemoteCommand 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).
 * Demotes a user in the Island rank system.
 *
 * @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;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
    User offlinePlayerUser = IridiumSkyblock.getInstance().getUserManager().getUser(offlinePlayer);
    if (!island.get().equals(offlinePlayerUser.getIsland().orElse(null))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandRank nextRank = IslandRank.getByLevel(offlinePlayerUser.getIslandRank().getLevel() - 1);
    if (nextRank == null || offlinePlayerUser.getIslandRank().getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.DEMOTE)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotDemoteUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (nextRank.equals(IslandRank.VISITOR)) {
        IridiumSkyblock.getInstance().getCommands().kickCommand.execute(sender, args);
        return true;
    }
    UserDemoteEvent userDemoteEvent = new UserDemoteEvent(island.get(), user, nextRank);
    Bukkit.getPluginManager().callEvent(userDemoteEvent);
    if (userDemoteEvent.isCancelled())
        return false;
    offlinePlayerUser.setIslandRank(nextRank);
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getUuid());
        if (islandMember == null)
            continue;
        if (islandMember.equals(player)) {
            islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().demotedPlayer.replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        } else {
            islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userDemotedPlayer.replace("%promoter%", player.getName()).replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    }
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_DEMOTED, user, offlinePlayerUser, 0, nextRank.getDisplayName());
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) IslandRank(com.iridium.iridiumskyblock.IslandRank) OfflinePlayer(org.bukkit.OfflinePlayer) UserDemoteEvent(com.iridium.iridiumskyblock.api.UserDemoteEvent) Island(com.iridium.iridiumskyblock.database.Island)

Example 32 with User

use of com.iridium.iridiumskyblock.database.User 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 33 with User

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

the class ExtraValueCommand 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).
 * Gives extra values to specific player's 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 < 3) {
        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> island = user.getIsland();
    if (!island.isPresent()) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().extraValueInfo.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName())).replace("%amount%", String.valueOf(island.get().getExtraValue())));
    return true;
}
Also used : User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Example 34 with User

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

the class FlyCommand 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 = IridiumSkyblock.getInstance().getIslandManager().getIslandViaPlayerLocation(player);
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notOnAnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    boolean flight = !user.isFlying();
    if (args.length == 2) {
        if (!args[1].equalsIgnoreCase("enable") && !args[1].equalsIgnoreCase("disable") && !args[1].equalsIgnoreCase("on") && !args[1].equalsIgnoreCase("off")) {
            sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
        flight = args[1].equalsIgnoreCase("enable") || args[1].equalsIgnoreCase("on");
    }
    IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), "flight");
    if (!islandBooster.isActive() && !player.hasPermission("iridiumskyblock.fly")) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightBoosterNotActive.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    user.setFlying(flight);
    player.setAllowFlight(flight);
    player.setFlying(flight);
    if (flight) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightEnabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    } else {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandBooster(com.iridium.iridiumskyblock.database.IslandBooster) Island(com.iridium.iridiumskyblock.database.Island)

Example 35 with User

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

the class BankCommand 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).
 * Opens the Island bank GUI.
 *
 * @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;
    }
    player.openInventory(new IslandBankGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) IslandBankGUI(com.iridium.iridiumskyblock.gui.IslandBankGUI)

Aggregations

User (com.iridium.iridiumskyblock.database.User)94 Island (com.iridium.iridiumskyblock.database.Island)73 Player (org.bukkit.entity.Player)66 OfflinePlayer (org.bukkit.OfflinePlayer)16 EventHandler (org.bukkit.event.EventHandler)16 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)13 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)12 List (java.util.List)12 Optional (java.util.Optional)11 Collectors (java.util.stream.Collectors)11 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 StringUtils (com.iridium.iridiumcore.utils.StringUtils)9 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)5 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)5 IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)5 IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)5