Work towards 1.8 support

TODO: Remove future disguise types and test backwards compatibility
This commit is contained in:
Byteflux 2014-12-07 07:59:38 -08:00
parent eabfe0d0bf
commit c335b245b5
5 changed files with 63 additions and 42 deletions

13
pom.xml
View File

@ -64,14 +64,9 @@
<url>http://repo.md-5.net/content/groups/public/</url> <url>http://repo.md-5.net/content/groups/public/</url>
</repository> </repository>
<repository> <repository>
<id>comphenix-rep</id> <id>shadowvolt-repo</id>
<name>Comphenix Repository</name> <name>Shadowvolt Maven Repository</name>
<url>http://repo.comphenix.net/content/groups/public</url> <url>http://ci.shadowvolt.com/plugin/repository/everything/</url>
</repository>
<repository>
<id>comphenix-snapshot-rep</id>
<name>Comphenix Snapshot Repository</name>
<url>http://repo.comphenix.net/content/repositories/snapshots/</url>
</repository> </repository>
</repositories> </repositories>
@ -79,7 +74,7 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>3.5.0-SNAPSHOT</version> <version>3.6.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>

View File

@ -34,8 +34,6 @@ public abstract class TargetedDisguise extends Disguise {
} }
public boolean canSee(Player player) { public boolean canSee(Player player) {
if (getType() != null && (getType().is1_8() && !ReflectionManager.is1_8(player)))
return false;
return canSee(player.getName()); return canSee(player.getName());
} }

View File

@ -81,12 +81,14 @@ public class DisguiseUtilities {
static { static {
try { try {
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
bedChunk = ReflectionManager.getNmsClass("Chunk") bedChunk = ReflectionManager.getNmsClass("Chunk")
.getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class).newInstance(null, 0, 0); .getConstructor(ReflectionManager.getNmsClass("World"), int.class, int.class).newInstance(world, 0, 0);
Field cSection = bedChunk.getClass().getDeclaredField("sections"); Field cSection = bedChunk.getClass().getDeclaredField("sections");
cSection.setAccessible(true); cSection.setAccessible(true);
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class) Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class)
.newInstance(0, false); .newInstance(0, true);
Object block; Object block;
try { try {
block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class)
@ -95,6 +97,19 @@ public class DisguiseUtilities {
block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK
.getId()]; .getId()];
} }
if (LibVersion.is1_8()) {
Method fromLegacyData = block.getClass().getMethod("fromLegacyData", int.class);
Method setType = chunkSection.getClass().getMethod("setType", int.class, int.class, int.class,
ReflectionManager.getNmsClass("IBlockData"));
Method setSky = chunkSection.getClass().getMethod("a", int.class, int.class, int.class, int.class);
Method setEmitted = chunkSection.getClass().getMethod("b", int.class, int.class, int.class, int.class);
for (BlockFace face : new BlockFace[] { BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH }) {
setType.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), fromLegacyData.invoke(block, face.ordinal()));
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
}
} else {
Method setId = chunkSection.getClass().getMethod("setTypeId", int.class, int.class, int.class, Method setId = chunkSection.getClass().getMethod("setTypeId", int.class, int.class, int.class,
ReflectionManager.getNmsClass("Block")); ReflectionManager.getNmsClass("Block"));
Method setData = chunkSection.getClass().getMethod("setData", int.class, int.class, int.class, int.class); Method setData = chunkSection.getClass().getMethod("setData", int.class, int.class, int.class, int.class);
@ -106,12 +121,11 @@ public class DisguiseUtilities {
setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0); setSky.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0); setEmitted.invoke(chunkSection, 1 + face.getModX(), 0, 1 + face.getModZ(), 0);
} }
}
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16); Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
array[0] = chunkSection; array[0] = chunkSection;
cSection.set(bedChunk, array); cSection.set(bedChunk, array);
Object server = ReflectionManager.getNmsMethod("MinecraftServer", "getServer").invoke(null);
Object world = ((List) server.getClass().getField("worlds").get(server)).get(0);
bedChunk.getClass().getField("world").set(bedChunk, world);
xChunk = bedChunk.getClass().getField("locX"); xChunk = bedChunk.getClass().getField("locX");
xChunk.setAccessible(true); xChunk.setAccessible(true);
zChunk = bedChunk.getClass().getField("locZ"); zChunk = bedChunk.getClass().getField("locZ");
@ -327,7 +341,7 @@ public class DisguiseUtilities {
try { try {
packets[i] = ProtocolLibrary.getProtocolManager() packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0, 40) .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0, 40)
.createPacket(bedChunk, true, 0, ReflectionManager.is1_8(player) ? 48 : 0); .createPacket(bedChunk, true, 0, LibVersion.is1_8() ? 48 : 0);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
packets[i] = ProtocolLibrary.getProtocolManager() packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0) .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0)
@ -339,10 +353,10 @@ public class DisguiseUtilities {
try { try {
packets[i] = ProtocolLibrary.getProtocolManager() packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk), 40) .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk), 40)
.createPacket(Arrays.asList(bedChunk), ReflectionManager.is1_8(player) ? 48 : 0); .createPacket(Arrays.asList(bedChunk), LibVersion.is1_8() ? 48 : 0);
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
packets[i] = ProtocolLibrary.getProtocolManager() packets[i] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk)) .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, List.class)
.createPacket(Arrays.asList(bedChunk)); .createPacket(Arrays.asList(bedChunk));
} }
i++; i++;
@ -356,7 +370,7 @@ public class DisguiseUtilities {
PacketContainer setBed = new PacketContainer(PacketType.Play.Server.BED); PacketContainer setBed = new PacketContainer(PacketType.Play.Server.BED);
StructureModifier<Integer> bedInts = setBed.getIntegers(); StructureModifier<Integer> bedInts = setBed.getIntegers();
bedInts.write(0, entity.getEntityId()); bedInts.write(0, entity.getEntityId());
if (ReflectionManager.is1_8(player)) { if (LibVersion.is1_8()) {
PlayerWatcher watcher = disguise.getWatcher(); PlayerWatcher watcher = disguise.getWatcher();
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math
.floor(playerLocation.getZ() / 16D) - 17; .floor(playerLocation.getZ() / 16D) - 17;
@ -599,7 +613,7 @@ public class DisguiseUtilities {
*/ */
public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher, public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher,
List<WrappedWatchableObject> list) { List<WrappedWatchableObject> list) {
if (!ReflectionManager.is1_8(player)) if (!LibVersion.is1_8())
return list; return list;
ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<WrappedWatchableObject>(); ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<WrappedWatchableObject>();
ArrayList<WrappedWatchableObject> backups = new ArrayList<WrappedWatchableObject>(); ArrayList<WrappedWatchableObject> backups = new ArrayList<WrappedWatchableObject>();

View File

@ -266,7 +266,7 @@ public class PacketsManager {
} }
} }
if (ReflectionManager.is1_8(player)) { if (LibVersion.is1_8()) {
ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>(); ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>();
newPackets.add(null); newPackets.add(null);
for (int i = 0; i < spawnPackets.length; i++) { for (int i = 0; i < spawnPackets.length; i++) {

View File

@ -36,19 +36,15 @@ public class ReflectionManager {
if (mcVersion.startsWith("1.")) { if (mcVersion.startsWith("1.")) {
if (mcVersion.compareTo("1.7") < 0) { if (mcVersion.compareTo("1.7") < 0) {
currentVersion = LibVersion.V1_6; currentVersion = LibVersion.V1_6;
} else { } else if (mcVersion.startsWith("1.7")) {
if (mcVersion.equals("1.7.10")) { if (mcVersion.equals("1.7.10")) {
currentVersion = LibVersion.V1_7_10; currentVersion = LibVersion.V1_7_10;
} else { } else {
currentVersion = mcVersion.compareTo("1.7.6") < 0 ? LibVersion.V1_7 : LibVersion.V1_7_6; currentVersion = mcVersion.compareTo("1.7.6") < 0 ? LibVersion.V1_7 : LibVersion.V1_7_6;
} }
} } else {
}
try {
Class.forName("org.spigotmc.ProtocolData");
currentVersion = V1_8; currentVersion = V1_8;
} catch (Exception ex) { }
// Its not 1.8
} }
} }
@ -249,6 +245,9 @@ public class ReflectionManager {
playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises", playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises",
playerinteractmanager); playerinteractmanager);
} }
} else if (LibVersion.is1_8() && entityName.equals("EnderPearl")) {
entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving"))
.newInstance(world, createEntityInstance("Sheep"));
} else { } else {
entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world); entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world);
} }
@ -265,7 +264,12 @@ public class ReflectionManager {
public static FakeBoundingBox getBoundingBox(Entity entity) { public static FakeBoundingBox getBoundingBox(Entity entity) {
try { try {
Object boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity)); Object boundingBox;
if (LibVersion.is1_8()) {
boundingBox = getNmsMethod("Entity", "getBoundingBox").invoke(getNmsEntity(entity));
} else {
boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity));
}
double x = 0, y = 0, z = 0; double x = 0, y = 0, z = 0;
int stage = 0; int stage = 0;
for (Field field : boundingBox.getClass().getFields()) { for (Field field : boundingBox.getClass().getFields()) {
@ -492,7 +496,12 @@ public class ReflectionManager {
try { try {
float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity)); float length = getNmsField("Entity", "length").getFloat(getNmsEntity(entity));
float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity)); float width = getNmsField("Entity", "width").getFloat(getNmsEntity(entity));
float height = getNmsField("Entity", "height").getFloat(getNmsEntity(entity)); float height;
if (LibVersion.is1_8()) {
height = (Float) getNmsMethod("Entity", "getHeadHeight").invoke(getNmsEntity(entity));
} else {
height = getNmsField("Entity", "height").getFloat(getNmsEntity(entity));
}
return new float[] { length, width, height }; return new float[] { length, width, height };
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -611,7 +620,12 @@ public class ReflectionManager {
public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) { public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) {
try { try {
Object boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity)); Object boundingBox;
if (LibVersion.is1_8()) {
boundingBox = getNmsMethod("Entity", "getBoundingBox").invoke(getNmsEntity(entity));
} else {
boundingBox = getNmsField("Entity", "boundingBox").get(getNmsEntity(entity));
}
int stage = 0; int stage = 0;
Location loc = entity.getLocation(); Location loc = entity.getLocation();
for (Field field : boundingBox.getClass().getFields()) { for (Field field : boundingBox.getClass().getFields()) {