diff --git a/src/main/java/ru/betterend/util/SpawnHelper.java b/src/main/java/ru/betterend/util/SpawnHelper.java index 155f8f20..168f29cb 100644 --- a/src/main/java/ru/betterend/util/SpawnHelper.java +++ b/src/main/java/ru/betterend/util/SpawnHelper.java @@ -15,11 +15,16 @@ public class SpawnHelper { private static Method regRestriction; public static void restriction(EntityType entity, Location location, Type heughtmapType, SpawnPredicate predicate) { - try { - regRestriction.invoke(null, entity, location, heughtmapType, predicate); + if (regRestriction != null) { + try { + regRestriction.invoke(null, entity, location, heughtmapType, predicate); + } + catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + BetterEnd.LOGGER.error(e.getMessage()); + } } - catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - BetterEnd.LOGGER.error(e.getMessage()); + else { + BetterEnd.LOGGER.error("Unable to register spawn restriction, variable is not handled"); } } @@ -29,10 +34,15 @@ public class SpawnHelper { static { try { - regRestriction = SpawnRestriction.class.getDeclaredMethod("register", EntityType.class, Location.class, Type.class, SpawnPredicate.class); - regRestriction.setAccessible(true); + for (Method method: SpawnRestriction.class.getDeclaredMethods()) { + if (method.getParameterCount() == 4) { + regRestriction = method; + regRestriction.setAccessible(true); + break; + } + } } - catch (NoSuchMethodException | SecurityException e) { + catch (SecurityException e) { BetterEnd.LOGGER.error(e.getMessage()); } }