Skip to content

Commit

Permalink
new algorithm to teleport the player to the ground in a menu conversa…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Wolf2323 committed Oct 23, 2023
1 parent f461696 commit f8827f0
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -218,12 +219,7 @@ private void start() {

final World world = player.getWorld();
final Location location = player.getLocation();
final Location target = location.clone();
target.setY(world.getHighestBlockYAt(location));
final BlockData blockData = target.getBlock().getBlockData();
if (blockData instanceof final Slab slab && slab.getType() == Slab.Type.BOTTOM) {
target.add(0, -0.5, 0);
}
final Location target = getBlockBelowPlayer(location);
stand = world.spawn(target.add(0, -0.375, 0), ArmorStand.class);

stand.setGravity(false);
Expand All @@ -250,6 +246,21 @@ private void start() {
}
}

private Location getBlockBelowPlayer(final Location location) {
final Location target = location.clone();
Block block = target.getBlock();
while (!block.isSolid()) {
target.add(0, -1, 0);
block = target.getBlock();
}
target.setY(block.getY());
final BlockData blockData = block.getBlockData();
if (blockData instanceof final Slab slab && slab.getType() == Slab.Type.BOTTOM) {
target.add(0, -0.5, 0);
}
return target;
}

/**
* Displays all data to the player. Should be called after setting all
* options.
Expand Down

0 comments on commit f8827f0

Please sign in to comment.