2016-07-21 22:40:24 +02:00
|
|
|
package me.lucko.luckperms;
|
|
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
import me.lucko.luckperms.api.LuckPermsApi;
|
|
|
|
|
2016-08-06 00:11:00 +02:00
|
|
|
import java.util.Optional;
|
|
|
|
|
2016-07-21 22:40:24 +02:00
|
|
|
/**
|
|
|
|
* Static access to LuckPerms
|
|
|
|
*/
|
|
|
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
2016-08-06 00:11:00 +02:00
|
|
|
public final class LuckPerms {
|
2016-07-21 22:40:24 +02:00
|
|
|
|
|
|
|
private static LuckPermsApi api = null;
|
|
|
|
|
2016-08-06 00:11:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an instance of {@link LuckPermsApi}
|
|
|
|
* @return an api instance
|
|
|
|
* @throws IllegalStateException if the api is not loaded
|
|
|
|
*/
|
2016-07-21 22:40:24 +02:00
|
|
|
public static LuckPermsApi getApi() {
|
|
|
|
if (api == null) {
|
|
|
|
throw new IllegalStateException("API is not loaded.");
|
|
|
|
}
|
|
|
|
return api;
|
|
|
|
}
|
|
|
|
|
2016-08-06 00:11:00 +02:00
|
|
|
/**
|
|
|
|
* Gets an instance of {@link LuckPermsApi} safely. Unlike {@link LuckPerms#getApi}, this method will not throw an
|
|
|
|
* {@link IllegalStateException} if the api is not loaded, rather return an empty {@link Optional}.
|
|
|
|
* @return an optional api instance
|
|
|
|
*/
|
|
|
|
public static Optional<LuckPermsApi> getApiSafe() {
|
|
|
|
return Optional.ofNullable(api);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:40:24 +02:00
|
|
|
static void registerProvider(LuckPermsApi luckPermsApi) {
|
|
|
|
api = luckPermsApi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unregisterProvider() {
|
|
|
|
api = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|