コード例 #1
0
  /**
   * Sends the update entity packet.
   *
   * @param entity The entity being updated.
   */
  public void sendUpdateEntity(Entity entity) {
    final Position oldPosition = entity.getOldPosition();
    final Position position = entity.getPosition();

    final Rotation oldRotation = entity.getOldRotation();
    final Rotation rotation = entity.getRotation();

    final int deltaX = -oldPosition.getX() - position.getX();
    final int deltaY = -oldPosition.getY() - position.getY();
    final int deltaZ = -oldPosition.getZ() - position.getZ();

    final int deltaRotation = -oldRotation.getRotation() - rotation.getRotation();
    final int deltaLook = -oldRotation.getLook() - rotation.getLook();
    if (deltaX != 0 || deltaY != 0 || deltaZ != 0) {
      if (deltaX > Byte.MAX_VALUE
          || deltaX < Byte.MIN_VALUE
          || deltaY > Byte.MAX_VALUE
          || deltaY < Byte.MIN_VALUE
          || deltaZ > Byte.MAX_VALUE
          || deltaZ < Byte.MIN_VALUE
          || deltaRotation > Byte.MAX_VALUE
          || deltaRotation < Byte.MIN_VALUE
          || deltaLook > Byte.MAX_VALUE
          || deltaLook < Byte.MIN_VALUE) {
        // teleport
        PacketBuilder bldr =
            new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(8));
        bldr.putByte("id", entity.getId());
        bldr.putShort("x", position.getX());
        bldr.putShort("y", position.getY());
        bldr.putShort("z", position.getZ());
        bldr.putByte("rotation", rotation.getRotation());
        bldr.putByte("look", rotation.getLook());
        session.send(bldr.toPacket());
      } else {
        // send move and rotate packet
        PacketBuilder bldr =
            new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(9));
        bldr.putByte("id", entity.getId());
        bldr.putByte("delta_x", deltaX);
        bldr.putByte("delta_y", deltaY);
        bldr.putByte("delta_z", deltaZ);
        bldr.putByte("delta_rotation", deltaRotation);
        bldr.putByte("delta_look", deltaLook);
        session.send(bldr.toPacket());
      }
    }
  }
コード例 #2
0
 /**
  * Sends a login failure.
  *
  * @param message The message to send to the client.
  */
 public void sendLoginFailure(String message) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(14));
   bldr.putString("reason", message);
   session.send(bldr.toPacket());
   session.close();
 }
コード例 #3
0
 /**
  * Sends a level block/chunk.
  *
  * @param len The length of the chunk.
  * @param chunk The chunk data.
  * @param percent The percentage.
  */
 public void sendLevelBlock(int len, byte[] chunk, int percent) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(3));
   bldr.putShort("chunk_length", len);
   bldr.putByteArray("chunk_data", chunk);
   bldr.putByte("percent", percent);
   session.send(bldr.toPacket());
 }
コード例 #4
0
 /**
  * Sends a login response.
  *
  * @param protocolVersion The protocol version.
  * @param name The server name.
  * @param message The server message of the day.
  * @param op Operator flag.
  */
 public void sendLoginResponse(int protocolVersion, String name, String message, boolean op) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(0));
   bldr.putByte("protocol_version", protocolVersion);
   bldr.putString("server_name", name);
   bldr.putString("server_message", message);
   bldr.putByte("user_type", op ? 100 : 0);
   session.send(bldr.toPacket());
 }
コード例 #5
0
 /**
  * Sends a block.
  *
  * @param x X coordinate.
  * @param y Y coordinate.
  * @param z Z coordinate.
  * @param type BlockDefinition type.
  */
 public void sendBlock(int x, int y, int z, byte type) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(6));
   bldr.putShort("x", x);
   bldr.putShort("y", y);
   bldr.putShort("z", z);
   bldr.putByte("type", type);
   session.send(bldr.toPacket());
 }
コード例 #6
0
 public void sendSpawn(byte id, String name, int x, int y, int z, byte rotation, byte look) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(7));
   bldr.putByte("id", id);
   bldr.putString("name", name);
   bldr.putShort("x", x);
   bldr.putShort("y", y);
   bldr.putShort("z", z);
   bldr.putByte("rotation", rotation);
   bldr.putByte("look", look);
   session.send(bldr.toPacket());
 }
コード例 #7
0
 /**
  * Sends the add entity packet.
  *
  * @param entity The entity being added.
  */
 public void sendAddEntity(Entity entity) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(7));
   bldr.putByte("id", entity.getId());
   bldr.putString("name", entity.getColoredName());
   bldr.putShort("x", entity.getPosition().getX());
   bldr.putShort("y", entity.getPosition().getY());
   bldr.putShort("z", entity.getPosition().getZ());
   bldr.putByte("rotation", entity.getRotation().getRotation());
   bldr.putByte("look", entity.getRotation().getLook());
   session.send(bldr.toPacket());
 }
コード例 #8
0
 /**
  * Sends a teleport.
  *
  * @param position The new position.
  * @param rotation The new rotation.
  */
 public void sendTeleport(Position position, Rotation rotation) {
   session.getPlayer().teleportPosition = position.toBlockPos();
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(8));
   bldr.putByte("id", -1);
   bldr.putShort("x", position.getX());
   bldr.putShort("y", position.getY());
   bldr.putShort("z", position.getZ());
   bldr.putByte("rotation", rotation.getRotation());
   bldr.putByte("look", rotation.getLook());
   session.send(bldr.toPacket());
   session.getPlayer().teleporting = true;
 }
コード例 #9
0
 /**
  * Sends a chat message.
  *
  * @param id The source player id.
  * @param message The message.
  */
 public void sendChatMessage(int id, String message) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(13));
   String message2 = "";
   if (message.length() > 64) {
     message2 = message.substring(64);
     int idx = message.lastIndexOf("&");
     if (idx != -1) message2 = "&" + message.charAt(idx + 1) + message2;
     message = message.substring(0, 64);
   }
   bldr.putByte("id", id);
   bldr.putString("message", message);
   session.send(bldr.toPacket());
   if (!message2.equals("")) sendChatMessage(id, "> " + message2);
 }
コード例 #10
0
 /**
  * Sends the remove entity packet.
  *
  * @param entity The entity being removed.
  */
 public void sendRemoveEntity(Entity entity) {
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(12));
   bldr.putByte("id", entity.getOldId());
   session.send(bldr.toPacket());
 }
コード例 #11
0
 /** Sends the level init packet. */
 public void sendLevelInit() {
   session.setAuthenticated();
   PacketBuilder bldr =
       new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(2));
   session.send(bldr.toPacket());
 }