|
20 | 20 | import org.bukkit.persistence.PersistentDataType; |
21 | 21 |
|
22 | 22 | import java.util.ArrayList; |
| 23 | +import java.util.List; |
23 | 24 | import java.util.Objects; |
24 | 25 | import java.util.Set; |
25 | 26 |
|
26 | 27 | public class MobDamageListener implements Listener { |
27 | 28 | public static final NamespacedKey nerfMob = new NamespacedKey(NerfFarms.plugin, "nerf-mob"); |
28 | 29 | public static final NamespacedKey blacklistedDamage = new NamespacedKey(NerfFarms.plugin, "blacklisted-damage"); |
29 | 30 | private static final byte t = 1; |
| 31 | + private static final ArrayList<Material> air = new ArrayList<>(List.of(Material.AIR, Material.CAVE_AIR, Material.VOID_AIR)); |
30 | 32 |
|
31 | 33 | @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) |
32 | 34 | public void onMobDamage(EntityDamageEvent damageEvent) { |
@@ -332,8 +334,24 @@ private boolean checkPath(EntityDamageByEntityEvent event, Entity entity, Persis |
332 | 334 | NerfFarms.debugLvl2("Entity's path is null. Returning false"); |
333 | 335 | return false; |
334 | 336 | } |
335 | | - if (!(entityPath.getPoints().size() > 1) ) { |
336 | | - NerfFarms.debugLvl2("Entity does not have a path to the player. Returning true"); |
| 337 | + int pathLength = entityPath.getPoints().size(); |
| 338 | + Location entityLoc = entity.getLocation(); |
| 339 | + double distance = entityLoc.distance(targetLoc); |
| 340 | + List<Location> pathPoints = entityPath.getPoints(); |
| 341 | + if (pathLength <= 1 ) { |
| 342 | + NerfFarms.debugLvl2("Entity does not have a path to the player (Path length less than or equal to 1). Returning true"); |
| 343 | + addPDCDamage(event, mobPDC, hitDamage); |
| 344 | + checkDamageThreshold(mobPDC, entity); |
| 345 | + return true; |
| 346 | + } |
| 347 | + if (!(air.contains(CheckUtils.getBlockAbove(pathPoints.get(1), entity)))) { |
| 348 | + NerfFarms.debugLvl2("Entity does not have a path to the player (2nd path point is blocked). Returning true"); |
| 349 | + addPDCDamage(event, mobPDC, hitDamage); |
| 350 | + checkDamageThreshold(mobPDC, entity); |
| 351 | + return true; |
| 352 | + } |
| 353 | + if (!(air.contains(CheckUtils.getBlockAbove(pathPoints.get(2), entity)))) { |
| 354 | + NerfFarms.debugLvl2("Entity does not have a path to the player (3rd path point is blocked). Returning true"); |
337 | 355 | addPDCDamage(event, mobPDC, hitDamage); |
338 | 356 | checkDamageThreshold(mobPDC, entity); |
339 | 357 | return true; |
@@ -373,6 +391,14 @@ private boolean checkDistance(EntityDamageByEntityEvent event, Entity entity, Pe |
373 | 391 | return false; |
374 | 392 | } |
375 | 393 |
|
| 394 | + /** |
| 395 | + * Checks the blocks around a mob's head, to make sure it is not blocked from moving |
| 396 | + * @param event EntityDamageEvent |
| 397 | + * @param entity Damaged Entity |
| 398 | + * @param mobPDC Mob's Persistent Data Container |
| 399 | + * @param hitDamage double Final Damage |
| 400 | + * @return boolean |
| 401 | + */ |
376 | 402 |
|
377 | 403 | private boolean checkSurroundings(EntityDamageByEntityEvent event, Entity entity, PersistentDataContainer mobPDC, double hitDamage){ |
378 | 404 | LivingEntity damager = CheckUtils.getRealDamager(event); |
|
0 commit comments