Search in sources :

Example 1 with IslandUpgrade

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

the class JoinCommand 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).
 * Enables users to join other Islands.
 *
 * @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);
    if (user.getIsland().isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyHaveIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
    User offlinePlayerUser = IridiumSkyblock.getInstance().getUserManager().getUser(offlinePlayer);
    Optional<Island> island = offlinePlayerUser.getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<IslandInvite> islandInvite = IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), user);
    if (!islandInvite.isPresent() && !user.isBypassing()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noInvite.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "member");
    int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount;
    if (!user.isBypassing() && island.get().getMembers().size() >= memberLimit) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandMemberLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<User> inviter = islandInvite.map(IslandInvite::getInviter);
    UserJoinEvent userJoinEvent = new UserJoinEvent(island.get(), user, inviter.orElse(null));
    Bukkit.getPluginManager().callEvent(userJoinEvent);
    if (userJoinEvent.isCancelled())
        return false;
    // Send a message to all other members
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getName());
        if (islandMember != null) {
            islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerJoinedYourIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        }
    }
    user.setIsland(island.get());
    user.setIslandRank(IslandRank.MEMBER);
    islandInvite.ifPresent(invite -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().delete(invite));
    IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, island.get(), 0);
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_JOINED, user, null, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) IslandInvite(com.iridium.iridiumskyblock.database.IslandInvite) UserJoinEvent(com.iridium.iridiumskyblock.api.UserJoinEvent) Island(com.iridium.iridiumskyblock.database.Island)

Example 2 with IslandUpgrade

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

the class UpgradesCommand 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) {
        player.openInventory(new IslandUpgradesGUI(island.get(), player.getOpenInventory().getTopInventory()).getInventory());
        return true;
    }
    String upgradeName = args[1];
    Upgrade<?> upgrade = IridiumSkyblock.getInstance().getUpgradesList().get(upgradeName);
    if (upgrade == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), upgradeName);
    UpgradeData upgradeData = upgrade.upgrades.get(islandUpgrade.getLevel() + 1);
    if (upgradeData == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().maxLevelReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!PlayerUtils.pay(player, island.get(), upgradeData.crystals, upgradeData.money)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    islandUpgrade.setLevel(islandUpgrade.getLevel() + 1);
    IslandLog islandLog = new IslandLog(island.get(), LogAction.UPGRADE_PURCHASE, user, null, 0, upgradeName);
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    IridiumSkyblock.getInstance().getIslandManager().sendIslandBorder(island.get());
    island.get().resetCache();
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().successfullyBoughtUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%upgrade%", upgrade.name).replace("%vault_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.money)).replace("%crystal_cost%", IridiumSkyblock.getInstance().getNumberFormatter().format(upgradeData.crystals))));
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) UpgradeData(com.iridium.iridiumskyblock.upgrades.UpgradeData) IslandUpgradesGUI(com.iridium.iridiumskyblock.gui.IslandUpgradesGUI) Island(com.iridium.iridiumskyblock.database.Island)

Example 3 with IslandUpgrade

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

the class PlaceholderBuilder method applyIslandPlaceholders.

public PlaceholderBuilder applyIslandPlaceholders(Island island) {
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island, "member");
    int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount;
    placeholderList.add(new Placeholder("island_name", island.getName()));
    placeholderList.add(new Placeholder("island_owner", island.getOwner().getName()));
    placeholderList.add(new Placeholder("island_value", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getValue())));
    placeholderList.add(new Placeholder("island_rank", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getRank())));
    placeholderList.add(new Placeholder("island_members", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getMembers().size())));
    placeholderList.add(new Placeholder("island_members_limit", IridiumSkyblock.getInstance().getNumberFormatter().format(memberLimit)));
    placeholderList.add(new Placeholder("island_level", IridiumSkyblock.getInstance().getNumberFormatter().format(island.getLevel())));
    placeholderList.add(new Placeholder("island_create", island.getCreateTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))));
    IridiumSkyblock.getInstance().getBlockValues().blockValues.keySet().stream().map(material -> new Placeholder(material.name() + "_AMOUNT", IridiumSkyblock.getInstance().getNumberFormatter().format(IridiumSkyblock.getInstance().getIslandManager().getIslandBlockAmount(island, material)))).forEach(placeholderList::add);
    return this;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) List(java.util.List) IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) User(com.iridium.iridiumskyblock.database.User) DateTimeFormatter(java.time.format.DateTimeFormatter) Island(com.iridium.iridiumskyblock.database.Island) Placeholder(com.iridium.iridiumcore.utils.Placeholder) ArrayList(java.util.ArrayList) Placeholder(com.iridium.iridiumcore.utils.Placeholder)

Example 4 with IslandUpgrade

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

the class SetWarpCommand 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 < 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 (!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());
    if (islandWarps.stream().anyMatch(islandWarp -> islandWarp.getName().equalsIgnoreCase(args[1]))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpAlreadyExists.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "warp");
    if (islandWarps.size() >= IridiumSkyblock.getInstance().getUpgrades().warpsUpgrade.upgrades.get(islandUpgrade.getLevel()).amount) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!island.get().isInIsland(player.getLocation())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().onlySetWarpOnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!LocationUtils.isSafe(player.getLocation())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notSafe.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandWarp islandWarp = new IslandWarp(island.get(), player.getLocation(), args[1]);
    if (args.length == 3) {
        islandWarp.setPassword(args[2]);
    }
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().addEntry(islandWarp);
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().createdWarp.replace("%name%", args[1]).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    return true;
}
Also used : IslandUpgrade(com.iridium.iridiumskyblock.database.IslandUpgrade) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandWarp(com.iridium.iridiumskyblock.database.IslandWarp) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)4 IslandUpgrade (com.iridium.iridiumskyblock.database.IslandUpgrade)4 User (com.iridium.iridiumskyblock.database.User)4 Player (org.bukkit.entity.Player)3 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 UserJoinEvent (com.iridium.iridiumskyblock.api.UserJoinEvent)1 IslandInvite (com.iridium.iridiumskyblock.database.IslandInvite)1 IslandWarp (com.iridium.iridiumskyblock.database.IslandWarp)1 IslandUpgradesGUI (com.iridium.iridiumskyblock.gui.IslandUpgradesGUI)1 UpgradeData (com.iridium.iridiumskyblock.upgrades.UpgradeData)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OfflinePlayer (org.bukkit.OfflinePlayer)1