private void route(JsonObject message, int fromNode) { String text = message.getString("text", null); int from = message.getInt("from", -1); int to = message.getInt("to", -1); if (fromNode == from && to >= 0 && text != null) { SwingUtilities.invokeLater( () -> { messages.addPacket(from, to, text, getByNode(from).getNetwork()); }); if (to == 0) { for (int i = 0; i < connections.size(); i++) { Connection c = connections.get(i); if (c != null && links.isNeighbour(fromNode, c.getNode())) { send(c, text, from, to); } } } else { Connection c = getByNode(to); if (c != null && links.isNeighbour(from, to)) { send(c, text, from, to); } } } }