From 25df3ce032f2b4d5c22d738a137d5292482cd30d Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 16 Sep 2016 20:10:57 +0200 Subject: [PATCH] add features to our API #943 + add getRegisteredNames() and getRegisteredRealNames() methods + add a new and more clear way to get the API instance --- src/main/java/fr/xephi/authme/AuthMe.java | 9 +++++++ src/main/java/fr/xephi/authme/api/NewAPI.java | 26 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 42b3bc33..a19aab97 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -119,6 +119,15 @@ public class AuthMe extends JavaPlugin { return pluginBuildNumber; } + /** + * Method used to obtain the plugin's api instance + * + * @return The plugin's api instance + */ + public static NewAPI getApi() { + return NewAPI.getInstance(); + } + /** * Method called when the server enables the plugin. */ diff --git a/src/main/java/fr/xephi/authme/api/NewAPI.java b/src/main/java/fr/xephi/authme/api/NewAPI.java index 6b87cb53..c77affa9 100644 --- a/src/main/java/fr/xephi/authme/api/NewAPI.java +++ b/src/main/java/fr/xephi/authme/api/NewAPI.java @@ -14,11 +14,13 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; /** * The current API of AuthMe. Recommended method of retrieving the API object: * - * NewAPI authmeApi = NewAPI.getInstance(); + * NewAPI authmeApi = AuthMe.getApi(); * */ public class NewAPI { @@ -218,4 +220,26 @@ public class NewAPI { public void forceUnregister(Player player) { management.performUnregisterByAdmin(null, player.getName(), player); } + + /** + * Get all the registered names (lowercase) + * + * @return registered names + */ + public List getRegisteredNames() { + List registeredNames = new ArrayList<>(); + dataSource.getAllAuths().forEach(auth -> registeredNames.add(auth.getNickname())); + return registeredNames; + } + + /** + * Get all the registered real-names (original case) + * + * @return registered real-names + */ + public List getRegisteredRealNames() { + List registeredNames = new ArrayList<>(); + dataSource.getAllAuths().forEach(auth -> registeredNames.add(auth.getRealName())); + return registeredNames; + } }