Search in sources :

Example 1 with IslandRegenGUI

use of com.iridium.iridiumskyblock.gui.IslandRegenGUI in project IridiumSkyblock by Iridium-Development.

the class RegenCommand 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).
 * Resets the Island of a user.
 *
 * @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 == 1) {
        if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.REGEN)) {
            player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotRegenIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
            return false;
        }
        player.openInventory(new IslandRegenGUI(player, getCooldownProvider()).getInventory());
        return false;
    }
    Optional<Schematics.SchematicConfig> schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(args[1])).map(Map.Entry::getValue).findFirst();
    if (!schematicConfig.isPresent()) {
        player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownSchematic.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
        return false;
    }
    IridiumSkyblock.getInstance().getIslandManager().regenerateIsland(island.get(), user, schematicConfig.get());
    return true;
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandRegenGUI(com.iridium.iridiumskyblock.gui.IslandRegenGUI) Island(com.iridium.iridiumskyblock.database.Island) Map(java.util.Map)

Aggregations

Island (com.iridium.iridiumskyblock.database.Island)1 User (com.iridium.iridiumskyblock.database.User)1 IslandRegenGUI (com.iridium.iridiumskyblock.gui.IslandRegenGUI)1 Map (java.util.Map)1 Player (org.bukkit.entity.Player)1