Exemple #1
0
  private static void addPacket(
      Player p, String msg, int slotId, WrappedGameProfile gameProfile, boolean b, int ping) {
    PacketContainer message = protocolManager.createPacket(PacketType.Play.Server.PLAYER_INFO);
    String nameToShow = (!shuttingdown ? "$" : "") + msg;
    if (protocolManager.getProtocolVersion(p) >= 47) {
      nameToShow =
          (!shuttingdown ? "$" : "")
              + ChatColor.DARK_GRAY
              + slotId
              + ": "
              + msg.substring(0, Math.min(msg.length(), 10));
    }
    EnumWrappers.PlayerInfoAction action;
    if (b) {
      action = EnumWrappers.PlayerInfoAction.ADD_PLAYER;
    } else {
      action = EnumWrappers.PlayerInfoAction.REMOVE_PLAYER;
    }
    message.getPlayerInfoAction().write(0, action);
    List<PlayerInfoData> pInfoData = new ArrayList<PlayerInfoData>();
    if (gameProfile != null) {
      pInfoData.add(
          new PlayerInfoData(
              gameProfile
                  .withName(nameToShow.substring(1))
                  .withId(
                      UUID.nameUUIDFromBytes(
                              ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8))
                          .toString()),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    } else {
      pInfoData.add(
          new PlayerInfoData(
              new WrappedGameProfile(
                  UUID.nameUUIDFromBytes(
                      ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8)),
                  nameToShow.substring(1)),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    }

    message.getPlayerInfoDataLists().write(0, pInfoData);
    List<PacketContainer> packetList = cachedPackets.get(p);
    if (packetList == null) {
      packetList = new ArrayList<PacketContainer>();
      cachedPackets.put(p, packetList);
    }
    packetList.add(message);
  }
  public static void setLinesFromStrings(PacketContainer updateSignPacket, String[] lines) {
    assert lines != null;
    assert lines.length == 4;

    WrappedChatComponent[] rawLines = new WrappedChatComponent[4];
    for (int i = 0; i < 4; i++) {
      rawLines[i] = lines[i].isEmpty() ? null : WrappedChatComponent.fromJson(lines[i]);
    }

    setLines(updateSignPacket, rawLines);
  }