use of com.github.ygimenez.exception.InvalidHandlerException 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");
}
Aggregations