Use Google commons
This commit is contained in:
parent
0a0c2dbe1b
commit
9fd007bfb1
@ -12,6 +12,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ServerUtils {
|
||||
/**
|
||||
* Get server's TPS
|
||||
@ -20,21 +22,17 @@ public class ServerUtils {
|
||||
* @return double array of TPS (not rounded!), values are -1 if reflection failed
|
||||
*/
|
||||
public static double[] getTPS(){
|
||||
if(Bukkit.getVersion().contains("Paper")) {
|
||||
if(Reflect.getMethod(Bukkit.class, "getTps") != null) {
|
||||
return Bukkit.getTPS();
|
||||
} else {
|
||||
Class<?> MinecraftServerClass = Reflect.getClass(
|
||||
String.format("net.minecraft.server.%s.MinecraftServer", getNmsVersion()));
|
||||
if(MinecraftServerClass != null){
|
||||
Method getServer = Reflect.getMethod(MinecraftServerClass, "getServer");
|
||||
Field recentTPS = Reflect.getField(MinecraftServerClass, "recentTps");
|
||||
if(getServer != null && recentTPS != null){
|
||||
Object server = Reflect.invokeMethod(getServer, null);
|
||||
try {
|
||||
return (double[]) Reflect.readField(recentTPS, server);
|
||||
} catch (NullPointerException e){}
|
||||
}
|
||||
}
|
||||
try {
|
||||
Class<?> MinecraftServerClass = checkNotNull(Reflect.getClass(
|
||||
String.format("net.minecraft.server.%s.MinecraftServer", getNmsVersion())));
|
||||
Method getServer = checkNotNull(Reflect.getMethod(MinecraftServerClass, "getServer"));
|
||||
Field recentTPS = checkNotNull(Reflect.getField(MinecraftServerClass, "recentTps"));
|
||||
Object server = checkNotNull(Reflect.invokeMethod(getServer, null));
|
||||
return (double[]) checkNotNull(Reflect.readField(recentTPS, server));
|
||||
} catch (NullPointerException ignored){}
|
||||
}
|
||||
return new double[]{-1, -1, -1};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user