Search in sources :

Example 1 with IslandInvite

use of com.iridium.iridiumskyblock.database.IslandInvite 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 IslandInvite

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

the class UnInviteCommand 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).
 * Un-Invites a User 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();
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(Bukkit.getServer().getOfflinePlayer(args[1]));
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    Optional<IslandInvite> islandInvite = IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), targetUser);
    if (!islandInvite.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noActiveInvite.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().delete(islandInvite.get());
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inviteRevoked.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_UNINVITED, user, targetUser, 0, "");
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog);
    return true;
}
Also used : IslandLog(com.iridium.iridiumskyblock.database.IslandLog) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandInvite(com.iridium.iridiumskyblock.database.IslandInvite) Island(com.iridium.iridiumskyblock.database.Island)

Example 3 with IslandInvite

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

the class IslandInvitesGUI method addContent.

@Override
public void addContent(Inventory inventory) {
    List<IslandInvite> islandInvites = IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().getEntries(getIsland());
    inventory.clear();
    InventoryUtils.fillInventory(inventory, getNoItemGUI().background);
    AtomicInteger slot = new AtomicInteger(0);
    for (int i = 0; i < islandInvites.size(); i++) {
        Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> {
            int itemSlot = slot.getAndIncrement();
            List<Placeholder> placeholderList = new PlaceholderBuilder().applyPlayerPlaceholders(islandInvites.get(itemSlot).getUser()).applyIslandPlaceholders(getIsland()).build();
            placeholderList.add(new Placeholder("inviter", islandInvites.get(itemSlot).getInviter().getName()));
            placeholderList.add(new Placeholder("time", islandInvites.get(itemSlot).getTime().format(DateTimeFormatter.ofPattern(IridiumSkyblock.getInstance().getConfiguration().dateTimeFormat))));
            inventory.setItem(itemSlot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().islandInvitesGUI.item, placeholderList));
            invites.put(itemSlot, islandInvites.get(itemSlot).getUser().getName());
        });
    }
    if (IridiumSkyblock.getInstance().getConfiguration().backButtons && getPreviousInventory() != null) {
        inventory.setItem(inventory.getSize() + IridiumSkyblock.getInstance().getInventories().backButton.slot, ItemStackUtils.makeItem(IridiumSkyblock.getInstance().getInventories().backButton));
    }
}
Also used : Placeholder(com.iridium.iridiumcore.utils.Placeholder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) IslandInvite(com.iridium.iridiumskyblock.database.IslandInvite)

Aggregations

IslandInvite (com.iridium.iridiumskyblock.database.IslandInvite)3 Island (com.iridium.iridiumskyblock.database.Island)2 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)2 User (com.iridium.iridiumskyblock.database.User)2 Player (org.bukkit.entity.Player)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)1 UserJoinEvent (com.iridium.iridiumskyblock.api.UserJoinEvent)1 IslandUpgrade (com.iridium.iridiumskyblock.database.IslandUpgrade)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 OfflinePlayer (org.bukkit.OfflinePlayer)1