Rework the MUtil.getOnlinePlayers slightly again.
This commit is contained in:
parent
da3549da0e
commit
48291b7c4d
@ -126,18 +126,28 @@ public class MUtil
|
|||||||
|
|
||||||
public static Collection<? extends Player> getOnlinePlayers()
|
public static Collection<? extends Player> getOnlinePlayers()
|
||||||
{
|
{
|
||||||
|
// Fetch some kind of playersObject.
|
||||||
|
Object playersObject = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Bukkit.getOnlinePlayers();
|
playersObject = Bukkit.getOnlinePlayers();
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable t)
|
||||||
{
|
{
|
||||||
|
// That didn't work!
|
||||||
// We probably just caught a NoSuchMethodError.
|
// We probably just caught a NoSuchMethodError.
|
||||||
|
// So let's try with reflection instead.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
playersObject = methodGetOnlinePlayers.invoke(null);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
// Now return the playersObject.
|
||||||
{
|
|
||||||
Object playersObject = methodGetOnlinePlayers.invoke(null);
|
|
||||||
if (playersObject instanceof Collection<?>)
|
if (playersObject instanceof Collection<?>)
|
||||||
{
|
{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -151,16 +161,9 @@ public class MUtil
|
|||||||
}
|
}
|
||||||
else
|
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
|
// IS VALID PLAYER NAME
|
||||||
|
Loading…
Reference in New Issue
Block a user