Created
February 2, 2017 08:55
-
-
Save Scarsz/33b3215f972fd67860b88aab3efc425c to your computer and use it in GitHub Desktop.
Backwards-compatible Server::getOnlinePlayers::size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int getOnlinePlayers() { | |
try { | |
Method onlinePlayerMethod = Server.class.getMethod("getOnlinePlayers"); | |
if (onlinePlayerMethod.getReturnType().equals(Collection.class)) { | |
return ((Collection<?>) onlinePlayerMethod.invoke(Bukkit.getServer())).size(); | |
} else { | |
return ((Player[]) onlinePlayerMethod.invoke(Bukkit.getServer())).length; | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment