Make root-target find the nearest ground block to root to.

This commit is contained in:
garbagemule
2015-07-28 20:25:08 +02:00
parent f49fe0e33b
commit 3a20be3db9
@@ -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;
@@ -50,10 +53,33 @@ public class RootTarget implements Ability
if (target == null || !(target instanceof Player))
return;
Player p = (Player) target;
Location loc = p.getLocation();
Player player = (Player) target;
ArenaRegion region = arena.getRegion();
rootTarget(arena, p, loc, ITERATIONS);
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) {