Hello Bukkiteers I tried the following to place a player into bed (day time). Code:java ((CraftPlayer) player).getHandle().a(x, y, z); This piece of code tends to do nothing. Or at least it won't show the results I was hoping for (placing the player into the bed). Maybe some of you have been fooling around with this and care to share their knowledge with me? Please feel free to share anything related to this problem. It has no need to be a full solution. Greets Neodork
try changing the players time. change the time to night specifically for that player when they attempt to use a bed. then change it back when they exit... just an idea...
@Iron_Crystal I can't access jd.bukkit.org atm, but it's basically: player.setPlayerTime(long, boolean) Where the long is the players new time and the boolean decides if the time is relative (if I remember corectly true means the time will pass for the player, false means it is frozen at the new time.
I'll drop like's when I've had the time to try this out. At the moment one of my pc's is undergoing scans so I will have to import most of my work.
I would think, rather than sending a client side time change, it would be alot better to listen to PlayerBedEnterEvent and see if you can't uncancel it. I've not tried, and I'm not even positive that the event is fired if they aren't allowed into the bed, but I would definitely look into that before you bothered messing with all the time changes.
Alright then... Once you get the time change working, I would check if you actually have to wait until they get up to change it back. If it doesn't kick them out if it becomes day (which is probably does) you should only change the time for a split second. That's really all I can contribute, lol
you can try something like .... Code: [psuedocode] onBedEnter (EnterBedEvent event) { if (event.isCancelled) { Player player = event.getPlayer(); player.setPlayerTime(night, freezeTheTime); //put him in the bed, then do whatever //take him out of bed player.setPlayerTime(globalTime, letItPass); } } (edit) actually, after looking at it again, try playerinteractevent Code: public void onBedInteract(PlayerInteractevent event) { if (event.getBlockClicked().getType() == Material.BED) { //do your thing } }
Just send the packet that places a player in a bed to the client (and obvs update local players) and perform the regular handling that vanilla mc performs when this action occurs.
Ok so I've tried a few things but when I change the players time to night the server will still spit out "you can only sleep at night". So no progress... Thanks for the help so far, I'll keep looking for a way to do it.