Making player lie down help

Discussion in 'Plugin Development' started by Threehundredcc2, Aug 13, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Threehundredcc2

    I have been searching for a while now and I have found some good sources but when I try it does not work.

    Here's my current code
    Code:java
    1. Packet70Bed packet = new Packet70Bed(p.getEntityId(), 78);
    2. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);


    if someone could point out to my what I'm doing wrong that would be great.
     
  2. Offline

    herpingdo

    Could you try giving us the error you are getting?
     
  3. Offline

    Threehundredcc2

    herpingdo
    There is no error at all. It just does nothing.
     
  4. Offline

    Threehundredcc2

  5. Threehundredcc2
    You know 78 is snow right?
    Just wondering if you knew.
     
  6. Offline

    Threehundredcc2

    HeyAwesomePeople
    Lol I did not know that where a block was suppose to go., what should I have there?
     
  7. Personally, I don't know. lol.
    Try setting it to grass and run the command on grass?

    If I am getting this right, its just supposed to lie the player down anywhere and not a bed right?
     
  8. Offline

    Threehundredcc2

    HeyAwesomePeople
    Correct.

    Okay, I changed the 78); around a bit to various different blocks, nothing worked.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    Threehundredcc2

  10. Offline

    Paulpkyou

    You got the wrong packet, Packet70Bed is used to set the weather, show the credits, and set the player's game mode. What you should be using is Packet17EntityLocationAction.
     
    ThunderWaffeMC likes this.
  11. Offline

    Threehundredcc2

    Paulpkyou
    Ah alright, is there any certain way I should use this?
     
  12. Offline

    xTrollxDudex

    Threehundredcc2
    The constructor has Entity, and 3 ints. I assume the entity should be a NMS player, and the ints a location.
     
    Threehundredcc2 likes this.
  13. Offline

    Threehundredcc2

    xTrollxDudex
    Okay, I got it to somewhat work, it gives me the screen just like it would if you entered a bed and with the option "Leave bed". They only problem is that it's not making my player look like its in a bed, it's just standing there.
     
  14. Offline

    xTrollxDudex

    Threehundredcc2
    Are you observing from a different player? It sounds like you are pressing F5.
     
  15. Offline

    Threehundredcc2

    xTrollxDudex
    Yes, I am observing from my alternate account.
     
  16. Offline

    ISHLCMinecraft

    this is my lying down method:
    Code:java
    1. public void layDown(Player player, Block block) {
    2. player.teleport(block.getLocation().add(0.5, 1, 0.5));
    3. player.sendBlockChange(block.getLocation(), Material.ENDER_PORTAL_FRAME, (byte) 0);
    4. player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 999999999, 9));
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 999999999, 199));
    6. player.setSneaking(false);
    7.  
    8. EntityPlayer entityPlayer = ((CraftPlayer)player).getHandle();
    9. Packet17EntityLocationAction packet = new Packet17EntityLocationAction(entityPlayer, 0, block.getX(), block.getY(), block.getZ());
    10.  
    11. for(Player p : Bukkit.getOnlinePlayers()){
    12. if(!p.equals(player))
    13. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(packet);
    14. }
    15.  
    16. Packet70Bed bedpacket = new Packet70Bed(player.getEntityId(), 78);
    17.  
    18. for(Player p : Bukkit.getOnlinePlayers()){
    19. if(!p.equals(player))
    20. ((CraftPlayer)p).getHandle().playerConnection.sendPacket(bedpacket);
    21. }
    22. }

    hope im helping :)
     
  17. Offline

    Threehundredcc2

    ISHLCMinecraft
    Thanks, but for some reason it is not working for me
     
  18. Offline

    ISHLCMinecraft

    Threehundredcc2 What is not working?
    The player in the method is the player you want to make him lay down.
    The block is the location block.
    The player that you making him lay down is actualy standing on fake block and he can't move.
    All the server see him on the groun.
     
  19. Offline

    Threehundredcc2

    ISHLCMinecraft
    Alright so I added some debug messages through some sections of the code, it seems o be passing through. When I get teleport it does not stop me from moving. I've looked on my other account and I am not lying down. I'm not exactly sure what is going on. Maybe it's how I'm calling the method:

    Code:java
    1. layDown(player, player.getLocation().getBlock());


    Thanks.
     
  20. Offline

    ISHLCMinecraft

    Code:java
    1. private void sleep(Player player) {
    2. Location loc = player.getLocation();
    3. Packet17EntityLocationAction packet17 = new Packet17EntityLocationAction(player, 0, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    4.  
    5. // player.teleport(loc);
    6. for(Player otherPlayer: player.getWorld().getPlayers()){
    7. ((CraftPlayer) otherPlayer).getHandle().playerConnection.sendPacket(packet17);
    8. }
    9. player.setAllowFlight(true);
    10. player.setFlying(true);
    11. }

    Code:java
    1. private void unsleep(Player player) {
    2. Packet18ArmAnimation packet18 = new Packet18ArmAnimation(player, 3), player);
    3. for(Player otherPlayer: player.getWorld().getPlayers()){
    4. ((CraftPlayer) otherPlayer).getHandle().playerConnection.sendPacket(packet18);
    5. }
    6. }

    Taken from Citizens API
     
Thread Status:
Not open for further replies.

Share This Page