48 lines
1.7 KiB
Java
48 lines
1.7 KiB
Java
package nz.jimmy.easyspawn;
|
|
|
|
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
|
|
*/
|
|
public class Bed implements CommandExecutor {
|
|
EasySpawn plugin;
|
|
public Bed(EasySpawn plugin) {
|
|
this.plugin = plugin;
|
|
plugin.getCommand("bed").setExecutor(this);
|
|
}
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label,
|
|
String[] args) {
|
|
if(sender instanceof Player) {
|
|
Player player = (Player)sender;
|
|
//Check if player has a bed
|
|
if(player.getBedSpawnLocation()!=null){
|
|
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;
|
|
}
|
|
return false;
|
|
}
|
|
} |