add features to our API #943

+ add getRegisteredNames() and getRegisteredRealNames() methods
+ add a new and more clear way to get the API instance
This commit is contained in:
Gabriele C 2016-09-16 20:10:57 +02:00
parent ffc5b77f36
commit 25df3ce032
2 changed files with 34 additions and 1 deletions

View File

@ -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.
*/

View File

@ -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:
* <code>
* NewAPI authmeApi = NewAPI.getInstance();
* NewAPI authmeApi = AuthMe.getApi();
* </code>
*/
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<String> getRegisteredNames() {
List<String> 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<String> getRegisteredRealNames() {
List<String> registeredNames = new ArrayList<>();
dataSource.getAllAuths().forEach(auth -> registeredNames.add(auth.getRealName()));
return registeredNames;
}
}