Solved update other players packet?

Discussion in 'Plugin Development' started by pkt, Jul 9, 2013.

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

    pkt

    I just started learning about packets, and I got a player to get into bed (lay down), but it doesn't show up for other players... is there a way I can update the other players ?
     
  2. Offline

    SnowGears

    You need to send the same packet that you sent to the player laying down to all other online players. Care to post the code?
     
  3. Offline

    pkt

    yep, here ya go:
    Code:
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new Packet17EntityLocationAction(((CraftPlayer) player).getHandle(), 0, player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
    Tooner101
    I am looking at http://wiki.vg/Protocol , and some Packets say client to server, others server to client, would sending my packet to the server allow everyone in the server to see it ?

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

    Polaris29

    No, you can't even send a packet to the server from the server, only server to client. To send a packet to everyone, you have to loop through all the players and send the packet to each player.

    net.minecraft.server already has methods to send Packets to everyone using PlayerList, to get the PlayerList, you would just do "MinecraftServer.getServer().getPlayerList()" then do "playerlist.sendAll(packet);" or for sending a packet nearby from a location: "playerlist.sendPacketNearby(x,y,z,d3,worldserver.dimension,packet);" I don't know what d3 is though
     
    pkt likes this.
  5. Offline

    SnowGears

    pkt
    Make sure you dont accidentally make everyone lay down though :p

    Something like this will work I think.
    Code:
    ((CraftPlayer)playerToSendPacketTo).getHandle().playerConnection.sendPacket(newPacket17EntityLocationAction(((CraftPlayer) playerToLayDown).getHandle(), 0,playerToLayDown.getLocation().getBlockX(),playerToLayDown.getLocation().getBlockY(), playerToLayDown.getLocation().getBlockZ()));
     
    pkt likes this.
  6. Offline

    pkt

    Polaris29 Tooner101
    Cool, thanks guys, I'll try it out later today

    @Polaris29 Tooner101
    It kind of worked, but other players see them as in the ground... how can I fix this?

    nvm, it works now for some reason xD

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page