Search in sources :

Example 31 with Island

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

the class BiomeCommand method execute.

@Override
public boolean execute(CommandSender sender, String[] args) {
    final Player player = (Player) sender;
    final User user = this.plugin.getUserManager().getUser(player);
    final Optional<Island> islandOptional = user.getIsland();
    if (!islandOptional.isPresent()) {
        player.sendMessage(StringUtils.color(this.plugin.getMessages().noIsland.replace("%prefix%", plugin.getConfiguration().prefix)));
        return false;
    }
    if (args.length != 2) {
        player.openInventory(new IslandBiomeGUI(1, islandOptional.get(), player.getWorld().getEnvironment(), getCooldownProvider(), player.getOpenInventory().getTopInventory()).getInventory());
        // The BiomeGUI handles the cooldown
        return false;
    }
    final Optional<XBiome> biomeOptional = XBiome.matchXBiome(args[1]);
    // Return if the biome doesn't exist or isn't supported by this version
    if (!biomeOptional.isPresent() || biomeOptional.get().getBiome() == null || biomeOptional.get() == XBiome.THE_VOID) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().invalidBiome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(islandOptional.get(), biomeOptional.get());
    player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().changedBiome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%biome%", WordUtils.capitalizeFully(biomeOptional.get().name().toLowerCase().replace("_", " ")))));
    return true;
}
Also used : Player(org.bukkit.entity.Player) IslandBiomeGUI(com.iridium.iridiumskyblock.gui.IslandBiomeGUI) User(com.iridium.iridiumskyblock.database.User) XBiome(com.iridium.iridiumcore.dependencies.xseries.XBiome) Island(com.iridium.iridiumskyblock.database.Island)

Example 32 with Island

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

the class ChatCommand 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).
 * Chats with the sender's island members {@link 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) {
    Player player = (Player) sender;
    Optional<Island> island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland();
    if (!island.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (args.length > 1) {
        String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
        for (User user : island.get().getMembers()) {
            Player recipient = Bukkit.getPlayer(user.getUuid());
            if (recipient != null) {
                recipient.sendMessage(StringUtils.color(StringUtils.processMultiplePlaceholders(IridiumSkyblock.getInstance().getMessages().islandMemberChat, new PlaceholderBuilder().applyIslandPlaceholders(island.get()).build()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%player%", player.getName()).replace("%message%", message)));
            }
        }
    } else {
        User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
        UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat());
        Bukkit.getPluginManager().callEvent(userChatToggleEvent);
        if (userChatToggleEvent.isCancelled())
            return false;
        user.setIslandChat(!user.isIslandChat());
        player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) UserChatToggleEvent(com.iridium.iridiumskyblock.api.UserChatToggleEvent) User(com.iridium.iridiumskyblock.database.User) PlaceholderBuilder(com.iridium.iridiumskyblock.PlaceholderBuilder) Island(com.iridium.iridiumskyblock.database.Island)

Example 33 with Island

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

the class TransferCommand 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).
 * Transfers Island ownership.
 *
 * @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;
    }
    User islandOwner = island.get().getOwner();
    OfflinePlayer targetPlayer = Bukkit.getServer().getOfflinePlayer(args[1]);
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (!user.getIslandRank().equals(IslandRank.OWNER) && !user.isBypassing()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferOwnership.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (!island.get().equals(targetUser.getIsland().orElse(null))) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (islandOwner.getUuid().equals(targetPlayer.getUniqueId())) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferYourself.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    islandOwner.setIslandRank(IslandRank.CO_OWNER);
    targetUser.setIslandRank(IslandRank.OWNER);
    for (User member : island.get().getMembers()) {
        Player islandMember = Bukkit.getPlayer(member.getUuid());
        if (islandMember == null)
            continue;
        islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().transferredOwnership.replace("%oldowner%", user.getName()).replace("%newowner%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) User(com.iridium.iridiumskyblock.database.User) OfflinePlayer(org.bukkit.OfflinePlayer) Island(com.iridium.iridiumskyblock.database.Island)

Example 34 with Island

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

the class TrustCommand 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 (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (args.length != 2) {
        player.openInventory(new IslandTrustedGUI(island.get()).getInventory());
        return true;
    }
    Player targetPlayer = Bukkit.getPlayer(args[1]);
    if (targetPlayer == null) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer);
    if (targetUser.getIsland().map(Island::getId).orElse(0) == island.get().getId()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyTrusted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IslandTrusted islandTrusted = new IslandTrusted(island.get(), targetUser, user);
    IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().addEntry(islandTrusted);
    island.get().getMembers().stream().map(user1 -> Bukkit.getPlayer(user1.getUuid())).filter(Objects::nonNull).forEach(onlineMember -> onlineMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().trustedPlayer.replace("%truster%", player.getName()).replace("%player%", targetPlayer.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))));
    targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerTrustedYou.replace("%truster%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_TRUSTED, 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) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) IslandTrustedGUI(com.iridium.iridiumskyblock.gui.IslandTrustedGUI) Island(com.iridium.iridiumskyblock.database.Island)

Example 35 with Island

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

the class UnBanCommand 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();
    return island.map(value -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().getEntries(value).stream().map(islandBan -> islandBan.getBannedUser().getName()).collect(Collectors.toList())).orElse(Collections.emptyList());
}
Also used : 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) List(java.util.List) PermissionType(com.iridium.iridiumskyblock.PermissionType) IslandBan(com.iridium.iridiumskyblock.database.IslandBan) Duration(java.time.Duration) Optional(java.util.Optional) Collections(java.util.Collections) IridiumSkyblock(com.iridium.iridiumskyblock.IridiumSkyblock) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) Island(com.iridium.iridiumskyblock.database.Island)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)92 User (com.iridium.iridiumskyblock.database.User)76 Player (org.bukkit.entity.Player)60 EventHandler (org.bukkit.event.EventHandler)18 List (java.util.List)16 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)15 OfflinePlayer (org.bukkit.OfflinePlayer)15 Collectors (java.util.stream.Collectors)14 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)12 Optional (java.util.Optional)11 StringUtils (com.iridium.iridiumcore.utils.StringUtils)10 IslandBank (com.iridium.iridiumskyblock.database.IslandBank)10 Duration (java.time.Duration)10 Collections (java.util.Collections)9 CommandSender (org.bukkit.command.CommandSender)9 XMaterial (com.iridium.iridiumcore.dependencies.xseries.XMaterial)7 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)6 BankItem (com.iridium.iridiumskyblock.bank.BankItem)6 IslandBooster (com.iridium.iridiumskyblock.database.IslandBooster)6 Bukkit (org.bukkit.Bukkit)6