diff --git a/src/main/java/com/garbagemule/MobArena/waves/ability/core/RootTarget.java b/src/main/java/com/garbagemule/MobArena/waves/ability/core/RootTarget.java index d321719..703faed 100644 --- a/src/main/java/com/garbagemule/MobArena/waves/ability/core/RootTarget.java +++ b/src/main/java/com/garbagemule/MobArena/waves/ability/core/RootTarget.java @@ -1,11 +1,14 @@ package com.garbagemule.MobArena.waves.ability.core; import com.garbagemule.MobArena.framework.Arena; +import com.garbagemule.MobArena.region.ArenaRegion; import com.garbagemule.MobArena.waves.MABoss; import com.garbagemule.MobArena.waves.ability.Ability; import com.garbagemule.MobArena.waves.ability.AbilityInfo; import com.garbagemule.MobArena.waves.ability.AbilityUtils; import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -49,11 +52,34 @@ public class RootTarget implements Ability final LivingEntity target = AbilityUtils.getTarget(arena, boss.getEntity(), true); if (target == null || !(target instanceof Player)) return; - - Player p = (Player) target; - Location loc = p.getLocation(); - - rootTarget(arena, p, loc, ITERATIONS); + + Player player = (Player) target; + ArenaRegion region = arena.getRegion(); + + Block block = player.getLocation().getBlock(); + Block solid = findSolidBlockBelow(region, block); + + Location location = player.getLocation(); + location.setY(solid.getLocation().getY() + 1); + + rootTarget(arena, player, location, ITERATIONS); + } + + private Block findSolidBlockBelow(ArenaRegion region, Block block) { + Block below = block.getRelative(BlockFace.DOWN); + + // If the block below is not in the region, return the block itself + if (!region.contains(below.getLocation())) { + return block; + } + + // If the block below is solid, return it + if (below.getType().isSolid()) { + return below; + } + + // Otherwise, recurse downwards + return findSolidBlockBelow(region, below); } private void rootTarget(final Arena arena, final Player p, final Location loc, final int counter) {