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 void execute(Session client, String[] message) {
    final MotdNotificationMessageComposer msg =
        new MotdNotificationMessageComposer(
            this.merge(message) + "\n\n- " + client.getPlayer().getData().getUsername());

    NetworkManager.getInstance().getSessions().broadcast(msg);
  }
Ejemplo n.º 3
0
  public boolean isInRoom() {
    if (!isOnline()) {
      return false;
    }

    Session client = NetworkManager.getInstance().getSessions().getByPlayerId(this.userId);

    // Could have these in 1 statement, but to make it easier to read - lets just leave it like
    // this. :P
    if (client == null || client.getPlayer() == null || client.getPlayer().getEntity() == null) {
      return false;
    }

    if (!client.getPlayer().getEntity().isVisible()) return false;

    return true;
  }
Ejemplo n.º 4
0
 public Session getSession() {
   return NetworkManager.getInstance().getSessions().getByPlayerId(this.userId);
 }