Placing a player into bed (Day time)

Discussion in 'Plugin Development' started by Neodork, Jun 10, 2012.

  1. Offline

    Neodork

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Hello Bukkiteers

    I tried the following to place a player into bed (day time).

    Code:java
    1. ((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

    This post has been edited 1 time. It was last edited by Neodork Jun 10, 2012.
  2. Offline

    Jeff.Halbert

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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...
    Neodork likes this.
  3. Offline

    Iron_Crystal

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    What? How do you do that?
  4. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @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.

    This post has been edited 1 time. It was last edited by V10lator Jun 11, 2012.
    Neodork likes this.
  5. Offline

    Neodork

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  6. Offline

    Malikk

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  7. Offline

    Neodork

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)

    I tried, It won't go off when not in evening...
  8. Offline

    Malikk

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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
  9. Offline

    Jeff.Halbert

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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
      }
    }

    This post has been edited 2 times. It was last edited by Jeff.Halbert Jun 13, 2012.
    Neodork likes this.
  10. Offline

    Korvacs

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.

    This post has been edited 1 time. It was last edited by Korvacs Jun 13, 2012.
  11. Offline

    Neodork

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.

Share This Page