Don't glitch out when trying to sleep.

This commit is contained in:
libraryaddict 2014-01-05 13:13:49 +13:00
parent 69b104f749
commit 5c94b59801
3 changed files with 16 additions and 4 deletions

View File

@ -61,7 +61,7 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0</version>
</dependency>
</dependencies>
<version>7.9.1-SNAPSHOT</version>

View File

@ -786,9 +786,9 @@ public class PacketsManager {
|| event.getPacketType() == PacketType.Play.Server.ENTITY_EFFECT
|| event.getPacketType() == PacketType.Play.Server.ENTITY_EQUIPMENT) {
event.setCancelled(true);
}
else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
} else if (event.getPacketType() == PacketType.Play.Server.BED) {
ReflectionManager.setAllowSleep(observer);
} else if (event.getPacketType() == PacketType.Play.Server.ENTITY_STATUS) {
Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer());
if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer()
&& event.getPacket().getBytes().read(0) == (ReflectionManager.isAfter17() ? 2 : 1)) {

View File

@ -10,6 +10,7 @@ import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class ReflectionManager {
@ -56,6 +57,17 @@ public class ReflectionManager {
}
}
public static void setAllowSleep(Player player) {
try {
Object nmsEntity = getNmsEntity(player);
Object connection = nmsEntity.getClass().getField("playerConnection").get(nmsEntity);
Field check = connection.getClass().getField("checkMovement");
check.setBoolean(connection, true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static Object createEntityInstance(String entityName) {
try {
Class entityClass = getNmsClass("Entity" + entityName);