public void handle(Session client, MessageEvent msg) {
    String username = msg.readString();

    if (username.equals(client.getPlayer().getData().getUsername())) return;

    Session request = NetworkManager.getInstance().getSessions().getByPlayerUsername(username);

    if (request == null
        || request.getPlayer() == null
        || request.getPlayer().getMessenger() == null) return;

    if (!request.getPlayer().getSettings().getAllowFriendRequests()) {
      client.send(
          new AdvancedAlertMessageComposer(Locale.get("game.messenger.friendrequests.disabled")));
      return;
    }

    if (request.getPlayer().getMessenger().hasRequestFrom(client.getPlayer().getId())) return;

    request.getPlayer().getMessenger().addRequest(client.getPlayer().getId());
    request.send(new FriendRequestMessageComposer(client.getPlayer().getData()));

    int userId = PlayerDao.getIdByUsername(username);

    if (userId == 0) return;

    client.getPlayer().getQuests().progressQuest(QuestType.SOCIAL_FRIEND);
    MessengerDao.createRequest(client.getPlayer().getId(), userId);
  }
Ejemplo n.º 2
0
 @Override
 public String getDescription() {
   return Locale.get("command.massmotd.description");
 }
  public void handle(Session client, MessageEvent msg) {
    String text = msg.readString();

    String user = text.split(" ")[0];
    String message = text.replace(user + " ", "");

    if (client.getPlayer().getEntity() == null
        || client.getPlayer().getEntity().getRoom() == null) {
      return;
    }

    if (!client.getPlayer().getEntity().isVisible()) {
      return;
    }

    final Room room = client.getPlayer().getEntity().getRoom();

    RoomEntity userTo = room.getEntities().getEntityByName(user, RoomEntityType.PLAYER);

    if (userTo == null || user.equals(client.getPlayer().getData().getUsername())) return;

    String filteredMessage = TalkMessageEvent.filterMessage(message);

    if (!client.getPlayer().getPermissions().getRank().roomFilterBypass()) {
      FilterResult filterResult = RoomManager.getInstance().getFilter().filter(message);

      if (filterResult.isBlocked()) {
        client.send(
            new AdvancedAlertMessageComposer(
                Locale.get("game.message.blocked").replace("%s", filterResult.getMessage())));
        return;
      } else if (filterResult.wasModified()) {
        filteredMessage = filterResult.getMessage();
      }
    }

    if (!client.getPlayer().getEntity().onChat(filteredMessage)) return;

    try {
      if (LogManager.ENABLED)
        LogManager.getInstance()
            .getStore()
            .getLogEntryContainer()
            .put(
                new RoomChatLogEntry(
                    room.getId(),
                    client.getPlayer().getId(),
                    Locale.getOrDefault("game.logging.whisper", "<Whisper to %username%>")
                            .replace("%username%", user)
                        + " "
                        + message));
    } catch (Exception ignored) {

    }

    client.send(
        new WhisperMessageComposer(client.getPlayer().getEntity().getId(), filteredMessage));

    if (!((PlayerEntity) userTo).getPlayer().ignores(client.getPlayer().getId()))
      ((PlayerEntity) userTo)
          .getPlayer()
          .getSession()
          .send(
              new WhisperMessageComposer(client.getPlayer().getEntity().getId(), filteredMessage));

    for (PlayerEntity entity :
        client.getPlayer().getEntity().getRoom().getEntities().getWhisperSeers()) {
      if (entity.getPlayer().getId() != client.getPlayer().getId()
          && !user.equals(entity.getUsername()))
        entity
            .getPlayer()
            .getSession()
            .send(
                new WhisperMessageComposer(
                    client.getPlayer().getEntity().getId(),
                    "Whisper to " + user + ": " + filteredMessage));
    }
  }