Search in sources :

Example 36 with User

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

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

the class BypassCommand 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).
 * Allows admins to bypass Island restrictions.
 *
 * @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);
    user.setBypassing(!user.isBypassing());
    player.sendMessage(StringUtils.color((user.isBypassing() ? IridiumSkyblock.getInstance().getMessages().nowBypassing : IridiumSkyblock.getInstance().getMessages().noLongerBypassing).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User)

Example 38 with User

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

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

the class ShopCommand 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).
 *
 * @param sender    The CommandSender which executes this command
 * @param arguments The arguments used with this command. They contain the sub-command
 */
@Override
public boolean execute(CommandSender sender, String[] arguments) {
    Player player = (Player) sender;
    User user = IridiumSkyblockAPI.getInstance().getUser(player);
    if (!user.getIsland().isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    if (arguments.length == 1) {
        player.openInventory(new ShopOverviewGUI(player.getOpenInventory().getTopInventory()).getInventory());
    } else {
        String[] commandArguments = Arrays.copyOfRange(arguments, 1, arguments.length);
        String categoryName = String.join(" ", commandArguments);
        Optional<ShopCategory> category = IridiumSkyblock.getInstance().getShopManager().getCategoryByName(categoryName);
        if (!category.isPresent()) {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noShopCategory.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
        player.openInventory(new ShopCategoryGUI(category.get(), player.getOpenInventory().getTopInventory()).getInventory());
    }
    return true;
}
Also used : ShopCategoryGUI(com.iridium.iridiumskyblock.gui.ShopCategoryGUI) Player(org.bukkit.entity.Player) ShopCategory(com.iridium.iridiumskyblock.shop.ShopCategory) User(com.iridium.iridiumskyblock.database.User) ShopOverviewGUI(com.iridium.iridiumskyblock.gui.ShopOverviewGUI)

Example 40 with User

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

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