Search in sources :

Example 26 with User

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

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

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

the class WithdrawCommand 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).
 * Withdraws a currency from the Island bank.
 *
 * @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.WITHDRAW_BANK)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotWithdraw.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<BankItem> bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[1])).findFirst();
    if (!bankItem.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    try {
        double amount = bankItem.get().withdraw(player, Double.parseDouble(args[2]));
        if (amount > 0) {
            IslandLog islandLog = new IslandLog(island.get(), LogAction.BANK_WITHDRAW, user, null, amount, bankItem.get().getName());
            IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
        }
        return true;
    } catch (NumberFormatException exception) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notANumber.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) 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) StringUtils(com.iridium.iridiumcore.utils.StringUtils) LogAction(com.iridium.iridiumskyblock.LogAction) BankItem(com.iridium.iridiumskyblock.bank.BankItem) 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) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) BankItem(com.iridium.iridiumskyblock.bank.BankItem) Island(com.iridium.iridiumskyblock.database.Island)

Example 29 with User

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

the class RemoveCommand 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(islandBank.getNumber() - Double.parseDouble(args[4]), 0));
                    sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().removedBank.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 30 with User

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

the class CreateCommand method createIsland.

/**
 * Creates an island for a specific Player and then teleports them to the island home.
 *
 * @param player          The owner of the island
 * @param name            The name of  the island
 * @param schematicConfig The schematic of the island
 * @return True if the island has been created successfully
 */
private boolean createIsland(Player player, String name, Schematics.SchematicConfig schematicConfig) {
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    if (user.getIsland().isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyHaveIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (name != null && IridiumSkyblock.getInstance().getIslandManager().getIslandByName(name).isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandWithNameAlreadyExists.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandCreateEvent islandCreateEvent = new IslandCreateEvent(user, name, schematicConfig);
    Bukkit.getPluginManager().callEvent(islandCreateEvent);
    if (islandCreateEvent.isCancelled())
        return false;
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().creatingIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IridiumSkyblock.getInstance().getIslandManager().createIsland(player, islandCreateEvent.getIslandName(), islandCreateEvent.getSchematicConfig()).thenAccept(island -> Bukkit.getScheduler().runTask(IridiumSkyblock.getInstance(), () -> {
        IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island, 0);
        IridiumSkyblock.getInstance().getNms().sendTitle(player, IridiumSkyblock.getInstance().getConfiguration().islandCreateTitle, IridiumSkyblock.getInstance().getConfiguration().islandCreateSubTitle, 20, 40, 20);
    }));
    return true;
}
Also used : User(com.iridium.iridiumskyblock.database.User) IslandCreateEvent(com.iridium.iridiumskyblock.api.IslandCreateEvent)

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