Make root-target find the nearest ground block to root to.
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package com.garbagemule.MobArena.waves.ability.core;
|
package com.garbagemule.MobArena.waves.ability.core;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
|
import com.garbagemule.MobArena.region.ArenaRegion;
|
||||||
import com.garbagemule.MobArena.waves.MABoss;
|
import com.garbagemule.MobArena.waves.MABoss;
|
||||||
import com.garbagemule.MobArena.waves.ability.Ability;
|
import com.garbagemule.MobArena.waves.ability.Ability;
|
||||||
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
|
import com.garbagemule.MobArena.waves.ability.AbilityInfo;
|
||||||
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
|
import com.garbagemule.MobArena.waves.ability.AbilityUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@@ -49,11 +52,34 @@ public class RootTarget implements Ability
|
|||||||
final LivingEntity target = AbilityUtils.getTarget(arena, boss.getEntity(), true);
|
final LivingEntity target = AbilityUtils.getTarget(arena, boss.getEntity(), true);
|
||||||
if (target == null || !(target instanceof Player))
|
if (target == null || !(target instanceof Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player p = (Player) target;
|
Player player = (Player) target;
|
||||||
Location loc = p.getLocation();
|
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) {
|
private void rootTarget(final Arena arena, final Player p, final Location loc, final int counter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user