Skip to content

Commit

Permalink
[build] trigger the github action
Browse files Browse the repository at this point in the history
No longer using reflection to get the player count because we do not need to.
  • Loading branch information
ryderbelserion committed Jun 20, 2024
1 parent 526ba84 commit c8be2a2
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,7 @@ private void appendServiceData(JsonObjectBuilder builder) {
}

private int getPlayerAmount() {
try {
// Around MC 1.8 the return type was changed from an array to a collection,
// This fixes java.lang.NoSuchMethodError:
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
return onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
// Just use the new method if the reflection failed
return Bukkit.getOnlinePlayers().size();
}
return this.plugin.getServer().getOnlinePlayers().size();
}

public static class MetricsBase {
Expand Down

0 comments on commit c8be2a2

Please sign in to comment.