Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra checks to make sure we don't accidentally suffocate player #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/com/koletar/jj/mineresetlite/Mine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -208,9 +211,9 @@ public void setSilence(boolean isSilent) {

public boolean isInside(Player p) {
Location l = p.getLocation();
return (l.getX() >= minX && l.getX() <= maxX)
&& (l.getY() >= minY && l.getY() <= maxY)
&& (l.getZ() >= minZ && l.getZ() <= maxZ);
return (l.getBlockX() >= minX && l.getBlockX() <= maxX)
&& (l.getBlockY() >= minY && l.getBlockY() <= maxY)
&& (l.getBlockZ() >= minZ && l.getBlockZ() <= maxZ);
}

public void reset() {
Expand All @@ -220,7 +223,15 @@ public void reset() {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
Location l = p.getLocation();
if (isInside(p)) {
p.teleport(new Location(world, l.getX(), maxY + 2D, l.getZ()));
// make sure we find a safe location above the mine
Location tp = new Location(world, l.getX(), maxY+1, l.getZ());
Block block = tp.getBlock();

// check to make sure we don't suffocate player
if (block.getType() != Material.AIR || block.getRelative(BlockFace.UP).getType() != Material.AIR) {
tp = new Location(world, l.getX(), l.getWorld().getHighestBlockYAt(l.getBlockX(), l.getBlockZ()), l.getZ());
}
p.teleport(tp);
}
}
//Actually reset
Expand Down