Update for 1.15

This commit is contained in:
libraryaddict
2019-12-14 13:10:11 +13:00
parent da0e282258
commit 7b70c9bb14
12 changed files with 119 additions and 164 deletions

View File

@@ -19,6 +19,9 @@ public enum DisguiseSound {
BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
BEE(Sound.ENTITY_BEE_HURT, null, Sound.ENTITY_BEE_DEATH, null, Sound.ENTITY_BEE_LOOP,
Sound.ENTITY_BEE_LOOP_AGGRESSIVE, Sound.ENTITY_BEE_POLLINATE, Sound.ENTITY_BEE_STING),
BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN,
Sound.ENTITY_BLAZE_SHOOT),

View File

@@ -525,62 +525,6 @@ public class DisguiseUtilities {
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) {
if (clonedDisguises.containsKey(key)) {
return clonedDisguises.get(key).clone();
@@ -879,81 +823,6 @@ public class DisguiseUtilities {
gson = gsonBuilder.create();
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");
threadField.setAccessible(true);

View File

@@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities.packets.packethandlers;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLib;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.reflect.StructureModifier;
@@ -209,14 +210,18 @@ public class PacketHandlerSpawn implements IPacketHandler {
bytes.write(0, yaw);
bytes.write(1, pitch);
spawnPlayer.getDataWatcherModifier().write(0, newWatcher);
// Make him invisible
newWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(MetaIndex.ENTITY_META.getIndex(),
WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32);
packets.addPacket(spawnPlayer);
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, newWatcher, true)
.createPacket(entityId, newWatcher, true);
packets.addPacket(metaPacket);
if (!selfDisguise) {
// Teleport the player back to where he's supposed to be
PacketContainer teleportPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
@@ -235,7 +240,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
packets.addDelayedPacket(teleportPacket, 3);
// Send a metadata packet
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
newWatcher = DisguiseUtilities
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
@@ -302,9 +307,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
mods.write(10, pitch);
mods.write(11, yaw);
spawnEntity.getDataWatcherModifier().write(0, DisguiseUtilities
WrappedDataWatcher newWatcher = DisguiseUtilities
.createSanitizedDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity),
disguise.getWatcher()));
disguise.getWatcher());
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(),
newWatcher, true).createPacket(disguisedEntity.getEntityId(), newWatcher, true);
packets.addPacket(metaPacket);
} else if (disguise.getType().isMisc()) {
int data = ((MiscDisguise) disguise).getData();
double x = loc.getX();