Fail to teleport if be is obstructed

This commit is contained in:
Jimmy Allen 2021-03-18 11:05:41 +13:00
parent 5af072d03f
commit 80e534b14e
1 changed files with 19 additions and 2 deletions

View File

@ -4,6 +4,10 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.*;
/**
* Bed
@ -21,8 +25,21 @@ public class Bed implements CommandExecutor {
Player player = (Player)sender;
//Check if player has a bed
if(player.getBedSpawnLocation()!=null){
player.teleport(player.getBedSpawnLocation());
player.sendMessage("You have been teleported to your bed.");
Location bed = player.getBedSpawnLocation();
//Check if 2 blocks above are air
World world = bed.getWorld();
Material mat1 = world.getBlockAt(bed.getBlockX(),
bed.getBlockY()+1, bed.getBlockZ()).getType();
Material mat2 = world.getBlockAt(bed.getBlockX(),
bed.getBlockY()+2, bed.getBlockZ()).getType();
if(mat1 == Material.AIR && mat2 == Material.AIR) {
player.teleport(bed);
player.sendMessage("You have been teleported to your bed.");
} else {
player.sendMessage("Your bed is obstructed.");
}
}else sender.sendMessage("You need to sleep in a bed first.");
return true;
}