Helper fix

This commit is contained in:
paulevsGitch 2020-10-07 00:03:30 +03:00
parent b36aae9e8b
commit c4fbfbf236

View file

@ -15,6 +15,7 @@ public class SpawnHelper {
private static Method regRestriction; private static Method regRestriction;
public static <T extends MobEntity> void restriction(EntityType<T> entity, Location location, Type heughtmapType, SpawnPredicate<T> predicate) { public static <T extends MobEntity> void restriction(EntityType<T> entity, Location location, Type heughtmapType, SpawnPredicate<T> predicate) {
if (regRestriction != null) {
try { try {
regRestriction.invoke(null, entity, location, heughtmapType, predicate); regRestriction.invoke(null, entity, location, heughtmapType, predicate);
} }
@ -22,6 +23,10 @@ public class SpawnHelper {
BetterEnd.LOGGER.error(e.getMessage()); BetterEnd.LOGGER.error(e.getMessage());
} }
} }
else {
BetterEnd.LOGGER.error("Unable to register spawn restriction, variable is not handled");
}
}
public static <T extends MobEntity> void restrictionLand(EntityType<T> entity, SpawnPredicate<T> predicate) { public static <T extends MobEntity> void restrictionLand(EntityType<T> entity, SpawnPredicate<T> predicate) {
restriction(entity, Location.ON_GROUND, Type.MOTION_BLOCKING, predicate); restriction(entity, Location.ON_GROUND, Type.MOTION_BLOCKING, predicate);
@ -29,10 +34,15 @@ public class SpawnHelper {
static { static {
try { try {
regRestriction = SpawnRestriction.class.getDeclaredMethod("register", EntityType.class, Location.class, Type.class, SpawnPredicate.class); for (Method method: SpawnRestriction.class.getDeclaredMethods()) {
if (method.getParameterCount() == 4) {
regRestriction = method;
regRestriction.setAccessible(true); regRestriction.setAccessible(true);
break;
} }
catch (NoSuchMethodException | SecurityException e) { }
}
catch (SecurityException e) {
BetterEnd.LOGGER.error(e.getMessage()); BetterEnd.LOGGER.error(e.getMessage());
} }
} }