Player setSleeping should work fine now

This commit is contained in:
libraryaddict 2014-09-29 16:29:13 +13:00
parent 4d50358934
commit 7864920385
2 changed files with 24 additions and 16 deletions

View File

@ -154,8 +154,11 @@ public class DisguiseListener implements Listener {
if (DisguiseConfig.isBedPacketsEnabled()) { if (DisguiseConfig.isBedPacketsEnabled()) {
Location to = event.getTo(); Location to = event.getTo();
Location from = event.getFrom(); Location from = event.getFrom();
if (Math.floor(to.getX() / 160D) != Math.floor(from.getX() / 160D) int x1 = (int) Math.floor(to.getX() / 16D) - 17;
|| Math.floor(to.getZ() / 160D) != Math.floor(from.getZ() / 160D)) { int x2 = (int) Math.floor(from.getX() / 16D) - 17;
int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) {
chunkMove(event.getPlayer(), to, from); chunkMove(event.getPlayer(), to, from);
} }
} }
@ -281,8 +284,11 @@ public class DisguiseListener implements Listener {
if (DisguiseConfig.isBedPacketsEnabled()) { if (DisguiseConfig.isBedPacketsEnabled()) {
Location to = event.getTo(); Location to = event.getTo();
Location from = event.getFrom(); Location from = event.getFrom();
if (Math.floor(to.getX() / 160D) != Math.floor(from.getX() / 160D) int x1 = (int) Math.floor(to.getX() / 16D) - 17;
|| Math.floor(to.getZ() / 160D) != Math.floor(from.getZ() / 160D)) { int x2 = (int) Math.floor(from.getX() / 16D) - 17;
int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) {
chunkMove(event.getPlayer(), null, from); chunkMove(event.getPlayer(), null, from);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() { public void run() {

View File

@ -90,7 +90,7 @@ public class DisguiseUtilities {
Object block; Object block;
try { try {
block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class)
.invoke(null, Material.BED_BLOCK.getId()); // TODO Method name exists in older versions? .invoke(null, Material.BED_BLOCK.getId());
} catch (Exception ex) { } catch (Exception ex) {
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()];
@ -315,9 +315,9 @@ public class DisguiseUtilities {
continue; continue;
} }
try { try {
int chunkX = (int) Math.floor(loc.getX() / 16D) - 20, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 20; int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17;
chunkX -= chunkX % 10; chunkX -= chunkX % 8;
chunkZ -= chunkZ % 10; chunkZ -= chunkZ % 8;
xChunk.set(bedChunk, chunkX); xChunk.set(bedChunk, chunkX);
zChunk.set(bedChunk, chunkZ); zChunk.set(bedChunk, chunkZ);
} catch (Exception ex) { } catch (Exception ex) {
@ -325,25 +325,27 @@ public class DisguiseUtilities {
} }
// Make unload packets // Make unload packets
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, ReflectionManager.is1_8(player) ? 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)
.createPacket(bedChunk, true, 0); .createPacket(bedChunk, true, 0);
} }
i++;
// Make load packets // Make load packets
if (oldLoc == null || i > 1) { if (oldLoc == null || i > 1) {
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), ReflectionManager.is1_8(player) ? 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, Arrays.asList(bedChunk))
.createPacket(Arrays.asList(bedChunk)); .createPacket(Arrays.asList(bedChunk));
} }
i++;
} }
} }
return packets; return packets;
@ -356,10 +358,10 @@ public class DisguiseUtilities {
bedInts.write(0, entity.getEntityId()); bedInts.write(0, entity.getEntityId());
if (ReflectionManager.is1_8(player)) { if (ReflectionManager.is1_8(player)) {
PlayerWatcher watcher = disguise.getWatcher(); PlayerWatcher watcher = disguise.getWatcher();
int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 20, chunkZ = (int) Math int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math
.floor(playerLocation.getZ() / 16D) - 20; .floor(playerLocation.getZ() / 16D) - 17;
chunkX -= chunkX % 10; chunkX -= chunkX % 8;
chunkZ -= chunkZ % 10; chunkZ -= chunkZ % 8;
bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX()); bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX());
bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ()); bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ());
} else { } else {