Add V1_7_10 to LibVersion for spigot's 1.8 hack

This commit is contained in:
libraryaddict 2014-09-15 02:06:35 +12:00
parent 17822426ab
commit 572ebf1bc5

View File

@ -29,7 +29,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
public class ReflectionManager { public class ReflectionManager {
public enum LibVersion { public enum LibVersion {
V1_6, V1_7, V1_7_6, V1_8; V1_6, V1_7, V1_7_6, V1_7_10, V1_8;
private static LibVersion currentVersion = LibVersion.V1_7; private static LibVersion currentVersion = LibVersion.V1_7;
static { static {
String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", ""); String mcVersion = Bukkit.getVersion().split("MC: ")[1].replace(")", "");
@ -37,8 +37,11 @@ public class ReflectionManager {
if (mcVersion.compareTo("1.7") < 0) { if (mcVersion.compareTo("1.7") < 0) {
currentVersion = LibVersion.V1_6; currentVersion = LibVersion.V1_6;
} else { } else {
currentVersion = mcVersion.compareTo("1.7.6") < 0 && !mcVersion.equals("1.7.10") ? LibVersion.V1_7 if (mcVersion.equals("1.7.10")) {
: LibVersion.V1_7_6; currentVersion = LibVersion.V1_7_10;
} else {
currentVersion = mcVersion.compareTo("1.7.6") < 0 ? LibVersion.V1_7 : LibVersion.V1_7_6;
}
} }
} }
} }
@ -52,12 +55,16 @@ public class ReflectionManager {
} }
public static boolean is1_7() { public static boolean is1_7() {
return getGameVersion() == V1_7 || is1_7_6(); return getGameVersion() == V1_7 || is1_7_6() || is1_7_10();
} }
public static boolean is1_7_6() { public static boolean is1_7_6() {
return getGameVersion() == V1_7_6; return getGameVersion() == V1_7_6;
} }
public static boolean is1_7_10() {
return getGameVersion() == V1_7_10;
}
} }
private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; private static final String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3];
@ -543,14 +550,16 @@ public class ReflectionManager {
} }
public static boolean is1_8(Player player) { public static boolean is1_8(Player player) {
try { if (LibVersion.is1_7_10()) {
Object cPlayer = getNmsEntity(player); try {
Field playerConnection = cPlayer.getClass().getField("playerConnection"); Object nmsEntity = getNmsEntity(player);
Field networkManager = getNmsClass("PlayerConnection").getField("networkManager"); Object connection = getNmsField(nmsEntity.getClass(), "playerConnection").get(nmsEntity);
Method getVersion = getNmsClass("NetworkManager").getMethod("getVersion"); Field networkManager = getNmsField(connection.getClass(), "networkManager");
return (Integer) getVersion.invoke(networkManager.get(playerConnection.get(cPlayer))) >= 28; Method getVersion = getNmsMethod(networkManager.getType(), "getVersion");
} catch (Exception ex) { return (Integer) getVersion.invoke(networkManager.get(connection)) >= 28;
ex.printStackTrace(); } catch (Exception ex) {
ex.printStackTrace();
}
} }
return false; return false;
} }