Update for 1.15

This commit is contained in:
libraryaddict 2020-01-28 16:34:18 +13:00
parent d4ef476d84
commit c170970438
No known key found for this signature in database
GPG key ID: 052E4FBCD257AEA4

View file

@ -598,62 +598,6 @@ public class DisguiseUtilities {
return cord; return cord;
} }
public static PacketContainer[] getBedChunkPacket(Location newLoc, Location oldLoc) {
int i = 0;
PacketContainer[] packets = new PacketContainer[(newLoc != null ? 1 : 0) + (oldLoc != null ? 1 : 0)];
if (oldLoc != null) {
PacketContainer despawn = new PacketContainer(Server.UNLOAD_CHUNK);
StructureModifier<Object> modifier = despawn.getModifier();
modifier.write(0, getChunkCord(oldLoc.getBlockX()));
modifier.write(1, getChunkCord(oldLoc.getBlockZ()));
packets[i++] = despawn;
}
if (newLoc != null) {
PacketContainer spawn = spawnChunk.shallowClone();
StructureModifier<Object> modifier = spawn.getModifier();
modifier.write(0, getChunkCord(newLoc.getBlockX()));
modifier.write(1, getChunkCord(newLoc.getBlockZ()));
packets[i++] = spawn;
}
return packets;
}
public static PacketContainer[] getBedPackets(Location sleepingLocation, Location playerLocation,
PlayerDisguise disguise) {
int entity = disguise.getEntity().getEntityId();
PlayerWatcher watcher = disguise.getWatcher();
//PacketContainer setBed = new PacketContainer(Server.BED);
int bX = (getChunkCord(playerLocation.getBlockX()) * 16) + 1 + watcher.getSleepingDirection().getModX();
int bZ = (getChunkCord(playerLocation.getBlockZ()) * 16) + 1 + watcher.getSleepingDirection().getModZ();
// setBed.getIntegers().write(0, entity);
// setBed.getBlockPositionModifier().write(0, new BlockPosition(bX, 0, bZ));
PacketContainer teleport = new PacketContainer(Server.ENTITY_TELEPORT);
StructureModifier<Double> doubles = teleport.getDoubles();
teleport.getIntegers().write(0, entity);
doubles.write(0, sleepingLocation.getX());
doubles.write(1, DisguiseUtilities.getYModifier(disguise.getEntity(), disguise) + sleepingLocation.getY());
doubles.write(2, sleepingLocation.getZ());
return new PacketContainer[]{teleport};
}
public static Disguise getClonedDisguise(String key) { public static Disguise getClonedDisguise(String key) {
if (clonedDisguises.containsKey(key)) { if (clonedDisguises.containsKey(key)) {
return clonedDisguises.get(key).clone(); return clonedDisguises.get(key).clone();
@ -973,81 +917,6 @@ public class DisguiseUtilities {
gson = gsonBuilder.create(); gson = gsonBuilder.create();
try { try {
Object world = ReflectionManager.getWorldServer(Bukkit.getWorlds().get(0));
Class chunkClass = ReflectionManager.getNmsClass("Chunk");
Object bedChunk = null;
Object[] biomes = (Object[]) Array.newInstance(ReflectionManager.getNmsClass("BiomeBase"), 256);
Class registry = ReflectionManager.getNmsClass("IRegistry");
Field biomeRegistry = ReflectionManager.getNmsField(registry, "BIOME");
Iterator itel = ((Iterator) registry.getMethod("iterator").invoke(biomeRegistry.get(null)));
for (int i = 0; i < biomes.length && itel.hasNext(); i++) {
while (itel.hasNext()) {
biomes[i] = itel.next();
}
}
for (Constructor constructor : chunkClass.getConstructors()) {
if (constructor.getParameterTypes().length != 9)
continue;
Object cords = ReflectionManager.getNmsConstructor("ChunkCoordIntPair", int.class, int.class)
.newInstance(0, 0);
bedChunk = constructor.newInstance(world, cords, biomes, null, null, null, 0L, null, null);
break;
}
if (bedChunk == null) {
throw new IllegalStateException("[LibsDisguises] Cannot find constructor to create world chunk");
}
Field cSection = chunkClass.getDeclaredField("sections");
cSection.setAccessible(true);
Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class)
.newInstance(0);
Class blockClass = ReflectionManager.getNmsClass("Block");
Object REGISTRY = ReflectionManager.getNmsField("IRegistry", "BLOCK").get(null);
Object minecraftKey = ReflectionManager.createMinecraftKey("white_bed");
Object block = REGISTRY.getClass().getMethod("get", minecraftKey.getClass()).invoke(REGISTRY, minecraftKey);
Object blockData = ReflectionManager.getNmsMethod(blockClass, "getBlockData").invoke(block);
Method method = null;
for (Method method1 : blockData.getClass().getMethods()) {
if (!method1.getName().equals("set") || method1.getParameterTypes().length != 2)
continue;
method = method1;
break;
}
Method setType = chunkSection.getClass()
.getMethod("setType", int.class, int.class, int.class, ReflectionManager.getNmsClass("IBlockData"));
for (BlockFace face : new BlockFace[]{BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}) {
int x = 1 + face.getModX();
int z = 1 + face.getModZ();
Object data = method.invoke(blockData, block.getClass().getField("FACING").get(null),
ReflectionManager.getEnumDirection(face.ordinal()));
setType.invoke(chunkSection, x, 0, z, data);
}
Object[] array = (Object[]) Array.newInstance(chunkSection.getClass(), 16);
array[0] = chunkSection;
cSection.set(bedChunk, array);
spawnChunk = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, 65535)
.createPacket(bedChunk, 65535);
Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread"); Field threadField = ReflectionManager.getNmsField("MinecraftServer", "serverThread");
threadField.setAccessible(true); threadField.setAccessible(true);