Search in sources :

Example 91 with User

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

the class BanCommand 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).
 * Bans a player visiting 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 IslandBansGUI(1, island.get(), player.getOpenInventory().getTopInventory()).getInventory());
        return false;
    }
    if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.BAN)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    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 (targetUser.isBypassing() || targetPlayer.hasPermission("iridiumskyblock.visitbypass")) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (IridiumSkyblock.getInstance().getIslandManager().isBannedOnIsland(island.get(), targetUser)) {
        sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().addEntry(new IslandBan(island.get(), user, targetUser));
    if (island.get().isInIsland(targetPlayer.getLocation())) {
        PlayerUtils.teleportSpawn(targetPlayer);
        targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerBanned.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandBan(com.iridium.iridiumskyblock.database.IslandBan) IslandBansGUI(com.iridium.iridiumskyblock.gui.IslandBansGUI) Island(com.iridium.iridiumskyblock.database.Island)

Example 92 with User

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

the class GiveCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length == 5) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        Optional<Island> island = user.getIsland();
        if (island.isPresent()) {
            Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[3])).findFirst();
            if (bankItem.isPresent()) {
                try {
                    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), bankItem.get());
                    islandBank.setNumber(islandBank.getNumber() + Double.parseDouble(args[4]));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().gaveBank.replace("%player%", player.getName()).replace("%amount%", args[4]).replace("%item%", bankItem.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                    return true;
                } catch (NumberFormatException exception) {
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            } else {
                sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        } else {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return false;
}
Also used : CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Duration(java.time.Duration) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) Optional(java.util.Optional) Command(com.iridium.iridiumskyblock.commands.Command) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Bukkit(org.bukkit.Bukkit) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Example 93 with User

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

the class SetCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) {
    if (args.length == 5) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[2]);
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        Optional<Island> island = user.getIsland();
        if (island.isPresent()) {
            Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[3])).findFirst();
            if (bankItem.isPresent()) {
                try {
                    IslandBank islandBank = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island.get(), bankItem.get());
                    islandBank.setNumber(Math.max(Double.parseDouble(args[4]), 0));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().setBank.replace("%player%", player.getName()).replace("%amount%", args[4]).replace("%item%", bankItem.get().getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                    return true;
                } catch (NumberFormatException exception) {
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
                }
            } else {
                sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            }
        } else {
            sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    } else {
        sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return false;
}
Also used : CommandSender(org.bukkit.command.CommandSender) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island) Collectors(java.util.stream.Collectors) StringUtils(com.iridium.iridiumcore.utils.StringUtils) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) List(java.util.List) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) Duration(java.time.Duration) PlayerUtils(com.iridium.iridiumskyblock.utils.PlayerUtils) Optional(java.util.Optional) Command(com.iridium.iridiumskyblock.commands.Command) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Bukkit(org.bukkit.Bukkit) IslandBank(com.iridium.iridiumskyblock.database.IslandBank) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Example 94 with User

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

the class Reward method claim.

/**
 * Claims this reward for the provided user and island.
 * Sets the experience, executes the commands and plays the sound.
 *
 * @param player The Player which should receive the reward
 * @param island The Island of the Player
 */
public void claim(Player player, Island island) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    island.setExperience(island.getTotalExperience() + islandExperience);
    commands.forEach(command -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("%player%", player.getName())));
    sound.play(player);
    IslandBank islandCrystals = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().crystalsBankItem);
    IslandBank islandExperience = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().experienceBankItem);
    IslandBank islandMoney = IridiumSkyblock.getInstance().getIslandManager().getIslandBank(island, IridiumSkyblock.getInstance().getBankItems().moneyBankItem);
    islandCrystals.setNumber(islandCrystals.getNumber() + crystals);
    islandExperience.setNumber(islandExperience.getNumber() + experience);
    islandMoney.setNumber(islandMoney.getNumber() + money);
    IslandLog islandLog = new IslandLog(island, LogAction.REWARD_REDEEMED, user, null, 0, ChatColor.stripColor(item.displayName));
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
}
Also used : IslandBank(com.iridium.iridiumskyblock.database.IslandBank) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) User(com.iridium.iridiumskyblock.database.User)

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