Rework the MUtil.getOnlinePlayers slightly again.

This commit is contained in:
Olof Larsson 2014-12-31 11:18:55 +01:00
parent da3549da0e
commit 48291b7c4d

View File

@ -126,18 +126,28 @@ public class MUtil
public static Collection<? extends Player> getOnlinePlayers()
{
// Fetch some kind of playersObject.
Object playersObject = null;
try
{
return Bukkit.getOnlinePlayers();
playersObject = Bukkit.getOnlinePlayers();
}
catch (Throwable e)
catch (Throwable t)
{
// That didn't work!
// We probably just caught a NoSuchMethodError.
// So let's try with reflection instead.
try
{
playersObject = methodGetOnlinePlayers.invoke(null);
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
Object playersObject = methodGetOnlinePlayers.invoke(null);
// Now return the playersObject.
if (playersObject instanceof Collection<?>)
{
@SuppressWarnings("unchecked")
@ -151,16 +161,9 @@ public class MUtil
}
else
{
throw new RuntimeException("Unknown return type for getOnlinePlayers using reflection.");
throw new RuntimeException("Failed retrieving online players.");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
// -------------------------------------------- //
// IS VALID PLAYER NAME