Search in sources :

Example 1 with AlreadyActivatedException

use of com.github.ygimenez.exception.AlreadyActivatedException in project Pagination-Utils by ygimenez.

the class Pages method activate.

/**
 * Sets a {@link Paginator} object to handle incoming reactions. This is
 * required only once unless you want to use another client as the handler. <br>
 * <br>
 * Before calling this method again, you must use {@link #deactivate()} to
 * remove current {@link Paginator}, else this method will throw
 * {@link AlreadyActivatedException}.
 *
 * @param paginator The {@link Paginator} object.
 * @throws AlreadyActivatedException Thrown if there's a handler already set.
 * @throws InvalidHandlerException   Thrown if the handler isn't either a {@link JDA}
 *                                   or {@link ShardManager} object.
 */
public static void activate(@Nonnull Paginator paginator) throws InvalidHandlerException {
    if (isActivated())
        throw new AlreadyActivatedException();
    Object hand = paginator.getHandler();
    if (hand instanceof JDA)
        ((JDA) hand).addEventListener(handler);
    else if (hand instanceof ShardManager)
        ((ShardManager) hand).addEventListener(handler);
    else
        throw new InvalidHandlerException();
    Pages.paginator = paginator;
    paginator.log(PUtilsConfig.LogLevel.LEVEL_2, "Pagination Utils activated successfully");
}
Also used : JDA(net.dv8tion.jda.api.JDA) ShardManager(net.dv8tion.jda.api.sharding.ShardManager) InvalidHandlerException(com.github.ygimenez.exception.InvalidHandlerException) AlreadyActivatedException(com.github.ygimenez.exception.AlreadyActivatedException)

Aggregations

AlreadyActivatedException (com.github.ygimenez.exception.AlreadyActivatedException)1 InvalidHandlerException (com.github.ygimenez.exception.InvalidHandlerException)1 JDA (net.dv8tion.jda.api.JDA)1 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)1