Search in sources :

Example 1 with ShopCategoryGUI

use of com.iridium.iridiumskyblock.gui.ShopCategoryGUI 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)

Aggregations

User (com.iridium.iridiumskyblock.database.User)1 ShopCategoryGUI (com.iridium.iridiumskyblock.gui.ShopCategoryGUI)1 ShopOverviewGUI (com.iridium.iridiumskyblock.gui.ShopOverviewGUI)1 ShopCategory (com.iridium.iridiumskyblock.shop.ShopCategory)1 Player (org.bukkit.entity.Player)1