Skip to content

Commit

Permalink
fixed issue when player is above void without a block between
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf2323 committed Oct 23, 2023
1 parent f8827f0 commit 0232204
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
Expand Down Expand Up @@ -217,10 +216,8 @@ private void start() {
}
state = ConversationState.ACTIVE;

final World world = player.getWorld();
final Location location = player.getLocation();
final Location target = getBlockBelowPlayer(location);
stand = world.spawn(target.add(0, -0.375, 0), ArmorStand.class);
final Location target = getBlockBelowPlayer(player);
stand = player.getWorld().spawn(target.add(0, -0.375, 0), ArmorStand.class);

stand.setGravity(false);
stand.setVisible(false);
Expand All @@ -246,12 +243,19 @@ private void start() {
}
}

private Location getBlockBelowPlayer(final Location location) {
private Location getBlockBelowPlayer(final Player player) {
final Location location = player.getLocation();
if (player.isFlying()) {
return location.add(0, -1, 0);
}
final Location target = location.clone();
Block block = target.getBlock();
while (!block.isSolid()) {
target.add(0, -1, 0);
block = target.getBlock();
if (target.getY() < target.getWorld().getMinHeight()) {
return location;
}
}
target.setY(block.getY());
final BlockData blockData = block.getBlockData();
Expand Down

0 comments on commit 0232204

Please sign in to comment.