Well, the title pretty much says it all. I feel that my code could work but I am having a problem running a certain part in Minecraft. My plugin involves dreaming so when a player uses a bed they are sent to a new world. However, I feel like it is not detecting when the player is sleeping. I used the statement:
if(player.isSleeping())
and then I continued the code from there. Here is part of the code that is relevant:
public class LucidDream extends JavaPlugin {
Location normalDream;
Location nightmareDream;
Location original;
public final Logger log = Logger.getLogger("Minecraft");
public void onEnable(){
log.info(ChatColor.GREEN + "LucidDream has been enabled!");
}
public void onDisable(){
log.info(ChatColor.RED + "LucidDream has been disabled!");
}
public boolean onCommand(CommandSender sender,Command cmd, String commandLabel, String[] args){
Player player = (Player) sender;
boolean sleeping = false;
original = player.getLocation();
saveInventory(player);
ItemStack[] copy = copyInventory(player.getInventory());
if(player.isSleeping())
{
if((int) Math.random() * 2 > .2){ // Make it so the player spawns in a safe place
normalDream = new Location(normalWorld(),0,0,0);
player.teleport(normalDream);
if(player.teleport(normalDream))
sender.sendMessage(ChatColor.BLUE + "Welcome to your dream!");
}else{
nightmareDream = new Location(nightmareWorld(),0,0,0);
player.teleport(nightmareDream);
if(player.teleport(nightmareDream))
sender.sendMessage(ChatColor.RED + "Welcome to your NIGHTMARE!");
}
sleeping = true;
return true;
}
if(sleeping==true && commandLabel.equalsIgnoreCase("wake"))
{
player.teleport(original);
restoreInventory(player, copy);
sender.sendMessage("Welcome Back!");
return true;
}
return false;
}
Also, you may see a part I had commented which is something else that I need some assistance in. When I create the locations of these world, I am trying to make it so each time a new world is made, the player is guaranteed to spawn in a safe place which means they wont spawn inside the ground for example.
if(player.isSleeping())
and then I continued the code from there. Here is part of the code that is relevant:
Also, you may see a part I had commented which is something else that I need some assistance in. When I create the locations of these world, I am trying to make it so each time a new world is made, the player is guaranteed to spawn in a safe place which means they wont spawn inside the ground for example.
Any help is greatly appreciated!