From 7864920385c6cb3e8a48cf8ccc1ca14cbbeedf65 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 29 Sep 2014 16:29:13 +1300 Subject: [PATCH] Player setSleeping should work fine now --- .../disguise/DisguiseListener.java | 14 +++++++--- .../disguise/utilities/DisguiseUtilities.java | 26 ++++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 838fbc5c..3c0bd14d 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -154,8 +154,11 @@ public class DisguiseListener implements Listener { if (DisguiseConfig.isBedPacketsEnabled()) { Location to = event.getTo(); Location from = event.getFrom(); - if (Math.floor(to.getX() / 160D) != Math.floor(from.getX() / 160D) - || Math.floor(to.getZ() / 160D) != Math.floor(from.getZ() / 160D)) { + int x1 = (int) Math.floor(to.getX() / 16D) - 17; + 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); } } @@ -281,8 +284,11 @@ public class DisguiseListener implements Listener { if (DisguiseConfig.isBedPacketsEnabled()) { Location to = event.getTo(); Location from = event.getFrom(); - if (Math.floor(to.getX() / 160D) != Math.floor(from.getX() / 160D) - || Math.floor(to.getZ() / 160D) != Math.floor(from.getZ() / 160D)) { + int x1 = (int) Math.floor(to.getX() / 16D) - 17; + 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); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index fca2b4da..cd5c0c5c 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -90,7 +90,7 @@ public class DisguiseUtilities { Object block; try { 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) { block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK .getId()]; @@ -315,9 +315,9 @@ public class DisguiseUtilities { continue; } try { - int chunkX = (int) Math.floor(loc.getX() / 16D) - 20, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 20; - chunkX -= chunkX % 10; - chunkZ -= chunkZ % 10; + int chunkX = (int) Math.floor(loc.getX() / 16D) - 17, chunkZ = (int) Math.floor(loc.getZ() / 16D) - 17; + chunkX -= chunkX % 8; + chunkZ -= chunkZ % 8; xChunk.set(bedChunk, chunkX); zChunk.set(bedChunk, chunkZ); } catch (Exception ex) { @@ -325,25 +325,27 @@ public class DisguiseUtilities { } // Make unload packets try { - packets[i++] = ProtocolLibrary.getProtocolManager() + packets[i] = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0, 40) .createPacket(bedChunk, true, 0, ReflectionManager.is1_8(player) ? 48 : 0); } catch (IllegalArgumentException ex) { - packets[i++] = ProtocolLibrary.getProtocolManager() + packets[i] = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK, bedChunk, true, 0) .createPacket(bedChunk, true, 0); } + i++; // Make load packets if (oldLoc == null || i > 1) { try { - packets[i++] = ProtocolLibrary.getProtocolManager() + packets[i] = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk), 40) .createPacket(Arrays.asList(bedChunk), ReflectionManager.is1_8(player) ? 48 : 0); } catch (IllegalArgumentException ex) { - packets[i++] = ProtocolLibrary.getProtocolManager() + packets[i] = ProtocolLibrary.getProtocolManager() .createPacketConstructor(PacketType.Play.Server.MAP_CHUNK_BULK, Arrays.asList(bedChunk)) .createPacket(Arrays.asList(bedChunk)); } + i++; } } return packets; @@ -356,10 +358,10 @@ public class DisguiseUtilities { bedInts.write(0, entity.getEntityId()); if (ReflectionManager.is1_8(player)) { PlayerWatcher watcher = disguise.getWatcher(); - int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 20, chunkZ = (int) Math - .floor(playerLocation.getZ() / 16D) - 20; - chunkX -= chunkX % 10; - chunkZ -= chunkZ % 10; + int chunkX = (int) Math.floor(playerLocation.getX() / 16D) - 17, chunkZ = (int) Math + .floor(playerLocation.getZ() / 16D) - 17; + chunkX -= chunkX % 8; + chunkZ -= chunkZ % 8; bedInts.write(1, (chunkX * 16) + 1 + watcher.getSleepingDirection().getModX()); bedInts.write(3, (chunkZ * 16) + 1 + watcher.getSleepingDirection().getModZ()); } else {