From 868c7a463d082e1f179357ada6b7f2920dd9ebc6 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 14 Nov 2022 18:02:52 +0800 Subject: [PATCH] Check for outdated versions of minecraft in SleepTrait --- .../java/net/citizensnpcs/trait/SleepTrait.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; }