Restore LocationUtil compatibility with 1_8_R1

This commit is contained in:
vemacs 2015-11-15 07:59:19 -07:00
parent 58948b45b3
commit 2d376bc72f

View file

@ -195,8 +195,18 @@ public class LocationUtil {
VOLUME = pos.toArray(new Vector3D[0]);
}
@SuppressWarnings("deprecation")
public static Location getTarget(final LivingEntity entity) throws Exception {
final Block block = entity.getTargetBlock(TRANSPARENT_MATERIALS, 300);
Block block;
try {
block = entity.getTargetBlock(TRANSPARENT_MATERIALS, 300);
} catch (NoSuchMethodError e) {
HashSet<Byte> legacyTransparent = new HashSet<>(); // Bukkit API prevents declaring as Set<Byte>
for (Material m : TRANSPARENT_MATERIALS) {
legacyTransparent.add((byte) m.getId());
}
block = entity.getTargetBlock(legacyTransparent, 300);
}
if (block == null) {
throw new Exception("Not targeting a block");
}