From d672013583049082273d67410f15078445368fa9 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Wed, 24 Sep 2014 02:52:38 +1200 Subject: [PATCH] Block.getById should now work for older versions of mc --- .../disguise/utilities/DisguiseUtilities.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index bdd6f5ce..01e53d83 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -87,8 +87,14 @@ public class DisguiseUtilities { cSection.setAccessible(true); Object chunkSection = ReflectionManager.getNmsClass("ChunkSection").getConstructor(int.class, boolean.class) .newInstance(0, false); - Object block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) - .invoke(null, Material.BED_BLOCK.getId()); // TODO Method name exists in older versions? + Object block; + try { + block = ReflectionManager.getNmsClass("Block").getMethod("getById", int.class) + .invoke(null, Material.BED_BLOCK.getId()); // TODO Method name exists in older versions? + } catch (Exception ex) { + block = ((Object[]) ReflectionManager.getNmsField(ReflectionManager.getNmsClass("Block"), "byId").get(null))[Material.BED_BLOCK + .getId()]; + } Method setId = chunkSection.getClass().getMethod("setTypeId", int.class, int.class, int.class, ReflectionManager.getNmsClass("Block")); Method setData = chunkSection.getClass().getMethod("setData", int.class, int.class, int.class, int.class);