diff --git a/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java b/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java index e62031408..532f3b5df 100644 --- a/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/SleepTrait.java @@ -40,10 +40,19 @@ public class SleepTrait extends Trait { if (at == null) return; + if (SUPPORT_BLOCKDATA == null) { + try { + SUPPORT_BLOCKDATA = true; + at.getBlock().getBlockData(); + } catch (NoSuchMethodError e) { + SUPPORT_BLOCKDATA = false; + } + } npc.teleport(at, TeleportCause.PLUGIN); if (npc.getEntity() instanceof Player) { Player player = (Player) npc.getEntity(); - if (at.getBlock().getBlockData() instanceof Bed || at.getBlock().getState() instanceof Bed) { + if ((SUPPORT_BLOCKDATA && at.getBlock().getBlockData() instanceof Bed) + || at.getBlock().getState() instanceof Bed) { player.sleep(at, true); } else { NMS.sleep(player, true); @@ -67,4 +76,6 @@ public class SleepTrait extends Trait { } sleeping = false; } + + private static Boolean SUPPORT_BLOCKDATA = null; }